Staging: rt2860: Hoist assign from if
[safe/jmp/linux-2.6] / drivers / staging / rt2860 / common / spectrum.c
index 598259e..2d5f847 100644 (file)
@@ -24,7 +24,6 @@
  *                                                                       *
  *************************************************************************
 
-
     Module Name:
        action.c
 
 #include "../rt_config.h"
 #include "action.h"
 
-VOID MeasureReqTabInit(
-       IN PRTMP_ADAPTER pAd)
+/* The regulatory information in the USA (US) */
+struct rt_dot11_regulatory_information USARegulatoryInfo[] = {
+/*  "regulatory class"  "number of channels"  "Max Tx Pwr"  "channel list" */
+       {0, {0, 0, {0}
+            }
+        }
+       ,                       /* Invlid entry */
+       {1, {4, 16, {36, 40, 44, 48}
+            }
+        }
+       ,
+       {2, {4, 23, {52, 56, 60, 64}
+            }
+        }
+       ,
+       {3, {4, 29, {149, 153, 157, 161}
+            }
+        }
+       ,
+       {4, {11, 23, {100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}
+            }
+        }
+       ,
+       {5, {5, 30, {149, 153, 157, 161, 165}
+            }
+        }
+       ,
+       {6, {10, 14, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+            }
+        }
+       ,
+       {7, {10, 27, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+            }
+        }
+       ,
+       {8, {5, 17, {11, 13, 15, 17, 19}
+            }
+        }
+       ,
+       {9, {5, 30, {11, 13, 15, 17, 19}
+            }
+        }
+       ,
+       {10, {2, 20, {21, 25}
+             }
+        }
+       ,
+       {11, {2, 33, {21, 25}
+             }
+        }
+       ,
+       {12, {11, 30, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
+             }
+        }
+};
+
+#define USA_REGULATORY_INFO_SIZE (sizeof(USARegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information))
+
+/* The regulatory information in Europe */
+struct rt_dot11_regulatory_information EuropeRegulatoryInfo[] = {
+/*  "regulatory class"  "number of channels"  "Max Tx Pwr"  "channel list" */
+       {0, {0, 0, {0}
+            }
+        }
+       ,                       /* Invalid entry */
+       {1, {4, 20, {36, 40, 44, 48}
+            }
+        }
+       ,
+       {2, {4, 20, {52, 56, 60, 64}
+            }
+        }
+       ,
+       {3, {11, 30, {100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}
+            }
+        }
+       ,
+       {4, {13, 20, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
+            }
+        }
+};
+
+#define EU_REGULATORY_INFO_SIZE (sizeof(EuropeRegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information))
+
+/* The regulatory information in Japan */
+struct rt_dot11_regulatory_information JapanRegulatoryInfo[] = {
+/*  "regulatory class"  "number of channels"  "Max Tx Pwr"  "channel list" */
+       {0, {0, 0, {0}
+            }
+        }
+       ,                       /* Invalid entry */
+       {1, {4, 22, {34, 38, 42, 46}
+            }
+        }
+       ,
+       {2, {3, 24, {8, 12, 16}
+            }
+        }
+       ,
+       {3, {3, 24, {8, 12, 16}
+            }
+        }
+       ,
+       {4, {3, 24, {8, 12, 16}
+            }
+        }
+       ,
+       {5, {3, 24, {8, 12, 16}
+            }
+        }
+       ,
+       {6, {3, 22, {8, 12, 16}
+            }
+        }
+       ,
+       {7, {4, 24, {184, 188, 192, 196}
+            }
+        }
+       ,
+       {8, {4, 24, {184, 188, 192, 196}
+            }
+        }
+       ,
+       {9, {4, 24, {184, 188, 192, 196}
+            }
+        }
+       ,
+       {10, {4, 24, {184, 188, 192, 196}
+             }
+        }
+       ,
+       {11, {4, 22, {184, 188, 192, 196}
+             }
+        }
+       ,
+       {12, {4, 24, {7, 8, 9, 11}
+             }
+        }
+       ,
+       {13, {4, 24, {7, 8, 9, 11}
+             }
+        }
+       ,
+       {14, {4, 24, {7, 8, 9, 11}
+             }
+        }
+       ,
+       {15, {4, 24, {7, 8, 9, 11}
+             }
+        }
+       ,
+       {16, {6, 24, {183, 184, 185, 187, 188, 189}
+             }
+        }
+       ,
+       {17, {6, 24, {183, 184, 185, 187, 188, 189}
+             }
+        }
+       ,
+       {18, {6, 24, {183, 184, 185, 187, 188, 189}
+             }
+        }
+       ,
+       {19, {6, 24, {183, 184, 185, 187, 188, 189}
+             }
+        }
+       ,
+       {20, {6, 17, {183, 184, 185, 187, 188, 189}
+             }
+        }
+       ,
+       {21, {6, 24, {6, 7, 8, 9, 10, 11}
+             }
+        }
+       ,
+       {22, {6, 24, {6, 7, 8, 9, 10, 11}
+             }
+        }
+       ,
+       {23, {6, 24, {6, 7, 8, 9, 10, 11}
+             }
+        }
+       ,
+       {24, {6, 24, {6, 7, 8, 9, 10, 11}
+             }
+        }
+       ,
+       {25, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
+             }
+        }
+       ,
+       {26, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
+             }
+        }
+       ,
+       {27, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
+             }
+        }
+       ,
+       {28, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
+             }
+        }
+       ,
+       {29, {8, 17, {182, 183, 184, 185, 186, 187, 188, 189}
+             }
+        }
+       ,
+       {30, {13, 23, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
+             }
+        }
+       ,
+       {31, {1, 23, {14}
+             }
+        }
+       ,
+       {32, {4, 22, {52, 56, 60, 64}
+             }
+        }
+};
+
+#define JP_REGULATORY_INFO_SIZE (sizeof(JapanRegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information))
+
+char RTMP_GetTxPwr(struct rt_rtmp_adapter *pAd, IN HTTRANSMIT_SETTING HTTxMode)
+{
+       struct tx_pwr_cfg {
+               u8 Mode;
+               u8 MCS;
+               u16 req;
+               u8 shift;
+               u32 BitMask;
+       };
+
+       u32 Value;
+       int Idx;
+       u8 PhyMode;
+       char CurTxPwr;
+       u8 TxPwrRef = 0;
+       char DaltaPwr;
+       unsigned long TxPwr[5];
+
+       struct tx_pwr_cfg TxPwrCfg[] = {
+               {MODE_CCK, 0, 0, 4, 0x000000f0},
+               {MODE_CCK, 1, 0, 0, 0x0000000f},
+               {MODE_CCK, 2, 0, 12, 0x0000f000},
+               {MODE_CCK, 3, 0, 8, 0x00000f00},
+
+               {MODE_OFDM, 0, 0, 20, 0x00f00000},
+               {MODE_OFDM, 1, 0, 16, 0x000f0000},
+               {MODE_OFDM, 2, 0, 28, 0xf0000000},
+               {MODE_OFDM, 3, 0, 24, 0x0f000000},
+               {MODE_OFDM, 4, 1, 4, 0x000000f0},
+               {MODE_OFDM, 5, 1, 0, 0x0000000f},
+               {MODE_OFDM, 6, 1, 12, 0x0000f000},
+               {MODE_OFDM, 7, 1, 8, 0x00000f00}
+               , {MODE_HTMIX, 0, 1, 20, 0x00f00000},
+               {MODE_HTMIX, 1, 1, 16, 0x000f0000},
+               {MODE_HTMIX, 2, 1, 28, 0xf0000000},
+               {MODE_HTMIX, 3, 1, 24, 0x0f000000},
+               {MODE_HTMIX, 4, 2, 4, 0x000000f0},
+               {MODE_HTMIX, 5, 2, 0, 0x0000000f},
+               {MODE_HTMIX, 6, 2, 12, 0x0000f000},
+               {MODE_HTMIX, 7, 2, 8, 0x00000f00},
+               {MODE_HTMIX, 8, 2, 20, 0x00f00000},
+               {MODE_HTMIX, 9, 2, 16, 0x000f0000},
+               {MODE_HTMIX, 10, 2, 28, 0xf0000000},
+               {MODE_HTMIX, 11, 2, 24, 0x0f000000},
+               {MODE_HTMIX, 12, 3, 4, 0x000000f0},
+               {MODE_HTMIX, 13, 3, 0, 0x0000000f},
+               {MODE_HTMIX, 14, 3, 12, 0x0000f000},
+               {MODE_HTMIX, 15, 3, 8, 0x00000f00}
+       };
+#define MAX_TXPWR_TAB_SIZE (sizeof(TxPwrCfg) / sizeof(struct tx_pwr_cfg))
+
+       CurTxPwr = 19;
+
+       /* check Tx Power setting from UI. */
+       if (pAd->CommonCfg.TxPowerPercentage > 90) ;
+       else if (pAd->CommonCfg.TxPowerPercentage > 60) /* reduce Pwr for 1 dB. */
+               CurTxPwr -= 1;
+       else if (pAd->CommonCfg.TxPowerPercentage > 30) /* reduce Pwr for 3 dB. */
+               CurTxPwr -= 3;
+       else if (pAd->CommonCfg.TxPowerPercentage > 15) /* reduce Pwr for 6 dB. */
+               CurTxPwr -= 6;
+       else if (pAd->CommonCfg.TxPowerPercentage > 9)  /* reduce Pwr for 9 dB. */
+               CurTxPwr -= 9;
+       else                    /* reduce Pwr for 12 dB. */
+               CurTxPwr -= 12;
+
+       if (pAd->CommonCfg.BBPCurrentBW == BW_40) {
+               if (pAd->CommonCfg.CentralChannel > 14) {
+                       TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
+                       TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
+                       TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
+                       TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
+                       TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
+               } else {
+                       TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
+                       TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
+                       TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
+                       TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
+                       TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
+               }
+       } else {
+               if (pAd->CommonCfg.Channel > 14) {
+                       TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
+                       TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
+                       TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
+                       TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
+                       TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
+               } else {
+                       TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
+                       TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
+                       TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
+                       TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
+                       TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
+               }
+       }
+
+       switch (HTTxMode.field.MODE) {
+       case MODE_CCK:
+       case MODE_OFDM:
+               Value = TxPwr[1];
+               TxPwrRef = (Value & 0x00000f00) >> 8;
+
+               break;
+
+       case MODE_HTMIX:
+       case MODE_HTGREENFIELD:
+               if (pAd->CommonCfg.TxStream == 1) {
+                       Value = TxPwr[2];
+                       TxPwrRef = (Value & 0x00000f00) >> 8;
+               } else if (pAd->CommonCfg.TxStream == 2) {
+                       Value = TxPwr[3];
+                       TxPwrRef = (Value & 0x00000f00) >> 8;
+               }
+               break;
+       }
+
+       PhyMode = (HTTxMode.field.MODE == MODE_HTGREENFIELD)
+           ? MODE_HTMIX : HTTxMode.field.MODE;
+
+       for (Idx = 0; Idx < MAX_TXPWR_TAB_SIZE; Idx++) {
+               if ((TxPwrCfg[Idx].Mode == PhyMode)
+                   && (TxPwrCfg[Idx].MCS == HTTxMode.field.MCS)) {
+                       Value = TxPwr[TxPwrCfg[Idx].req];
+                       DaltaPwr =
+                           TxPwrRef - (char)((Value & TxPwrCfg[Idx].BitMask)
+                                              >> TxPwrCfg[Idx].shift);
+                       CurTxPwr -= DaltaPwr;
+                       break;
+               }
+       }
+
+       return CurTxPwr;
+}
+
+void MeasureReqTabInit(struct rt_rtmp_adapter *pAd)
 {
        NdisAllocateSpinLock(&pAd->CommonCfg.MeasureReqTabLock);
 
-       pAd->CommonCfg.pMeasureReqTab = kmalloc(sizeof(MEASURE_REQ_TAB), GFP_ATOMIC);
+       pAd->CommonCfg.pMeasureReqTab =
+           kmalloc(sizeof(struct rt_measure_req_tab), GFP_ATOMIC);
        if (pAd->CommonCfg.pMeasureReqTab)
-               NdisZeroMemory(pAd->CommonCfg.pMeasureReqTab, sizeof(MEASURE_REQ_TAB));
+               NdisZeroMemory(pAd->CommonCfg.pMeasureReqTab,
+                              sizeof(struct rt_measure_req_tab));
        else
-               DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pMeasureReqTab.\n", __func__));
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s Fail to alloc memory for pAd->CommonCfg.pMeasureReqTab.\n",
+                         __func__));
 
        return;
 }
 
-VOID MeasureReqTabExit(
-       IN PRTMP_ADAPTER pAd)
+void MeasureReqTabExit(struct rt_rtmp_adapter *pAd)
 {
-       NdisFreeSpinLock(pAd->CommonCfg.MeasureReqTabLock);
+       NdisFreeSpinLock(&pAd->CommonCfg.MeasureReqTabLock);
 
        if (pAd->CommonCfg.pMeasureReqTab)
                kfree(pAd->CommonCfg.pMeasureReqTab);
@@ -66,18 +423,16 @@ VOID MeasureReqTabExit(
        return;
 }
 
-static PMEASURE_REQ_ENTRY MeasureReqLookUp(
-       IN PRTMP_ADAPTER        pAd,
-       IN UINT8                        DialogToken)
+struct rt_measure_req_entry *MeasureReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken)
 {
-       UINT HashIdx;
-       PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
-       PMEASURE_REQ_ENTRY pEntry = NULL;
-       PMEASURE_REQ_ENTRY pPrevEntry = NULL;
-
-       if (pTab == NULL)
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __func__));
+       u32 HashIdx;
+       struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab;
+       struct rt_measure_req_entry *pEntry = NULL;
+       struct rt_measure_req_entry *pPrevEntry = NULL;
+
+       if (pTab == NULL) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: pMeasureReqTab doesn't exist.\n", __func__));
                return NULL;
        }
 
@@ -86,12 +441,10 @@ static PMEASURE_REQ_ENTRY MeasureReqLookUp(
        HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
        pEntry = pTab->Hash[HashIdx];
 
-       while (pEntry)
-       {
+       while (pEntry) {
                if (pEntry->DialogToken == DialogToken)
                        break;
-               else
-               {
+               else {
                        pPrevEntry = pEntry;
                        pEntry = pEntry->pNext;
                }
@@ -102,50 +455,49 @@ static PMEASURE_REQ_ENTRY MeasureReqLookUp(
        return pEntry;
 }
 
-static PMEASURE_REQ_ENTRY MeasureReqInsert(
-       IN PRTMP_ADAPTER        pAd,
-       IN UINT8                        DialogToken)
+struct rt_measure_req_entry *MeasureReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken)
 {
-       INT i;
-       ULONG HashIdx;
-       PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
-       PMEASURE_REQ_ENTRY pEntry = NULL, pCurrEntry;
-       ULONG Now;
-
-       if(pTab == NULL)
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __func__));
+       int i;
+       unsigned long HashIdx;
+       struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab;
+       struct rt_measure_req_entry *pEntry = NULL, *pCurrEntry;
+       unsigned long Now;
+
+       if (pTab == NULL) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: pMeasureReqTab doesn't exist.\n", __func__));
                return NULL;
        }
 
        pEntry = MeasureReqLookUp(pAd, DialogToken);
-       if (pEntry == NULL)
-       {
+       if (pEntry == NULL) {
                RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
-               for (i = 0; i < MAX_MEASURE_REQ_TAB_SIZE; i++)
-               {
+               for (i = 0; i < MAX_MEASURE_REQ_TAB_SIZE; i++) {
                        NdisGetSystemUpTime(&Now);
                        pEntry = &pTab->Content[i];
 
                        if ((pEntry->Valid == TRUE)
-                               && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + MQ_REQ_AGE_OUT)))
+                           && RTMP_TIME_AFTER((unsigned long)Now,
+                                              (unsigned long)(pEntry->
+                                                              lastTime +
+                                                              MQ_REQ_AGE_OUT)))
                        {
-                               PMEASURE_REQ_ENTRY pPrevEntry = NULL;
-                               ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
-                               PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
-
-                               // update Hash list
-                               do
-                               {
-                                       if (pProbeEntry == pEntry)
-                                       {
-                                               if (pPrevEntry == NULL)
-                                               {
-                                                       pTab->Hash[HashIdx] = pEntry->pNext;
-                                               }
-                                               else
-                                               {
-                                                       pPrevEntry->pNext = pEntry->pNext;
+                               struct rt_measure_req_entry *pPrevEntry = NULL;
+                               unsigned long HashIdx =
+                                   MQ_DIALOGTOKEN_HASH_INDEX(pEntry->
+                                                             DialogToken);
+                               struct rt_measure_req_entry *pProbeEntry =
+                                   pTab->Hash[HashIdx];
+
+                               /* update Hash list */
+                               do {
+                                       if (pProbeEntry == pEntry) {
+                                               if (pPrevEntry == NULL) {
+                                                       pTab->Hash[HashIdx] =
+                                                           pEntry->pNext;
+                                               } else {
+                                                       pPrevEntry->pNext =
+                                                           pEntry->pNext;
                                                }
                                                break;
                                        }
@@ -154,7 +506,8 @@ static PMEASURE_REQ_ENTRY MeasureReqInsert(
                                        pProbeEntry = pProbeEntry->pNext;
                                } while (pProbeEntry);
 
-                               NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY));
+                               NdisZeroMemory(pEntry,
+                                              sizeof(struct rt_measure_req_entry));
                                pTab->Size--;
 
                                break;
@@ -164,30 +517,24 @@ static PMEASURE_REQ_ENTRY MeasureReqInsert(
                                break;
                }
 
-               if (i < MAX_MEASURE_REQ_TAB_SIZE)
-               {
+               if (i < MAX_MEASURE_REQ_TAB_SIZE) {
                        NdisGetSystemUpTime(&Now);
                        pEntry->lastTime = Now;
                        pEntry->Valid = TRUE;
                        pEntry->DialogToken = DialogToken;
                        pTab->Size++;
-               }
-               else
-               {
+               } else {
                        pEntry = NULL;
-                       DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab tab full.\n", __func__));
+                       DBGPRINT(RT_DEBUG_ERROR,
+                                ("%s: pMeasureReqTab tab full.\n", __func__));
                }
 
-               // add this Neighbor entry into HASH table
-               if (pEntry)
-               {
+               /* add this Neighbor entry into HASH table */
+               if (pEntry) {
                        HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
-                       if (pTab->Hash[HashIdx] == NULL)
-                       {
+                       if (pTab->Hash[HashIdx] == NULL) {
                                pTab->Hash[HashIdx] = pEntry;
-                       }
-                       else
-                       {
+                       } else {
                                pCurrEntry = pTab->Hash[HashIdx];
                                while (pCurrEntry->pNext != NULL)
                                        pCurrEntry = pCurrEntry->pNext;
@@ -201,45 +548,35 @@ static PMEASURE_REQ_ENTRY MeasureReqInsert(
        return pEntry;
 }
 
-static VOID MeasureReqDelete(
-       IN PRTMP_ADAPTER        pAd,
-       IN UINT8                        DialogToken)
+void MeasureReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken)
 {
-       PMEASURE_REQ_TAB pTab = pAd->CommonCfg.pMeasureReqTab;
-       PMEASURE_REQ_ENTRY pEntry = NULL;
+       struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab;
+       struct rt_measure_req_entry *pEntry = NULL;
 
-       if(pTab == NULL)
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: pMeasureReqTab doesn't exist.\n", __func__));
+       if (pTab == NULL) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: pMeasureReqTab doesn't exist.\n", __func__));
                return;
        }
-
-       // if empty, return
-       if (pTab->Size == 0)
-       {
+       /* if empty, return */
+       if (pTab->Size == 0) {
                DBGPRINT(RT_DEBUG_ERROR, ("pMeasureReqTab empty.\n"));
                return;
        }
 
        pEntry = MeasureReqLookUp(pAd, DialogToken);
-       if (pEntry != NULL)
-       {
-               PMEASURE_REQ_ENTRY pPrevEntry = NULL;
-               ULONG HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
-               PMEASURE_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
+       if (pEntry != NULL) {
+               struct rt_measure_req_entry *pPrevEntry = NULL;
+               unsigned long HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
+               struct rt_measure_req_entry *pProbeEntry = pTab->Hash[HashIdx];
 
                RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
-               // update Hash list
-               do
-               {
-                       if (pProbeEntry == pEntry)
-                       {
-                               if (pPrevEntry == NULL)
-                               {
+               /* update Hash list */
+               do {
+                       if (pProbeEntry == pEntry) {
+                               if (pPrevEntry == NULL) {
                                        pTab->Hash[HashIdx] = pEntry->pNext;
-                               }
-                               else
-                               {
+                               } else {
                                        pPrevEntry->pNext = pEntry->pNext;
                                }
                                break;
@@ -249,7 +586,7 @@ static VOID MeasureReqDelete(
                        pProbeEntry = pProbeEntry->pNext;
                } while (pProbeEntry);
 
-               NdisZeroMemory(pEntry, sizeof(MEASURE_REQ_ENTRY));
+               NdisZeroMemory(pEntry, sizeof(struct rt_measure_req_entry));
                pTab->Size--;
 
                RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
@@ -258,24 +595,24 @@ static VOID MeasureReqDelete(
        return;
 }
 
-VOID TpcReqTabInit(
-       IN PRTMP_ADAPTER pAd)
+void TpcReqTabInit(struct rt_rtmp_adapter *pAd)
 {
        NdisAllocateSpinLock(&pAd->CommonCfg.TpcReqTabLock);
 
-       pAd->CommonCfg.pTpcReqTab = kmalloc(sizeof(TPC_REQ_TAB), GFP_ATOMIC);
+       pAd->CommonCfg.pTpcReqTab = kmalloc(sizeof(struct rt_tpc_req_tab), GFP_ATOMIC);
        if (pAd->CommonCfg.pTpcReqTab)
-               NdisZeroMemory(pAd->CommonCfg.pTpcReqTab, sizeof(TPC_REQ_TAB));
+               NdisZeroMemory(pAd->CommonCfg.pTpcReqTab, sizeof(struct rt_tpc_req_tab));
        else
-               DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pTpcReqTab.\n", __func__));
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s Fail to alloc memory for pAd->CommonCfg.pTpcReqTab.\n",
+                         __func__));
 
        return;
 }
 
-VOID TpcReqTabExit(
-       IN PRTMP_ADAPTER pAd)
+void TpcReqTabExit(struct rt_rtmp_adapter *pAd)
 {
-       NdisFreeSpinLock(pAd->CommonCfg.TpcReqTabLock);
+       NdisFreeSpinLock(&pAd->CommonCfg.TpcReqTabLock);
 
        if (pAd->CommonCfg.pTpcReqTab)
                kfree(pAd->CommonCfg.pTpcReqTab);
@@ -284,18 +621,16 @@ VOID TpcReqTabExit(
        return;
 }
 
-static PTPC_REQ_ENTRY TpcReqLookUp(
-       IN PRTMP_ADAPTER        pAd,
-       IN UINT8                        DialogToken)
+static struct rt_tpc_req_entry *TpcReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken)
 {
-       UINT HashIdx;
-       PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
-       PTPC_REQ_ENTRY pEntry = NULL;
-       PTPC_REQ_ENTRY pPrevEntry = NULL;
-
-       if (pTab == NULL)
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __func__));
+       u32 HashIdx;
+       struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab;
+       struct rt_tpc_req_entry *pEntry = NULL;
+       struct rt_tpc_req_entry *pPrevEntry = NULL;
+
+       if (pTab == NULL) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: pTpcReqTab doesn't exist.\n", __func__));
                return NULL;
        }
 
@@ -304,12 +639,10 @@ static PTPC_REQ_ENTRY TpcReqLookUp(
        HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
        pEntry = pTab->Hash[HashIdx];
 
-       while (pEntry)
-       {
+       while (pEntry) {
                if (pEntry->DialogToken == DialogToken)
                        break;
-               else
-               {
+               else {
                        pPrevEntry = pEntry;
                        pEntry = pEntry->pNext;
                }
@@ -320,51 +653,49 @@ static PTPC_REQ_ENTRY TpcReqLookUp(
        return pEntry;
 }
 
-
-static PTPC_REQ_ENTRY TpcReqInsert(
-       IN PRTMP_ADAPTER        pAd,
-       IN UINT8                        DialogToken)
+static struct rt_tpc_req_entry *TpcReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken)
 {
-       INT i;
-       ULONG HashIdx;
-       PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
-       PTPC_REQ_ENTRY pEntry = NULL, pCurrEntry;
-       ULONG Now;
-
-       if(pTab == NULL)
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __func__));
+       int i;
+       unsigned long HashIdx;
+       struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab;
+       struct rt_tpc_req_entry *pEntry = NULL, *pCurrEntry;
+       unsigned long Now;
+
+       if (pTab == NULL) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: pTpcReqTab doesn't exist.\n", __func__));
                return NULL;
        }
 
        pEntry = TpcReqLookUp(pAd, DialogToken);
-       if (pEntry == NULL)
-       {
+       if (pEntry == NULL) {
                RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
-               for (i = 0; i < MAX_TPC_REQ_TAB_SIZE; i++)
-               {
+               for (i = 0; i < MAX_TPC_REQ_TAB_SIZE; i++) {
                        NdisGetSystemUpTime(&Now);
                        pEntry = &pTab->Content[i];
 
                        if ((pEntry->Valid == TRUE)
-                               && RTMP_TIME_AFTER((unsigned long)Now, (unsigned long)(pEntry->lastTime + TPC_REQ_AGE_OUT)))
+                           && RTMP_TIME_AFTER((unsigned long)Now,
+                                              (unsigned long)(pEntry->
+                                                              lastTime +
+                                                              TPC_REQ_AGE_OUT)))
                        {
-                               PTPC_REQ_ENTRY pPrevEntry = NULL;
-                               ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
-                               PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
-
-                               // update Hash list
-                               do
-                               {
-                                       if (pProbeEntry == pEntry)
-                                       {
-                                               if (pPrevEntry == NULL)
-                                               {
-                                                       pTab->Hash[HashIdx] = pEntry->pNext;
-                                               }
-                                               else
-                                               {
-                                                       pPrevEntry->pNext = pEntry->pNext;
+                               struct rt_tpc_req_entry *pPrevEntry = NULL;
+                               unsigned long HashIdx =
+                                   TPC_DIALOGTOKEN_HASH_INDEX(pEntry->
+                                                              DialogToken);
+                               struct rt_tpc_req_entry *pProbeEntry =
+                                   pTab->Hash[HashIdx];
+
+                               /* update Hash list */
+                               do {
+                                       if (pProbeEntry == pEntry) {
+                                               if (pPrevEntry == NULL) {
+                                                       pTab->Hash[HashIdx] =
+                                                           pEntry->pNext;
+                                               } else {
+                                                       pPrevEntry->pNext =
+                                                           pEntry->pNext;
                                                }
                                                break;
                                        }
@@ -373,7 +704,7 @@ static PTPC_REQ_ENTRY TpcReqInsert(
                                        pProbeEntry = pProbeEntry->pNext;
                                } while (pProbeEntry);
 
-                               NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY));
+                               NdisZeroMemory(pEntry, sizeof(struct rt_tpc_req_entry));
                                pTab->Size--;
 
                                break;
@@ -383,30 +714,24 @@ static PTPC_REQ_ENTRY TpcReqInsert(
                                break;
                }
 
-               if (i < MAX_TPC_REQ_TAB_SIZE)
-               {
+               if (i < MAX_TPC_REQ_TAB_SIZE) {
                        NdisGetSystemUpTime(&Now);
                        pEntry->lastTime = Now;
                        pEntry->Valid = TRUE;
                        pEntry->DialogToken = DialogToken;
                        pTab->Size++;
-               }
-               else
-               {
+               } else {
                        pEntry = NULL;
-                       DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab tab full.\n", __func__));
+                       DBGPRINT(RT_DEBUG_ERROR,
+                                ("%s: pTpcReqTab tab full.\n", __func__));
                }
 
-               // add this Neighbor entry into HASH table
-               if (pEntry)
-               {
+               /* add this Neighbor entry into HASH table */
+               if (pEntry) {
                        HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
-                       if (pTab->Hash[HashIdx] == NULL)
-                       {
+                       if (pTab->Hash[HashIdx] == NULL) {
                                pTab->Hash[HashIdx] = pEntry;
-                       }
-                       else
-                       {
+                       } else {
                                pCurrEntry = pTab->Hash[HashIdx];
                                while (pCurrEntry->pNext != NULL)
                                        pCurrEntry = pCurrEntry->pNext;
@@ -420,45 +745,35 @@ static PTPC_REQ_ENTRY TpcReqInsert(
        return pEntry;
 }
 
-static VOID TpcReqDelete(
-       IN PRTMP_ADAPTER        pAd,
-       IN UINT8                        DialogToken)
+static void TpcReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken)
 {
-       PTPC_REQ_TAB pTab = pAd->CommonCfg.pTpcReqTab;
-       PTPC_REQ_ENTRY pEntry = NULL;
+       struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab;
+       struct rt_tpc_req_entry *pEntry = NULL;
 
-       if(pTab == NULL)
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: pTpcReqTab doesn't exist.\n", __func__));
+       if (pTab == NULL) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: pTpcReqTab doesn't exist.\n", __func__));
                return;
        }
-
-       // if empty, return
-       if (pTab->Size == 0)
-       {
+       /* if empty, return */
+       if (pTab->Size == 0) {
                DBGPRINT(RT_DEBUG_ERROR, ("pTpcReqTab empty.\n"));
                return;
        }
 
        pEntry = TpcReqLookUp(pAd, DialogToken);
-       if (pEntry != NULL)
-       {
-               PTPC_REQ_ENTRY pPrevEntry = NULL;
-               ULONG HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
-               PTPC_REQ_ENTRY pProbeEntry = pTab->Hash[HashIdx];
+       if (pEntry != NULL) {
+               struct rt_tpc_req_entry *pPrevEntry = NULL;
+               unsigned long HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
+               struct rt_tpc_req_entry *pProbeEntry = pTab->Hash[HashIdx];
 
                RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
-               // update Hash list
-               do
-               {
-                       if (pProbeEntry == pEntry)
-                       {
-                               if (pPrevEntry == NULL)
-                               {
+               /* update Hash list */
+               do {
+                       if (pProbeEntry == pEntry) {
+                               if (pPrevEntry == NULL) {
                                        pTab->Hash[HashIdx] = pEntry->pNext;
-                               }
-                               else
-                               {
+                               } else {
                                        pPrevEntry->pNext = pEntry->pNext;
                                }
                                break;
@@ -468,7 +783,7 @@ static VOID TpcReqDelete(
                        pProbeEntry = pProbeEntry->pNext;
                } while (pProbeEntry);
 
-               NdisZeroMemory(pEntry, sizeof(TPC_REQ_ENTRY));
+               NdisZeroMemory(pEntry, sizeof(struct rt_tpc_req_entry));
                pTab->Size--;
 
                RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
@@ -487,10 +802,9 @@ static VOID TpcReqDelete(
        Return  : Current Time Stamp.
        ==========================================================================
  */
-static UINT64 GetCurrentTimeStamp(
-       IN PRTMP_ADAPTER pAd)
+static u64 GetCurrentTimeStamp(struct rt_rtmp_adapter *pAd)
 {
-       // get current time stamp.
+       /* get current time stamp. */
        return 0;
 }
 
@@ -504,11 +818,73 @@ static UINT64 GetCurrentTimeStamp(
        Return  : Current Time Stamp.
        ==========================================================================
  */
-static UINT8 GetCurTxPwr(
-       IN PRTMP_ADAPTER pAd,
-       IN UINT8 Wcid)
+static u8 GetCurTxPwr(struct rt_rtmp_adapter *pAd, u8 Wcid)
 {
-       return 16; /* 16 dBm */
+       return 16;              /* 16 dBm */
+}
+
+/*
+       ==========================================================================
+       Description:
+               Get Current Transmit Power.
+
+       Parametrs:
+
+       Return  : Current Time Stamp.
+       ==========================================================================
+ */
+void InsertChannelRepIE(struct rt_rtmp_adapter *pAd,
+                       u8 *pFrameBuf,
+                       unsigned long *pFrameLen,
+                       char *pCountry, u8 RegulatoryClass)
+{
+       unsigned long TempLen;
+       u8 Len;
+       u8 IEId = IE_AP_CHANNEL_REPORT;
+       u8 *pChListPtr = NULL;
+
+       Len = 1;
+       if (strncmp(pCountry, "US", 2) == 0) {
+               if (RegulatoryClass >= USA_REGULATORY_INFO_SIZE) {
+                       DBGPRINT(RT_DEBUG_ERROR,
+                                ("%s: USA Unknow Requlatory class (%d)\n",
+                                 __func__, RegulatoryClass));
+                       return;
+               }
+
+               Len +=
+                   USARegulatoryInfo[RegulatoryClass].ChannelSet.
+                   NumberOfChannels;
+               pChListPtr =
+                   USARegulatoryInfo[RegulatoryClass].ChannelSet.ChannelList;
+       } else if (strncmp(pCountry, "JP", 2) == 0) {
+               if (RegulatoryClass >= JP_REGULATORY_INFO_SIZE) {
+                       DBGPRINT(RT_DEBUG_ERROR,
+                                ("%s: JP Unknow Requlatory class (%d)\n",
+                                 __func__, RegulatoryClass));
+                       return;
+               }
+
+               Len +=
+                   JapanRegulatoryInfo[RegulatoryClass].ChannelSet.
+                   NumberOfChannels;
+               pChListPtr =
+                   JapanRegulatoryInfo[RegulatoryClass].ChannelSet.ChannelList;
+       } else {
+               DBGPRINT(RT_DEBUG_ERROR, ("%s: Unknow Country (%s)\n",
+                                         __func__, pCountry));
+               return;
+       }
+
+       MakeOutgoingFrame(pFrameBuf, &TempLen,
+                         1, &IEId,
+                         1, &Len,
+                         1, &RegulatoryClass,
+                         Len - 1, pChListPtr, END_OF_ARGS);
+
+       *pFrameLen = *pFrameLen + TempLen;
+
+       return;
 }
 
 /*
@@ -524,16 +900,12 @@ static UINT8 GetCurTxPwr(
        Return  : None.
        ==========================================================================
  */
-static VOID InsertDialogToken(
-       IN PRTMP_ADAPTER pAd,
-       OUT PUCHAR pFrameBuf,
-       OUT PULONG pFrameLen,
-       IN UINT8 DialogToken)
+void InsertDialogToken(struct rt_rtmp_adapter *pAd,
+                      u8 *pFrameBuf,
+                      unsigned long *pFrameLen, u8 DialogToken)
 {
-       ULONG TempLen;
-       MakeOutgoingFrame(pFrameBuf,    &TempLen,
-                                       1,                              &DialogToken,
-                                       END_OF_ARGS);
+       unsigned long TempLen;
+       MakeOutgoingFrame(pFrameBuf, &TempLen, 1, &DialogToken, END_OF_ARGS);
 
        *pFrameLen = *pFrameLen + TempLen;
 
@@ -552,19 +924,15 @@ static VOID InsertDialogToken(
        Return  : None.
        ==========================================================================
  */
- static VOID InsertTpcReqIE(
-       IN PRTMP_ADAPTER pAd,
-       OUT PUCHAR pFrameBuf,
-       OUT PULONG pFrameLen)
+static void InsertTpcReqIE(struct rt_rtmp_adapter *pAd,
+                          u8 *pFrameBuf, unsigned long *pFrameLen)
 {
-       ULONG TempLen;
-       ULONG Len = 0;
-       UINT8 ElementID = IE_TPC_REQUEST;
+       unsigned long TempLen;
+       unsigned long Len = 0;
+       u8 ElementID = IE_TPC_REQUEST;
 
-       MakeOutgoingFrame(pFrameBuf,                                    &TempLen,
-                                               1,                                                      &ElementID,
-                                               1,                                                      &Len,
-                                               END_OF_ARGS);
+       MakeOutgoingFrame(pFrameBuf, &TempLen,
+                         1, &ElementID, 1, &Len, END_OF_ARGS);
 
        *pFrameLen = *pFrameLen + TempLen;
 
@@ -585,30 +953,25 @@ static VOID InsertDialogToken(
        Return  : None.
        ==========================================================================
  */
- static VOID InsertTpcReportIE(
-       IN PRTMP_ADAPTER pAd,
-       OUT PUCHAR pFrameBuf,
-       OUT PULONG pFrameLen,
-       IN UINT8 TxPwr,
-       IN UINT8 LinkMargin)
+void InsertTpcReportIE(struct rt_rtmp_adapter *pAd,
+                      u8 *pFrameBuf,
+                      unsigned long *pFrameLen,
+                      u8 TxPwr, u8 LinkMargin)
 {
-       ULONG TempLen;
-       ULONG Len = sizeof(TPC_REPORT_INFO);
-       UINT8 ElementID = IE_TPC_REPORT;
-       TPC_REPORT_INFO TpcReportIE;
+       unsigned long TempLen;
+       unsigned long Len = sizeof(struct rt_tpc_report_info);
+       u8 ElementID = IE_TPC_REPORT;
+       struct rt_tpc_report_info TpcReportIE;
 
        TpcReportIE.TxPwr = TxPwr;
        TpcReportIE.LinkMargin = LinkMargin;
 
-       MakeOutgoingFrame(pFrameBuf,                                    &TempLen,
-                                               1,                                                      &ElementID,
-                                               1,                                                      &Len,
-                                               Len,                                            &TpcReportIE,
-                                               END_OF_ARGS);
+       MakeOutgoingFrame(pFrameBuf, &TempLen,
+                         1, &ElementID,
+                         1, &Len, Len, &TpcReportIE, END_OF_ARGS);
 
        *pFrameLen = *pFrameLen + TempLen;
 
-
        return;
 }
 
@@ -627,32 +990,26 @@ static VOID InsertDialogToken(
        Return  : None.
        ==========================================================================
  */
-static VOID InsertChSwAnnIE(
-       IN PRTMP_ADAPTER pAd,
-       OUT PUCHAR pFrameBuf,
-       OUT PULONG pFrameLen,
-       IN UINT8 ChSwMode,
-       IN UINT8 NewChannel,
-       IN UINT8 ChSwCnt)
+static void InsertChSwAnnIE(struct rt_rtmp_adapter *pAd,
+                           u8 *pFrameBuf,
+                           unsigned long *pFrameLen,
+                           u8 ChSwMode,
+                           u8 NewChannel, u8 ChSwCnt)
 {
-       ULONG TempLen;
-       ULONG Len = sizeof(CH_SW_ANN_INFO);
-       UINT8 ElementID = IE_CHANNEL_SWITCH_ANNOUNCEMENT;
-       CH_SW_ANN_INFO ChSwAnnIE;
+       unsigned long TempLen;
+       unsigned long Len = sizeof(struct rt_ch_sw_ann_info);
+       u8 ElementID = IE_CHANNEL_SWITCH_ANNOUNCEMENT;
+       struct rt_ch_sw_ann_info ChSwAnnIE;
 
        ChSwAnnIE.ChSwMode = ChSwMode;
        ChSwAnnIE.Channel = NewChannel;
        ChSwAnnIE.ChSwCnt = ChSwCnt;
 
-       MakeOutgoingFrame(pFrameBuf,                            &TempLen,
-                                               1,                                              &ElementID,
-                                               1,                                              &Len,
-                                               Len,                                    &ChSwAnnIE,
-                                               END_OF_ARGS);
+       MakeOutgoingFrame(pFrameBuf, &TempLen,
+                         1, &ElementID, 1, &Len, Len, &ChSwAnnIE, END_OF_ARGS);
 
        *pFrameLen = *pFrameLen + TempLen;
 
-
        return;
 }
 
@@ -671,25 +1028,21 @@ static VOID InsertChSwAnnIE(
                7. Measure Start time.
                8. Measure Duration.
 
-
        Return  : None.
        ==========================================================================
  */
-static VOID InsertMeasureReqIE(
-       IN PRTMP_ADAPTER pAd,
-       OUT PUCHAR pFrameBuf,
-       OUT PULONG pFrameLen,
-       IN PMEASURE_REQ_INFO pMeasureReqIE)
+static void InsertMeasureReqIE(struct rt_rtmp_adapter *pAd,
+                              u8 *pFrameBuf,
+                              unsigned long *pFrameLen,
+                              u8 Len, struct rt_measure_req_info * pMeasureReqIE)
 {
-       ULONG TempLen;
-       UINT8 Len = sizeof(MEASURE_REQ_INFO);
-       UINT8 ElementID = IE_MEASUREMENT_REQUEST;
+       unsigned long TempLen;
+       u8 ElementID = IE_MEASUREMENT_REQUEST;
 
-       MakeOutgoingFrame(pFrameBuf,                                    &TempLen,
-                                               1,                                                      &ElementID,
-                                               1,                                                      &Len,
-                                               Len,                                            pMeasureReqIE,
-                                               END_OF_ARGS);
+       MakeOutgoingFrame(pFrameBuf, &TempLen,
+                         1, &ElementID,
+                         1, &Len,
+                         sizeof(struct rt_measure_req_info), pMeasureReqIE, END_OF_ARGS);
 
        *pFrameLen = *pFrameLen + TempLen;
 
@@ -713,33 +1066,27 @@ static VOID InsertMeasureReqIE(
        Return  : None.
        ==========================================================================
  */
-static VOID InsertMeasureReportIE(
-       IN PRTMP_ADAPTER pAd,
-       OUT PUCHAR pFrameBuf,
-       OUT PULONG pFrameLen,
-       IN PMEASURE_REPORT_INFO pMeasureReportIE,
-       IN UINT8 ReportLnfoLen,
-       IN PUINT8 pReportInfo)
+static void InsertMeasureReportIE(struct rt_rtmp_adapter *pAd,
+                                 u8 *pFrameBuf,
+                                 unsigned long *pFrameLen,
+                                 struct rt_measure_report_info * pMeasureReportIE,
+                                 u8 ReportLnfoLen, u8 *pReportInfo)
 {
-       ULONG TempLen;
-       ULONG Len;
-       UINT8 ElementID = IE_MEASUREMENT_REPORT;
+       unsigned long TempLen;
+       unsigned long Len;
+       u8 ElementID = IE_MEASUREMENT_REPORT;
 
-       Len = sizeof(MEASURE_REPORT_INFO) + ReportLnfoLen;
+       Len = sizeof(struct rt_measure_report_info) + ReportLnfoLen;
 
-       MakeOutgoingFrame(pFrameBuf,                                    &TempLen,
-                                               1,                                                      &ElementID,
-                                               1,                                                      &Len,
-                                               Len,                                            pMeasureReportIE,
-                                               END_OF_ARGS);
+       MakeOutgoingFrame(pFrameBuf, &TempLen,
+                         1, &ElementID,
+                         1, &Len, Len, pMeasureReportIE, END_OF_ARGS);
 
        *pFrameLen = *pFrameLen + TempLen;
 
-       if ((ReportLnfoLen > 0) && (pReportInfo != NULL))
-       {
-               MakeOutgoingFrame(pFrameBuf + *pFrameLen,               &TempLen,
-                                                       ReportLnfoLen,                          pReportInfo,
-                                                       END_OF_ARGS);
+       if ((ReportLnfoLen > 0) && (pReportInfo != NULL)) {
+               MakeOutgoingFrame(pFrameBuf + *pFrameLen, &TempLen,
+                                 ReportLnfoLen, pReportInfo, END_OF_ARGS);
 
                *pFrameLen = *pFrameLen + TempLen;
        }
@@ -758,53 +1105,40 @@ static VOID InsertMeasureReportIE(
        Return  : None.
        ==========================================================================
  */
-VOID EnqueueMeasurementReq(
-       IN PRTMP_ADAPTER pAd,
-       IN PUCHAR pDA,
-       IN UINT8 MeasureToken,
-       IN UINT8 MeasureReqMode,
-       IN UINT8 MeasureReqType,
-       IN UINT8 MeasureCh,
-       IN UINT16 MeasureDuration)
+void MakeMeasurementReqFrame(struct rt_rtmp_adapter *pAd,
+                            u8 *pOutBuffer,
+                            unsigned long *pFrameLen,
+                            u8 TotalLen,
+                            u8 Category,
+                            u8 Action,
+                            u8 MeasureToken,
+                            u8 MeasureReqMode,
+                            u8 MeasureReqType, u8 NumOfRepetitions)
 {
-       PUCHAR pOutBuffer = NULL;
-       NDIS_STATUS NStatus;
-       ULONG FrameLen;
-       HEADER_802_11 ActHdr;
-       MEASURE_REQ_INFO MeasureReqIE;
-       UINT8 RmReqDailogToken = RandomByte(pAd);
-       UINT64 MeasureStartTime = GetCurrentTimeStamp(pAd);
-
-       // build action frame header.
-       MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
-                                               pAd->CurrentAddress);
+       unsigned long TempLen;
+       struct rt_measure_req_info MeasureReqIE;
 
-       NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);  //Get an unused nonpaged memory
-       if(NStatus != NDIS_STATUS_SUCCESS)
-       {
-               DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__));
-               return;
-       }
-       NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
-       FrameLen = sizeof(HEADER_802_11);
+       InsertActField(pAd, (pOutBuffer + *pFrameLen), pFrameLen, Category,
+                      Action);
 
-       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRQ);
+       /* fill Dialog Token */
+       InsertDialogToken(pAd, (pOutBuffer + *pFrameLen), pFrameLen,
+                         MeasureToken);
 
-       // fill Dialog Token
-       InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, MeasureToken);
+       /* fill Number of repetitions. */
+       if (Category == CATEGORY_RM) {
+               MakeOutgoingFrame((pOutBuffer + *pFrameLen), &TempLen,
+                                 2, &NumOfRepetitions, END_OF_ARGS);
 
-       // prepare Measurement IE.
-       NdisZeroMemory(&MeasureReqIE, sizeof(MEASURE_REQ_INFO));
-       MeasureReqIE.Token = RmReqDailogToken;
+               *pFrameLen += TempLen;
+       }
+       /* prepare Measurement IE. */
+       NdisZeroMemory(&MeasureReqIE, sizeof(struct rt_measure_req_info));
+       MeasureReqIE.Token = MeasureToken;
        MeasureReqIE.ReqMode.word = MeasureReqMode;
        MeasureReqIE.ReqType = MeasureReqType;
-       MeasureReqIE.MeasureReq.ChNum = MeasureCh;
-       MeasureReqIE.MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime);
-       MeasureReqIE.MeasureReq.MeasureDuration = cpu2le16(MeasureDuration);
-       InsertMeasureReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureReqIE);
-
-       MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
-       MlmeFreeMemory(pAd, pOutBuffer);
+       InsertMeasureReqIE(pAd, (pOutBuffer + *pFrameLen), pFrameLen,
+                          TotalLen, &MeasureReqIE);
 
        return;
 }
@@ -821,46 +1155,46 @@ VOID EnqueueMeasurementReq(
        Return  : None.
        ==========================================================================
  */
-VOID EnqueueMeasurementRep(
-       IN PRTMP_ADAPTER pAd,
-       IN PUCHAR pDA,
-       IN UINT8 DialogToken,
-       IN UINT8 MeasureToken,
-       IN UINT8 MeasureReqMode,
-       IN UINT8 MeasureReqType,
-       IN UINT8 ReportInfoLen,
-       IN PUINT8 pReportInfo)
+void EnqueueMeasurementRep(struct rt_rtmp_adapter *pAd,
+                          u8 *pDA,
+                          u8 DialogToken,
+                          u8 MeasureToken,
+                          u8 MeasureReqMode,
+                          u8 MeasureReqType,
+                          u8 ReportInfoLen, u8 *pReportInfo)
 {
-       PUCHAR pOutBuffer = NULL;
-       NDIS_STATUS NStatus;
-       ULONG FrameLen;
-       HEADER_802_11 ActHdr;
-       MEASURE_REPORT_INFO MeasureRepIE;
+       u8 *pOutBuffer = NULL;
+       int NStatus;
+       unsigned long FrameLen;
+       struct rt_header_802_11 ActHdr;
+       struct rt_measure_report_info MeasureRepIE;
 
-       // build action frame header.
+       /* build action frame header. */
        MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
-                                               pAd->CurrentAddress);
+                        pAd->CurrentAddress);
 
-       NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);  //Get an unused nonpaged memory
-       if(NStatus != NDIS_STATUS_SUCCESS)
-       {
-               DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__));
+       NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer);        /*Get an unused nonpaged memory */
+       if (NStatus != NDIS_STATUS_SUCCESS) {
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("%s() allocate memory failed \n", __func__));
                return;
        }
-       NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
-       FrameLen = sizeof(HEADER_802_11);
+       NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
+       FrameLen = sizeof(struct rt_header_802_11);
 
-       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRP);
+       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
+                      CATEGORY_SPECTRUM, SPEC_MRP);
 
-       // fill Dialog Token
+       /* fill Dialog Token */
        InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
 
-       // prepare Measurement IE.
-       NdisZeroMemory(&MeasureRepIE, sizeof(MEASURE_REPORT_INFO));
+       /* prepare Measurement IE. */
+       NdisZeroMemory(&MeasureRepIE, sizeof(struct rt_measure_report_info));
        MeasureRepIE.Token = MeasureToken;
-       MeasureRepIE.ReportMode.word = MeasureReqMode;
+       MeasureRepIE.ReportMode = MeasureReqMode;
        MeasureRepIE.ReportType = MeasureReqType;
-       InsertMeasureReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureRepIE, ReportInfoLen, pReportInfo);
+       InsertMeasureReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen,
+                             &MeasureRepIE, ReportInfoLen, pReportInfo);
 
        MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
        MlmeFreeMemory(pAd, pOutBuffer);
@@ -880,36 +1214,34 @@ VOID EnqueueMeasurementRep(
        Return  : None.
        ==========================================================================
  */
-VOID EnqueueTPCReq(
-       IN PRTMP_ADAPTER pAd,
-       IN PUCHAR pDA,
-       IN UCHAR DialogToken)
+void EnqueueTPCReq(struct rt_rtmp_adapter *pAd, u8 *pDA, u8 DialogToken)
 {
-       PUCHAR pOutBuffer = NULL;
-       NDIS_STATUS NStatus;
-       ULONG FrameLen;
+       u8 *pOutBuffer = NULL;
+       int NStatus;
+       unsigned long FrameLen;
 
-       HEADER_802_11 ActHdr;
+       struct rt_header_802_11 ActHdr;
 
-       // build action frame header.
+       /* build action frame header. */
        MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
-                                               pAd->CurrentAddress);
+                        pAd->CurrentAddress);
 
-       NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);  //Get an unused nonpaged memory
-       if(NStatus != NDIS_STATUS_SUCCESS)
-       {
-               DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__));
+       NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer);        /*Get an unused nonpaged memory */
+       if (NStatus != NDIS_STATUS_SUCCESS) {
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("%s() allocate memory failed \n", __func__));
                return;
        }
-       NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
-       FrameLen = sizeof(HEADER_802_11);
+       NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
+       FrameLen = sizeof(struct rt_header_802_11);
 
-       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRQ);
+       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
+                      CATEGORY_SPECTRUM, SPEC_TPCRQ);
 
-       // fill Dialog Token
+       /* fill Dialog Token */
        InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
 
-       // Insert TPC Request IE.
+       /* Insert TPC Request IE. */
        InsertTpcReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen);
 
        MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
@@ -930,39 +1262,38 @@ VOID EnqueueTPCReq(
        Return  : None.
        ==========================================================================
  */
-VOID EnqueueTPCRep(
-       IN PRTMP_ADAPTER pAd,
-       IN PUCHAR pDA,
-       IN UINT8 DialogToken,
-       IN UINT8 TxPwr,
-       IN UINT8 LinkMargin)
+void EnqueueTPCRep(struct rt_rtmp_adapter *pAd,
+                  u8 *pDA,
+                  u8 DialogToken, u8 TxPwr, u8 LinkMargin)
 {
-       PUCHAR pOutBuffer = NULL;
-       NDIS_STATUS NStatus;
-       ULONG FrameLen;
+       u8 *pOutBuffer = NULL;
+       int NStatus;
+       unsigned long FrameLen;
 
-       HEADER_802_11 ActHdr;
+       struct rt_header_802_11 ActHdr;
 
-       // build action frame header.
+       /* build action frame header. */
        MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
-                                               pAd->CurrentAddress);
+                        pAd->CurrentAddress);
 
-       NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);  //Get an unused nonpaged memory
-       if(NStatus != NDIS_STATUS_SUCCESS)
-       {
-               DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__));
+       NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer);        /*Get an unused nonpaged memory */
+       if (NStatus != NDIS_STATUS_SUCCESS) {
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("%s() allocate memory failed \n", __func__));
                return;
        }
-       NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
-       FrameLen = sizeof(HEADER_802_11);
+       NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
+       FrameLen = sizeof(struct rt_header_802_11);
 
-       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_TPCRP);
+       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
+                      CATEGORY_SPECTRUM, SPEC_TPCRP);
 
-       // fill Dialog Token
+       /* fill Dialog Token */
        InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
 
-       // Insert TPC Request IE.
-       InsertTpcReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, TxPwr, LinkMargin);
+       /* Insert TPC Request IE. */
+       InsertTpcReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, TxPwr,
+                         LinkMargin);
 
        MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
        MlmeFreeMemory(pAd, pOutBuffer);
@@ -984,34 +1315,33 @@ VOID EnqueueTPCRep(
        Return  : None.
        ==========================================================================
  */
-VOID EnqueueChSwAnn(
-       IN PRTMP_ADAPTER pAd,
-       IN PUCHAR pDA,
-       IN UINT8 ChSwMode,
-       IN UINT8 NewCh)
+void EnqueueChSwAnn(struct rt_rtmp_adapter *pAd,
+                   u8 *pDA, u8 ChSwMode, u8 NewCh)
 {
-       PUCHAR pOutBuffer = NULL;
-       NDIS_STATUS NStatus;
-       ULONG FrameLen;
+       u8 *pOutBuffer = NULL;
+       int NStatus;
+       unsigned long FrameLen;
 
-       HEADER_802_11 ActHdr;
+       struct rt_header_802_11 ActHdr;
 
-       // build action frame header.
+       /* build action frame header. */
        MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
-                                               pAd->CurrentAddress);
+                        pAd->CurrentAddress);
 
-       NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);  //Get an unused nonpaged memory
-       if(NStatus != NDIS_STATUS_SUCCESS)
-       {
-               DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__));
+       NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer);        /*Get an unused nonpaged memory */
+       if (NStatus != NDIS_STATUS_SUCCESS) {
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("%s() allocate memory failed \n", __func__));
                return;
        }
-       NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
-       FrameLen = sizeof(HEADER_802_11);
+       NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
+       FrameLen = sizeof(struct rt_header_802_11);
 
-       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_CHANNEL_SWITCH);
+       InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
+                      CATEGORY_SPECTRUM, SPEC_CHANNEL_SWITCH);
 
-       InsertChSwAnnIE(pAd, (pOutBuffer + FrameLen), &FrameLen, ChSwMode, NewCh, 0);
+       InsertChSwAnnIE(pAd, (pOutBuffer + FrameLen), &FrameLen, ChSwMode,
+                       NewCh, 0);
 
        MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
        MlmeFreeMemory(pAd, pOutBuffer);
@@ -1019,59 +1349,47 @@ VOID EnqueueChSwAnn(
        return;
 }
 
-static BOOLEAN DfsRequirementCheck(
-       IN PRTMP_ADAPTER pAd,
-       IN UINT8 Channel)
+static BOOLEAN DfsRequirementCheck(struct rt_rtmp_adapter *pAd, u8 Channel)
 {
        BOOLEAN Result = FALSE;
-       INT i;
+       int i;
 
-       do
-       {
-               // check DFS procedure is running.
-               // make sure DFS procedure won't start twice.
-               if (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
-               {
+       do {
+               /* check DFS procedure is running. */
+               /* make sure DFS procedure won't start twice. */
+               if (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) {
                        Result = FALSE;
                        break;
                }
-
-               // check the new channel carried from Channel Switch Announcemnet is valid.
-               for (i=0; i<pAd->ChannelListNum; i++)
-               {
+               /* check the new channel carried from Channel Switch Announcemnet is valid. */
+               for (i = 0; i < pAd->ChannelListNum; i++) {
                        if ((Channel == pAd->ChannelList[i].Channel)
-                               &&(pAd->ChannelList[i].RemainingTimeForUse == 0))
-                       {
-                               // found radar signal in the channel. the channel can't use at least for 30 minutes.
-                               pAd->ChannelList[i].RemainingTimeForUse = 1800;//30 min = 1800 sec
+                           && (pAd->ChannelList[i].RemainingTimeForUse == 0)) {
+                               /* found radar signal in the channel. the channel can't use at least for 30 minutes. */
+                               pAd->ChannelList[i].RemainingTimeForUse = 1800; /*30 min = 1800 sec */
                                Result = TRUE;
                                break;
                        }
                }
-       } while(FALSE);
+       } while (FALSE);
 
        return Result;
 }
 
-VOID NotifyChSwAnnToPeerAPs(
-       IN PRTMP_ADAPTER pAd,
-       IN PUCHAR pRA,
-       IN PUCHAR pTA,
-       IN UINT8 ChSwMode,
-       IN UINT8 Channel)
+void NotifyChSwAnnToPeerAPs(struct rt_rtmp_adapter *pAd,
+                           u8 *pRA,
+                           u8 *pTA, u8 ChSwMode, u8 Channel)
 {
 }
 
-static VOID StartDFSProcedure(
-       IN PRTMP_ADAPTER pAd,
-       IN UCHAR Channel,
-       IN UINT8 ChSwMode)
+static void StartDFSProcedure(struct rt_rtmp_adapter *pAd,
+                             u8 Channel, u8 ChSwMode)
 {
-       // start DFS procedure
+       /* start DFS procedure */
        pAd->CommonCfg.Channel = Channel;
-#ifdef DOT11_N_SUPPORT
+
        N_ChannelCheck(pAd);
-#endif // DOT11_N_SUPPORT //
+
        pAd->CommonCfg.RadarDetect.RDMode = RD_SWITCHING_MODE;
        pAd->CommonCfg.RadarDetect.CSCount = 0;
 }
@@ -1086,7 +1404,6 @@ static VOID StartDFSProcedure(
                2. message length.
                3. Channel switch announcement infomation buffer.
 
-
        Return  : None.
        ==========================================================================
  */
@@ -1098,44 +1415,45 @@ static VOID StartDFSProcedure(
   +----+-----+-----------+------------+-----------+
     1    1        1           1            1
 */
-static BOOLEAN PeerChSwAnnSanity(
-       IN PRTMP_ADAPTER pAd,
-       IN VOID *pMsg,
-       IN ULONG MsgLen,
-       OUT PCH_SW_ANN_INFO pChSwAnnInfo)
+static BOOLEAN PeerChSwAnnSanity(struct rt_rtmp_adapter *pAd,
+                                void * pMsg,
+                                unsigned long MsgLen,
+                                struct rt_ch_sw_ann_info * pChSwAnnInfo)
 {
-       PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
-       PUCHAR pFramePtr = Fr->Octet;
+       struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
+       u8 *pFramePtr = Fr->Octet;
        BOOLEAN result = FALSE;
-       PEID_STRUCT eid_ptr;
+       struct rt_eid * eid_ptr;
 
-       // skip 802.11 header.
-       MsgLen -= sizeof(HEADER_802_11);
+       /* skip 802.11 header. */
+       MsgLen -= sizeof(struct rt_header_802_11);
 
-       // skip category and action code.
+       /* skip category and action code. */
        pFramePtr += 2;
        MsgLen -= 2;
 
        if (pChSwAnnInfo == NULL)
                return result;
 
-       eid_ptr = (PEID_STRUCT)pFramePtr;
-       while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
-       {
-               switch(eid_ptr->Eid)
-               {
-                       case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
-                               NdisMoveMemory(&pChSwAnnInfo->ChSwMode, eid_ptr->Octet, 1);
-                               NdisMoveMemory(&pChSwAnnInfo->Channel, eid_ptr->Octet + 1, 1);
-                               NdisMoveMemory(&pChSwAnnInfo->ChSwCnt, eid_ptr->Octet + 2, 1);
-
-                               result = TRUE;
-                break;
+       eid_ptr = (struct rt_eid *) pFramePtr;
+       while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
+              ((u8 *)pFramePtr + MsgLen)) {
+               switch (eid_ptr->Eid) {
+               case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
+                       NdisMoveMemory(&pChSwAnnInfo->ChSwMode, eid_ptr->Octet,
+                                      1);
+                       NdisMoveMemory(&pChSwAnnInfo->Channel,
+                                      eid_ptr->Octet + 1, 1);
+                       NdisMoveMemory(&pChSwAnnInfo->ChSwCnt,
+                                      eid_ptr->Octet + 2, 1);
+
+                       result = TRUE;
+                       break;
 
-                       default:
-                               break;
+               default:
+                       break;
                }
-               eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
+               eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
        }
 
        return result;
@@ -1154,25 +1472,25 @@ static BOOLEAN PeerChSwAnnSanity(
        Return  : None.
        ==========================================================================
  */
-static BOOLEAN PeerMeasureReqSanity(
-       IN PRTMP_ADAPTER pAd,
-       IN VOID *pMsg,
-       IN ULONG MsgLen,
-       OUT PUINT8 pDialogToken,
-       OUT PMEASURE_REQ_INFO pMeasureReqInfo)
+static BOOLEAN PeerMeasureReqSanity(struct rt_rtmp_adapter *pAd,
+                                   void * pMsg,
+                                   unsigned long MsgLen,
+                                   u8 *pDialogToken,
+                                   struct rt_measure_req_info * pMeasureReqInfo,
+                                   struct rt_measure_req * pMeasureReq)
 {
-       PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
-       PUCHAR pFramePtr = Fr->Octet;
+       struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
+       u8 *pFramePtr = Fr->Octet;
        BOOLEAN result = FALSE;
-       PEID_STRUCT eid_ptr;
-       PUCHAR ptr;
-       UINT64 MeasureStartTime;
-       UINT16 MeasureDuration;
+       struct rt_eid * eid_ptr;
+       u8 *ptr;
+       u64 MeasureStartTime;
+       u16 MeasureDuration;
 
-       // skip 802.11 header.
-       MsgLen -= sizeof(HEADER_802_11);
+       /* skip 802.11 header. */
+       MsgLen -= sizeof(struct rt_header_802_11);
 
-       // skip category and action code.
+       /* skip category and action code. */
        pFramePtr += 2;
        MsgLen -= 2;
 
@@ -1183,29 +1501,32 @@ static BOOLEAN PeerMeasureReqSanity(
        pFramePtr += 1;
        MsgLen -= 1;
 
-       eid_ptr = (PEID_STRUCT)pFramePtr;
-       while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
-       {
-               switch(eid_ptr->Eid)
-               {
-                       case IE_MEASUREMENT_REQUEST:
-                               NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet, 1);
-                               NdisMoveMemory(&pMeasureReqInfo->ReqMode.word, eid_ptr->Octet + 1, 1);
-                               NdisMoveMemory(&pMeasureReqInfo->ReqType, eid_ptr->Octet + 2, 1);
-                               ptr = eid_ptr->Octet + 3;
-                               NdisMoveMemory(&pMeasureReqInfo->MeasureReq.ChNum, ptr, 1);
-                               NdisMoveMemory(&MeasureStartTime, ptr + 1, 8);
-                               pMeasureReqInfo->MeasureReq.MeasureStartTime = SWAP64(MeasureStartTime);
-                               NdisMoveMemory(&MeasureDuration, ptr + 9, 2);
-                               pMeasureReqInfo->MeasureReq.MeasureDuration = SWAP16(MeasureDuration);
-
-                               result = TRUE;
-                               break;
+       eid_ptr = (struct rt_eid *) pFramePtr;
+       while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
+              ((u8 *)pFramePtr + MsgLen)) {
+               switch (eid_ptr->Eid) {
+               case IE_MEASUREMENT_REQUEST:
+                       NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet,
+                                      1);
+                       NdisMoveMemory(&pMeasureReqInfo->ReqMode.word,
+                                      eid_ptr->Octet + 1, 1);
+                       NdisMoveMemory(&pMeasureReqInfo->ReqType,
+                                      eid_ptr->Octet + 2, 1);
+                       ptr = (u8 *)(eid_ptr->Octet + 3);
+                       NdisMoveMemory(&pMeasureReq->ChNum, ptr, 1);
+                       NdisMoveMemory(&MeasureStartTime, ptr + 1, 8);
+                       pMeasureReq->MeasureStartTime =
+                           SWAP64(MeasureStartTime);
+                       NdisMoveMemory(&MeasureDuration, ptr + 9, 2);
+                       pMeasureReq->MeasureDuration = SWAP16(MeasureDuration);
+
+                       result = TRUE;
+                       break;
 
-                       default:
-                               break;
+               default:
+                       break;
                }
-               eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
+               eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
        }
 
        return result;
@@ -1245,24 +1566,24 @@ static BOOLEAN PeerMeasureReqSanity(
   +-----+---------------+---------------------+-------+------------+----------+
      0          1                  2              3         4          5-7
 */
-static BOOLEAN PeerMeasureReportSanity(
-       IN PRTMP_ADAPTER pAd,
-       IN VOID *pMsg,
-       IN ULONG MsgLen,
-       OUT PUINT8 pDialogToken,
-       OUT PMEASURE_REPORT_INFO pMeasureReportInfo,
-       OUT PUINT8 pReportBuf)
+static BOOLEAN PeerMeasureReportSanity(struct rt_rtmp_adapter *pAd,
+                                      void * pMsg,
+                                      unsigned long MsgLen,
+                                      u8 *pDialogToken,
+                                      struct rt_measure_report_info *
+                                      pMeasureReportInfo,
+                                      u8 *pReportBuf)
 {
-       PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
-       PUCHAR pFramePtr = Fr->Octet;
+       struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
+       u8 *pFramePtr = Fr->Octet;
        BOOLEAN result = FALSE;
-       PEID_STRUCT eid_ptr;
-       PUCHAR ptr;
+       struct rt_eid * eid_ptr;
+       u8 *ptr;
 
-       // skip 802.11 header.
-       MsgLen -= sizeof(HEADER_802_11);
+       /* skip 802.11 header. */
+       MsgLen -= sizeof(struct rt_header_802_11);
 
-       // skip category and action code.
+       /* skip category and action code. */
        pFramePtr += 2;
        MsgLen -= 2;
 
@@ -1273,51 +1594,60 @@ static BOOLEAN PeerMeasureReportSanity(
        pFramePtr += 1;
        MsgLen -= 1;
 
-       eid_ptr = (PEID_STRUCT)pFramePtr;
-       while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
-       {
-               switch(eid_ptr->Eid)
-               {
-                       case IE_MEASUREMENT_REPORT:
-                               NdisMoveMemory(&pMeasureReportInfo->Token, eid_ptr->Octet, 1);
-                               NdisMoveMemory(&pMeasureReportInfo->ReportMode, eid_ptr->Octet + 1, 1);
-                               NdisMoveMemory(&pMeasureReportInfo->ReportType, eid_ptr->Octet + 2, 1);
-                               if (pMeasureReportInfo->ReportType == RM_BASIC)
-                               {
-                                       PMEASURE_BASIC_REPORT pReport = (PMEASURE_BASIC_REPORT)pReportBuf;
-                                       ptr = eid_ptr->Octet + 3;
-                                       NdisMoveMemory(&pReport->ChNum, ptr, 1);
-                                       NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
-                                       NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
-                                       NdisMoveMemory(&pReport->Map, ptr + 11, 1);
-
-                               }
-                               else if (pMeasureReportInfo->ReportType == RM_CCA)
-                               {
-                                       PMEASURE_CCA_REPORT pReport = (PMEASURE_CCA_REPORT)pReportBuf;
-                                       ptr = eid_ptr->Octet + 3;
-                                       NdisMoveMemory(&pReport->ChNum, ptr, 1);
-                                       NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
-                                       NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
-                                       NdisMoveMemory(&pReport->CCA_Busy_Fraction, ptr + 11, 1);
-
-                               }
-                               else if (pMeasureReportInfo->ReportType == RM_RPI_HISTOGRAM)
-                               {
-                                       PMEASURE_RPI_REPORT pReport = (PMEASURE_RPI_REPORT)pReportBuf;
-                                       ptr = eid_ptr->Octet + 3;
-                                       NdisMoveMemory(&pReport->ChNum, ptr, 1);
-                                       NdisMoveMemory(&pReport->MeasureStartTime, ptr + 1, 8);
-                                       NdisMoveMemory(&pReport->MeasureDuration, ptr + 9, 2);
-                                       NdisMoveMemory(&pReport->RPI_Density, ptr + 11, 8);
-                               }
-                               result = TRUE;
-                break;
+       eid_ptr = (struct rt_eid *) pFramePtr;
+       while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
+              ((u8 *)pFramePtr + MsgLen)) {
+               switch (eid_ptr->Eid) {
+               case IE_MEASUREMENT_REPORT:
+                       NdisMoveMemory(&pMeasureReportInfo->Token,
+                                      eid_ptr->Octet, 1);
+                       NdisMoveMemory(&pMeasureReportInfo->ReportMode,
+                                      eid_ptr->Octet + 1, 1);
+                       NdisMoveMemory(&pMeasureReportInfo->ReportType,
+                                      eid_ptr->Octet + 2, 1);
+                       if (pMeasureReportInfo->ReportType == RM_BASIC) {
+                               struct rt_measure_basic_report * pReport =
+                                   (struct rt_measure_basic_report *) pReportBuf;
+                               ptr = (u8 *)(eid_ptr->Octet + 3);
+                               NdisMoveMemory(&pReport->ChNum, ptr, 1);
+                               NdisMoveMemory(&pReport->MeasureStartTime,
+                                              ptr + 1, 8);
+                               NdisMoveMemory(&pReport->MeasureDuration,
+                                              ptr + 9, 2);
+                               NdisMoveMemory(&pReport->Map, ptr + 11, 1);
+
+                       } else if (pMeasureReportInfo->ReportType == RM_CCA) {
+                               struct rt_measure_cca_report * pReport =
+                                   (struct rt_measure_cca_report *) pReportBuf;
+                               ptr = (u8 *)(eid_ptr->Octet + 3);
+                               NdisMoveMemory(&pReport->ChNum, ptr, 1);
+                               NdisMoveMemory(&pReport->MeasureStartTime,
+                                              ptr + 1, 8);
+                               NdisMoveMemory(&pReport->MeasureDuration,
+                                              ptr + 9, 2);
+                               NdisMoveMemory(&pReport->CCA_Busy_Fraction,
+                                              ptr + 11, 1);
+
+                       } else if (pMeasureReportInfo->ReportType ==
+                                  RM_RPI_HISTOGRAM) {
+                               struct rt_measure_rpi_report * pReport =
+                                   (struct rt_measure_rpi_report *) pReportBuf;
+                               ptr = (u8 *)(eid_ptr->Octet + 3);
+                               NdisMoveMemory(&pReport->ChNum, ptr, 1);
+                               NdisMoveMemory(&pReport->MeasureStartTime,
+                                              ptr + 1, 8);
+                               NdisMoveMemory(&pReport->MeasureDuration,
+                                              ptr + 9, 2);
+                               NdisMoveMemory(&pReport->RPI_Density, ptr + 11,
+                                              8);
+                       }
+                       result = TRUE;
+                       break;
 
-                       default:
-                               break;
+               default:
+                       break;
                }
-               eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
+               eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
        }
 
        return result;
@@ -1336,20 +1666,18 @@ static BOOLEAN PeerMeasureReportSanity(
        Return  : None.
        ==========================================================================
  */
-static BOOLEAN PeerTpcReqSanity(
-       IN PRTMP_ADAPTER pAd,
-       IN VOID *pMsg,
-       IN ULONG MsgLen,
-       OUT PUINT8 pDialogToken)
+static BOOLEAN PeerTpcReqSanity(struct rt_rtmp_adapter *pAd,
+                               void * pMsg,
+                               unsigned long MsgLen, u8 *pDialogToken)
 {
-       PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
-       PUCHAR pFramePtr = Fr->Octet;
+       struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
+       u8 *pFramePtr = Fr->Octet;
        BOOLEAN result = FALSE;
-       PEID_STRUCT eid_ptr;
+       struct rt_eid * eid_ptr;
 
-       MsgLen -= sizeof(HEADER_802_11);
+       MsgLen -= sizeof(struct rt_header_802_11);
 
-       // skip category and action code.
+       /* skip category and action code. */
        pFramePtr += 2;
        MsgLen -= 2;
 
@@ -1360,19 +1688,18 @@ static BOOLEAN PeerTpcReqSanity(
        pFramePtr += 1;
        MsgLen -= 1;
 
-       eid_ptr = (PEID_STRUCT)pFramePtr;
-       while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
-       {
-               switch(eid_ptr->Eid)
-               {
-                       case IE_TPC_REQUEST:
-                               result = TRUE;
-                break;
+       eid_ptr = (struct rt_eid *) pFramePtr;
+       while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
+              ((u8 *)pFramePtr + MsgLen)) {
+               switch (eid_ptr->Eid) {
+               case IE_TPC_REQUEST:
+                       result = TRUE;
+                       break;
 
-                       default:
-                               break;
+               default:
+                       break;
                }
-               eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
+               eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
        }
 
        return result;
@@ -1392,21 +1719,20 @@ static BOOLEAN PeerTpcReqSanity(
        Return  : None.
        ==========================================================================
  */
-static BOOLEAN PeerTpcRepSanity(
-       IN PRTMP_ADAPTER pAd,
-       IN VOID *pMsg,
-       IN ULONG MsgLen,
-       OUT PUINT8 pDialogToken,
-       OUT PTPC_REPORT_INFO pTpcRepInfo)
+static BOOLEAN PeerTpcRepSanity(struct rt_rtmp_adapter *pAd,
+                               void * pMsg,
+                               unsigned long MsgLen,
+                               u8 *pDialogToken,
+                               struct rt_tpc_report_info * pTpcRepInfo)
 {
-       PFRAME_802_11 Fr = (PFRAME_802_11)pMsg;
-       PUCHAR pFramePtr = Fr->Octet;
+       struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
+       u8 *pFramePtr = Fr->Octet;
        BOOLEAN result = FALSE;
-       PEID_STRUCT eid_ptr;
+       struct rt_eid * eid_ptr;
 
-       MsgLen -= sizeof(HEADER_802_11);
+       MsgLen -= sizeof(struct rt_header_802_11);
 
-       // skip category and action code.
+       /* skip category and action code. */
        pFramePtr += 2;
        MsgLen -= 2;
 
@@ -1417,21 +1743,21 @@ static BOOLEAN PeerTpcRepSanity(
        pFramePtr += 1;
        MsgLen -= 1;
 
-       eid_ptr = (PEID_STRUCT)pFramePtr;
-       while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen))
-       {
-               switch(eid_ptr->Eid)
-               {
-                       case IE_TPC_REPORT:
-                               NdisMoveMemory(&pTpcRepInfo->TxPwr, eid_ptr->Octet, 1);
-                               NdisMoveMemory(&pTpcRepInfo->LinkMargin, eid_ptr->Octet + 1, 1);
-                               result = TRUE;
-                break;
-
-                       default:
-                               break;
+       eid_ptr = (struct rt_eid *) pFramePtr;
+       while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
+              ((u8 *)pFramePtr + MsgLen)) {
+               switch (eid_ptr->Eid) {
+               case IE_TPC_REPORT:
+                       NdisMoveMemory(&pTpcRepInfo->TxPwr, eid_ptr->Octet, 1);
+                       NdisMoveMemory(&pTpcRepInfo->LinkMargin,
+                                      eid_ptr->Octet + 1, 1);
+                       result = TRUE;
+                       break;
+
+               default:
+                       break;
                }
-               eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len);
+               eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
        }
 
        return result;
@@ -1448,64 +1774,69 @@ static BOOLEAN PeerTpcRepSanity(
        Return  : None.
        ==========================================================================
  */
-static VOID PeerChSwAnnAction(
-       IN PRTMP_ADAPTER pAd,
-       IN MLME_QUEUE_ELEM *Elem)
+static void PeerChSwAnnAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
 {
-       CH_SW_ANN_INFO ChSwAnnInfo;
-       PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
-       UCHAR index = 0, Channel = 0, NewChannel = 0;
-       ULONG Bssidx = 0;
-
-       NdisZeroMemory(&ChSwAnnInfo, sizeof(CH_SW_ANN_INFO));
-       if (! PeerChSwAnnSanity(pAd, Elem->Msg, Elem->MsgLen, &ChSwAnnInfo))
-       {
-               DBGPRINT(RT_DEBUG_TRACE, ("Invalid Channel Switch Action Frame.\n"));
+       struct rt_ch_sw_ann_info ChSwAnnInfo;
+       struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
+       u8 index = 0, Channel = 0, NewChannel = 0;
+       unsigned long Bssidx = 0;
+
+       NdisZeroMemory(&ChSwAnnInfo, sizeof(struct rt_ch_sw_ann_info));
+       if (!PeerChSwAnnSanity(pAd, Elem->Msg, Elem->MsgLen, &ChSwAnnInfo)) {
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("Invalid Channel Switch Action Frame.\n"));
                return;
        }
 
-       if (pAd->OpMode == OPMODE_STA)
-       {
-               Bssidx = BssTableSearch(&pAd->ScanTab, pFr->Hdr.Addr3, pAd->CommonCfg.Channel);
-               if (Bssidx == BSS_NOT_FOUND)
-               {
-                       DBGPRINT(RT_DEBUG_TRACE, ("PeerChSwAnnAction - Bssidx is not found\n"));
+       if (pAd->OpMode == OPMODE_STA) {
+               Bssidx =
+                   BssTableSearch(&pAd->ScanTab, pFr->Hdr.Addr3,
+                                  pAd->CommonCfg.Channel);
+               if (Bssidx == BSS_NOT_FOUND) {
+                       DBGPRINT(RT_DEBUG_TRACE,
+                                ("PeerChSwAnnAction - Bssidx is not found\n"));
                        return;
                }
 
-               DBGPRINT(RT_DEBUG_TRACE, ("\n****Bssidx is %d, Channel = %d\n", index, pAd->ScanTab.BssEntry[Bssidx].Channel));
-               hex_dump("SSID",pAd->ScanTab.BssEntry[Bssidx].Bssid ,6);
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("\n****Bssidx is %d, Channel = %d\n", index,
+                         pAd->ScanTab.BssEntry[Bssidx].Channel));
+               hex_dump("SSID", pAd->ScanTab.BssEntry[Bssidx].Bssid, 6);
 
                Channel = pAd->CommonCfg.Channel;
                NewChannel = ChSwAnnInfo.Channel;
 
-               if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel))
-               {
-                       // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection).
-                       // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results.
+               if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0)
+                   && (Channel != NewChannel)) {
+                       /* Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection). */
+                       /* In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results. */
                        AsicSwitchChannel(pAd, 1, FALSE);
                        AsicLockChannel(pAd, 1);
-                   LinkDown(pAd, FALSE);
+                       LinkDown(pAd, FALSE);
                        MlmeQueueInit(&pAd->Mlme.Queue);
                        BssTableInit(&pAd->ScanTab);
-                   RTMPusecDelay(1000000);             // use delay to prevent STA do reassoc
-
-                       // channel sanity check
-                       for (index = 0 ; index < pAd->ChannelListNum; index++)
-                       {
-                               if (pAd->ChannelList[index].Channel == NewChannel)
-                               {
-                                       pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel;
+                       RTMPusecDelay(1000000); /* use delay to prevent STA do reassoc */
+
+                       /* channel sanity check */
+                       for (index = 0; index < pAd->ChannelListNum; index++) {
+                               if (pAd->ChannelList[index].Channel ==
+                                   NewChannel) {
+                                       pAd->ScanTab.BssEntry[Bssidx].Channel =
+                                           NewChannel;
                                        pAd->CommonCfg.Channel = NewChannel;
-                                       AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
-                                       AsicLockChannel(pAd, pAd->CommonCfg.Channel);
-                                       DBGPRINT(RT_DEBUG_TRACE, ("&&&&&&&&&&&&&&&&PeerChSwAnnAction - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel));
+                                       AsicSwitchChannel(pAd,
+                                                         pAd->CommonCfg.
+                                                         Channel, FALSE);
+                                       AsicLockChannel(pAd,
+                                                       pAd->CommonCfg.Channel);
+                                       DBGPRINT(RT_DEBUG_TRACE,
+                                                ("&&&&&&&&&&&&&&&&PeerChSwAnnAction - STA receive channel switch announcement IE (New Channel =%d)\n",
+                                                 NewChannel));
                                        break;
                                }
                        }
 
-                       if (index >= pAd->ChannelListNum)
-                       {
+                       if (index >= pAd->ChannelListNum) {
                                DBGPRINT_ERR(("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum));
                        }
                }
@@ -1514,7 +1845,6 @@ static VOID PeerChSwAnnAction(
        return;
 }
 
-
 /*
        ==========================================================================
        Description:
@@ -1526,20 +1856,23 @@ static VOID PeerChSwAnnAction(
        Return  : None.
        ==========================================================================
  */
-static VOID PeerMeasureReqAction(
-       IN PRTMP_ADAPTER pAd,
-       IN MLME_QUEUE_ELEM *Elem)
+static void PeerMeasureReqAction(struct rt_rtmp_adapter *pAd,
+                                struct rt_mlme_queue_elem *Elem)
 {
-       PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
-       UINT8 DialogToken;
-       MEASURE_REQ_INFO MeasureReqInfo;
+       struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
+       u8 DialogToken;
+       struct rt_measure_req_info MeasureReqInfo;
+       struct rt_measure_req MeasureReq;
        MEASURE_REPORT_MODE ReportMode;
 
-       if(PeerMeasureReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReqInfo))
-       {
+       if (PeerMeasureReqSanity
+           (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReqInfo,
+            &MeasureReq)) {
                ReportMode.word = 0;
                ReportMode.field.Incapable = 1;
-               EnqueueMeasurementRep(pAd, pFr->Hdr.Addr2, DialogToken, MeasureReqInfo.Token, ReportMode.word, MeasureReqInfo.ReqType, 0, NULL);
+               EnqueueMeasurementRep(pAd, pFr->Hdr.Addr2, DialogToken,
+                                     MeasureReqInfo.Token, ReportMode.word,
+                                     MeasureReqInfo.ReqType, 0, NULL);
        }
 
        return;
@@ -1556,54 +1889,65 @@ static VOID PeerMeasureReqAction(
        Return  : None.
        ==========================================================================
  */
-static VOID PeerMeasureReportAction(
-       IN PRTMP_ADAPTER pAd,
-       IN MLME_QUEUE_ELEM *Elem)
+static void PeerMeasureReportAction(struct rt_rtmp_adapter *pAd,
+                                   struct rt_mlme_queue_elem *Elem)
 {
-       MEASURE_REPORT_INFO MeasureReportInfo;
-       PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
-       UINT8 DialogToken;
-       PUINT8 pMeasureReportInfo;
-
-//     if (pAd->CommonCfg.bIEEE80211H != TRUE)
-//             return;
-
-       if ((pMeasureReportInfo = kmalloc(sizeof(MEASURE_RPI_REPORT), GFP_ATOMIC)) == NULL)
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s unable to alloc memory for measure report buffer (size=%zu).\n", __func__, sizeof(MEASURE_RPI_REPORT)));
+       struct rt_measure_report_info MeasureReportInfo;
+       struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
+       u8 DialogToken;
+       u8 *pMeasureReportInfo;
+
+/*      if (pAd->CommonCfg.bIEEE80211H != TRUE) */
+/*              return; */
+
+       pMeasureReportInfo = kmalloc(sizeof(struct rt_measure_rpi_report), GFP_ATOMIC);
+       if (pMeasureReportInfo == NULL) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s unable to alloc memory for measure report buffer (size=%zu).\n",
+                         __func__, sizeof(struct rt_measure_rpi_report)));
                return;
        }
 
-       NdisZeroMemory(&MeasureReportInfo, sizeof(MEASURE_REPORT_INFO));
-       NdisZeroMemory(pMeasureReportInfo, sizeof(MEASURE_RPI_REPORT));
-       if (PeerMeasureReportSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReportInfo, pMeasureReportInfo))
-       {
+       NdisZeroMemory(&MeasureReportInfo, sizeof(struct rt_measure_report_info));
+       NdisZeroMemory(pMeasureReportInfo, sizeof(struct rt_measure_rpi_report));
+       if (PeerMeasureReportSanity
+           (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReportInfo,
+            pMeasureReportInfo)) {
                do {
-                       PMEASURE_REQ_ENTRY pEntry = NULL;
+                       struct rt_measure_req_entry *pEntry = NULL;
 
-                       // Not a autonomous measure report.
-                       // check the dialog token field. drop it if the dialog token doesn't match.
+                       /* Not a autonomous measure report. */
+                       /* check the dialog token field. drop it if the dialog token doesn't match. */
                        if ((DialogToken != 0)
-                               && ((pEntry = MeasureReqLookUp(pAd, DialogToken)) == NULL))
+                           && ((pEntry = MeasureReqLookUp(pAd, DialogToken)) ==
+                               NULL))
                                break;
 
                        if (pEntry != NULL)
                                MeasureReqDelete(pAd, pEntry->DialogToken);
 
-                       if (MeasureReportInfo.ReportType == RM_BASIC)
-                       {
-                               PMEASURE_BASIC_REPORT pBasicReport = (PMEASURE_BASIC_REPORT)pMeasureReportInfo;
+                       if (MeasureReportInfo.ReportType == RM_BASIC) {
+                               struct rt_measure_basic_report * pBasicReport =
+                                   (struct rt_measure_basic_report *) pMeasureReportInfo;
                                if ((pBasicReport->Map.field.Radar)
-                                       && (DfsRequirementCheck(pAd, pBasicReport->ChNum) == TRUE))
-                               {
-                                       NotifyChSwAnnToPeerAPs(pAd, pFr->Hdr.Addr1, pFr->Hdr.Addr2, 1, pBasicReport->ChNum);
-                                       StartDFSProcedure(pAd, pBasicReport->ChNum, 1);
+                                   &&
+                                   (DfsRequirementCheck
+                                    (pAd, pBasicReport->ChNum) == TRUE)) {
+                                       NotifyChSwAnnToPeerAPs(pAd,
+                                                              pFr->Hdr.Addr1,
+                                                              pFr->Hdr.Addr2,
+                                                              1,
+                                                              pBasicReport->
+                                                              ChNum);
+                                       StartDFSProcedure(pAd,
+                                                         pBasicReport->ChNum,
+                                                         1);
                                }
                        }
                } while (FALSE);
-       }
-       else
-               DBGPRINT(RT_DEBUG_TRACE, ("Invalid Measurement Report Frame.\n"));
+       } else
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("Invalid Measurement Report Frame.\n"));
 
        kfree(pMeasureReportInfo);
 
@@ -1621,34 +1965,33 @@ static VOID PeerMeasureReportAction(
        Return  : None.
        ==========================================================================
  */
-static VOID PeerTpcReqAction(
-       IN PRTMP_ADAPTER pAd,
-       IN MLME_QUEUE_ELEM *Elem)
+static void PeerTpcReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
 {
-       PFRAME_802_11 pFr = (PFRAME_802_11)Elem->Msg;
-       PUCHAR pFramePtr = pFr->Octet;
-       UINT8 DialogToken;
-       UINT8 TxPwr = GetCurTxPwr(pAd, Elem->Wcid);
-       UINT8 LinkMargin = 0;
-       CHAR RealRssi;
+       struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
+       u8 *pFramePtr = pFr->Octet;
+       u8 DialogToken;
+       u8 TxPwr = GetCurTxPwr(pAd, Elem->Wcid);
+       u8 LinkMargin = 0;
+       char RealRssi;
 
-       // link margin: Ratio of the received signal power to the minimum desired by the station (STA). The
-       //                              STA may incorporate rate information and channel conditions, including interference, into its computation
-       //                              of link margin.
+       /* link margin: Ratio of the received signal power to the minimum desired by the station (STA). The */
+       /*                              STA may incorporate rate information and channel conditions, including interference, into its computation */
+       /*                              of link margin. */
 
        RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0),
-                                                               ConvertToRssi(pAd, Elem->Rssi1, RSSI_1),
-                                                               ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
+                              ConvertToRssi(pAd, Elem->Rssi1, RSSI_1),
+                              ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
 
-       // skip Category and action code.
+       /* skip Category and action code. */
        pFramePtr += 2;
 
-       // Dialog token.
+       /* Dialog token. */
        NdisMoveMemory(&DialogToken, pFramePtr, 1);
 
        LinkMargin = (RealRssi / MIN_RCV_PWR);
        if (PeerTpcReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken))
-               EnqueueTPCRep(pAd, pFr->Hdr.Addr2, DialogToken, TxPwr, LinkMargin);
+               EnqueueTPCRep(pAd, pFr->Hdr.Addr2, DialogToken, TxPwr,
+                             LinkMargin);
 
        return;
 }
@@ -1664,22 +2007,22 @@ static VOID PeerTpcReqAction(
        Return  : None.
        ==========================================================================
  */
-static VOID PeerTpcRepAction(
-       IN PRTMP_ADAPTER pAd,
-       IN MLME_QUEUE_ELEM *Elem)
+static void PeerTpcRepAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
 {
-       UINT8 DialogToken;
-       TPC_REPORT_INFO TpcRepInfo;
-       PTPC_REQ_ENTRY pEntry = NULL;
-
-       NdisZeroMemory(&TpcRepInfo, sizeof(TPC_REPORT_INFO));
-       if (PeerTpcRepSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &TpcRepInfo))
-       {
-               if ((pEntry = TpcReqLookUp(pAd, DialogToken)) != NULL)
-               {
+       u8 DialogToken;
+       struct rt_tpc_report_info TpcRepInfo;
+       struct rt_tpc_req_entry *pEntry = NULL;
+
+       NdisZeroMemory(&TpcRepInfo, sizeof(struct rt_tpc_report_info));
+       if (PeerTpcRepSanity
+           (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &TpcRepInfo)) {
+               pEntry = TpcReqLookUp(pAd, DialogToken);
+               if (pEntry != NULL) {
                        TpcReqDelete(pAd, pEntry->DialogToken);
-                       DBGPRINT(RT_DEBUG_TRACE, ("%s: DialogToken=%x, TxPwr=%d, LinkMargin=%d\n",
-                               __func__, DialogToken, TpcRepInfo.TxPwr, TpcRepInfo.LinkMargin));
+                       DBGPRINT(RT_DEBUG_TRACE,
+                                ("%s: DialogToken=%x, TxPwr=%d, LinkMargin=%d\n",
+                                 __func__, DialogToken, TpcRepInfo.TxPwr,
+                                 TpcRepInfo.LinkMargin));
                }
        }
 
@@ -1698,41 +2041,37 @@ static VOID PeerTpcRepAction(
        Return  : None.
        ==========================================================================
  */
-VOID PeerSpectrumAction(
-       IN PRTMP_ADAPTER pAd,
-       IN MLME_QUEUE_ELEM *Elem)
+void PeerSpectrumAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
 {
 
-       UCHAR   Action = Elem->Msg[LENGTH_802_11+1];
+       u8 Action = Elem->Msg[LENGTH_802_11 + 1];
 
        if (pAd->CommonCfg.bIEEE80211H != TRUE)
                return;
 
-       switch(Action)
-       {
-               case SPEC_MRQ:
-                       // current rt2860 unable do such measure specified in Measurement Request.
-                       // reject all measurement request.
-                       PeerMeasureReqAction(pAd, Elem);
-                       break;
+       switch (Action) {
+       case SPEC_MRQ:
+               /* current rt2860 unable do such measure specified in Measurement Request. */
+               /* reject all measurement request. */
+               PeerMeasureReqAction(pAd, Elem);
+               break;
 
-               case SPEC_MRP:
-                       PeerMeasureReportAction(pAd, Elem);
-                       break;
+       case SPEC_MRP:
+               PeerMeasureReportAction(pAd, Elem);
+               break;
 
-               case SPEC_TPCRQ:
-                       PeerTpcReqAction(pAd, Elem);
-                       break;
+       case SPEC_TPCRQ:
+               PeerTpcReqAction(pAd, Elem);
+               break;
 
-               case SPEC_TPCRP:
-                       PeerTpcRepAction(pAd, Elem);
-                       break;
+       case SPEC_TPCRP:
+               PeerTpcRepAction(pAd, Elem);
+               break;
 
-               case SPEC_CHANNEL_SWITCH:
-{
-}
-                       PeerChSwAnnAction(pAd, Elem);
-                       break;
+       case SPEC_CHANNEL_SWITCH:
+
+               PeerChSwAnnAction(pAd, Elem);
+               break;
        }
 
        return;
@@ -1747,49 +2086,63 @@ VOID PeerSpectrumAction(
        Return  : None.
        ==========================================================================
  */
-INT Set_MeasureReq_Proc(
-       IN      PRTMP_ADAPTER   pAd,
-       IN      PUCHAR                  arg)
+int Set_MeasureReq_Proc(struct rt_rtmp_adapter *pAd, char *arg)
 {
-       UINT Aid = 1;
-       UINT ArgIdx;
-       PUCHAR thisChar;
+       u32 Aid = 1;
+       u32 ArgIdx;
+       char *thisChar;
 
        MEASURE_REQ_MODE MeasureReqMode;
-       UINT8 MeasureReqToken = RandomByte(pAd);
-       UINT8 MeasureReqType = RM_BASIC;
-       UINT8 MeasureCh = 1;
+       u8 MeasureReqToken = RandomByte(pAd);
+       u8 MeasureReqType = RM_BASIC;
+       u8 MeasureCh = 1;
+       u64 MeasureStartTime = GetCurrentTimeStamp(pAd);
+       struct rt_measure_req MeasureReq;
+       u8 TotalLen;
+
+       struct rt_header_802_11 ActHdr;
+       u8 *pOutBuffer = NULL;
+       int NStatus;
+       unsigned long FrameLen;
+
+       NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer);        /*Get an unused nonpaged memory */
+       if (NStatus != NDIS_STATUS_SUCCESS) {
+               DBGPRINT(RT_DEBUG_TRACE,
+                        ("%s() allocate memory failed \n", __func__));
+               goto END_OF_MEASURE_REQ;
+       }
 
        ArgIdx = 1;
-       while ((thisChar = strsep((char **)&arg, "-")) != NULL)
-       {
-               switch(ArgIdx)
-               {
-                       case 1: // Aid.
-                               Aid = simple_strtol(thisChar, 0, 16);
-                               break;
+       while ((thisChar = strsep((char **)&arg, "-")) != NULL) {
+               switch (ArgIdx) {
+               case 1: /* Aid. */
+                       Aid = (u8)simple_strtol(thisChar, 0, 16);
+                       break;
 
-                       case 2: // Measurement Request Type.
-                               MeasureReqType = simple_strtol(thisChar, 0, 16);
-                               if (MeasureReqType > 3)
-                               {
-                                       DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow MeasureReqType(%d)\n", __func__, MeasureReqType));
-                                       return TRUE;
-                               }
-                               break;
+               case 2: /* Measurement Request Type. */
+                       MeasureReqType = simple_strtol(thisChar, 0, 16);
+                       if (MeasureReqType > 3) {
+                               DBGPRINT(RT_DEBUG_ERROR,
+                                        ("%s: unknow MeasureReqType(%d)\n",
+                                         __func__, MeasureReqType));
+                               goto END_OF_MEASURE_REQ;
+                       }
+                       break;
 
-                       case 3: // Measurement channel.
-                               MeasureCh = simple_strtol(thisChar, 0, 16);
-                               break;
+               case 3: /* Measurement channel. */
+                       MeasureCh = (u8)simple_strtol(thisChar, 0, 16);
+                       break;
                }
                ArgIdx++;
        }
 
-       DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d, MeasureReqType=%d MeasureCh=%d\n", __func__, Aid, MeasureReqType, MeasureCh));
-       if (!VALID_WCID(Aid))
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __func__, Aid));
-               return TRUE;
+       DBGPRINT(RT_DEBUG_TRACE,
+                ("%s::Aid = %d, MeasureReqType=%d MeasureCh=%d\n", __func__,
+                 Aid, MeasureReqType, MeasureCh));
+       if (!VALID_WCID(Aid)) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: unknow sta of Aid(%d)\n", __func__, Aid));
+               goto END_OF_MEASURE_REQ;
        }
 
        MeasureReqMode.word = 0;
@@ -1797,26 +2150,52 @@ INT Set_MeasureReq_Proc(
 
        MeasureReqInsert(pAd, MeasureReqToken);
 
-       EnqueueMeasurementReq(pAd, pAd->MacTab.Content[Aid].Addr,
-               MeasureReqToken, MeasureReqMode.word, MeasureReqType, MeasureCh, 2000);
+       /* build action frame header. */
+       MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0,
+                        pAd->MacTab.Content[Aid].Addr, pAd->CurrentAddress);
+
+       NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
+       FrameLen = sizeof(struct rt_header_802_11);
+
+       TotalLen = sizeof(struct rt_measure_req_info) + sizeof(struct rt_measure_req);
+
+       MakeMeasurementReqFrame(pAd, pOutBuffer, &FrameLen,
+                               sizeof(struct rt_measure_req_info), CATEGORY_RM, RM_BASIC,
+                               MeasureReqToken, MeasureReqMode.word,
+                               MeasureReqType, 0);
+
+       MeasureReq.ChNum = MeasureCh;
+       MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime);
+       MeasureReq.MeasureDuration = cpu2le16(2000);
+
+       {
+               unsigned long TempLen;
+               MakeOutgoingFrame(pOutBuffer + FrameLen, &TempLen,
+                                 sizeof(struct rt_measure_req), &MeasureReq,
+                                 END_OF_ARGS);
+               FrameLen += TempLen;
+       }
+
+       MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, (u32)FrameLen);
+
+END_OF_MEASURE_REQ:
+       MlmeFreeMemory(pAd, pOutBuffer);
 
        return TRUE;
 }
 
-INT Set_TpcReq_Proc(
-       IN      PRTMP_ADAPTER   pAd,
-       IN      PUCHAR                  arg)
+int Set_TpcReq_Proc(struct rt_rtmp_adapter *pAd, char *arg)
 {
-       UINT Aid;
+       u32 Aid;
 
-       UINT8 TpcReqToken = RandomByte(pAd);
+       u8 TpcReqToken = RandomByte(pAd);
 
-       Aid = simple_strtol(arg, 0, 16);
+       Aid = (u32)simple_strtol(arg, 0, 16);
 
        DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d\n", __func__, Aid));
-       if (!VALID_WCID(Aid))
-       {
-               DBGPRINT(RT_DEBUG_ERROR, ("%s: unknow sta of Aid(%d)\n", __func__, Aid));
+       if (!VALID_WCID(Aid)) {
+               DBGPRINT(RT_DEBUG_ERROR,
+                        ("%s: unknow sta of Aid(%d)\n", __func__, Aid));
                return TRUE;
        }
 
@@ -1826,4 +2205,3 @@ INT Set_TpcReq_Proc(
 
        return TRUE;
 }
-