wifi_mac.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:27k
源码类别:

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2001
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *   wifi_mac.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *   WiFi MAC source
  23.  *
  24.  * Author:
  25.  * -------
  26.  *  Andy Ueng (mtk00490)
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * $Revision$
  33.  * $Modtime$
  34.  * $Log$
  35.  *
  36.  *------------------------------------------------------------------------------
  37.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  38.  *============================================================================
  39.  ****************************************************************************/
  40. //===========================================================================
  41. #include <IniFiles.hpp>
  42. #pragma hdrstop
  43. #ifndef  _WIFI_MAC_H_
  44. #include "wifi_mac.h"
  45. #endif
  46. // man
  47. #ifndef  _MAN_ACTIVE_H_
  48. #include "man_active.h"
  49. #endif
  50. #ifndef  _MAN_FDM_H_
  51. #include "man_fdm.h"
  52. #endif
  53. // misc
  54. #ifndef  _FT_UTILS_H_
  55. #include "ft_utils.h"
  56. #endif
  57. static CWIFIMAC*  gs_wifi_mac_ptr;
  58. //===========================================================================
  59. //static  void  Read_From_Reg( void )
  60. //{   gs_wifi_mac_ptr->Read_From_Reg();
  61. //}
  62. //---------------------------------------------------------------------------
  63. //static  void  REQ_Read_From_AllReg( void )
  64. //{   gs_wifi_mac_ptr->REQ_Read_From_AllReg();
  65. //}
  66. //---------------------------------------------------------------------------
  67. //static  void  Write_To_Reg( void )
  68. //{   gs_wifi_mac_ptr->Write_To_Reg();
  69. //}
  70. //---------------------------------------------------------------------------
  71. static  void  REQ_Read_MCR_Setting_From_Reg( void )
  72. {   gs_wifi_mac_ptr->REQ_Read_MCR_Setting_From_Reg();
  73. }
  74. //---------------------------------------------------------------------------
  75. static  void  REQ_Write_MCR_Setting_To_Reg( void )
  76. {    gs_wifi_mac_ptr->REQ_Write_MCR_Setting_To_Reg();
  77. }
  78. //---------------------------------------------------------------------------
  79. static  void  REQ_Read_MCR16_Setting_From_Reg( void )
  80. {   gs_wifi_mac_ptr->REQ_Read_MCR16_Setting_From_Reg();
  81. }
  82. //---------------------------------------------------------------------------
  83. static  void  REQ_Write_MCR16_Setting_To_Reg( void )
  84. {   gs_wifi_mac_ptr->REQ_Write_MCR16_Setting_To_Reg();
  85. }
  86. //---------------------------------------------------------------------------
  87. static  void  CNF_ReadFromNVRAM( void )
  88. {
  89.     gs_wifi_mac_ptr->CNF_ReadFromNVRAM();
  90. }
  91. //---------------------------------------------------------------------------
  92. static  void  CNF_WriteToNVRAM(void)
  93. {
  94.     gs_wifi_mac_ptr->CNF_WriteToNVRAM();
  95. }
  96. //------------------------------------------------------------------------------
  97. static void  REQ_TimeOut( void )
  98. {   gs_wifi_mac_ptr->REQ_TimeOut();
  99. }
  100. //------------------------------------------------------------------------------
  101. static void  REQ_Finish( void )
  102. {   gs_wifi_mac_ptr->REQ_Finish();
  103. }
  104. //===========================================================================
  105. CWIFIMAC::CWIFIMAC(void)
  106. {
  107.    m_bIsRunning = false;
  108.    ConfirmCallback = NULL;
  109.    m_pcMacAddrBuf = NULL;
  110.    m_iMacAddrBufSize = 0;
  111. }
  112. //---------------------------------------------------------------------------
  113. CWIFIMAC::~CWIFIMAC( )
  114. {
  115.    m_bIsRunning = false;
  116.    ConfirmCallback = 0;
  117.    if( m_pcMacAddrBuf )
  118.    {
  119.        delete [] m_pcMacAddrBuf;
  120.        m_pcMacAddrBuf = NULL;
  121.    }
  122. }
  123. //---------------------------------------------------------------------------
  124. void  CWIFIMAC::REQ_Finish( void )
  125. {
  126.    if( ! m_bIsRunning )  return;
  127.    Confirm( STATE_MAC_OK );
  128.    m_bIsRunning = false;
  129. }
  130. //---------------------------------------------------------------------------
  131. void  CWIFIMAC::REQ_Stop( void )
  132. {
  133.     if( ! m_bIsRunning )  return;
  134.     Confirm( STATE_MAC_STOP );
  135.     m_bIsRunning = false;
  136. }
  137. //---------------------------------------------------------------------------
  138. void  CWIFIMAC::REQ_TimeOut( void )
  139. {
  140.     if( ! m_bIsRunning )  return;
  141.     Confirm( STATE_MAC_TIMEOUT );
  142.     m_bIsRunning = false;
  143. }
  144. //---------------------------------------------------------------------------
  145. void  CWIFIMAC::Confirm( int confirm_state )
  146. {
  147.    if( ! m_bIsRunning )  return;
  148.    if(ConfirmCallback==0)  return;
  149.    m_iConfirmState = confirm_state;
  150.    ActiveMan->SetActiveFunction( ConfirmCallback );
  151. }
  152. //===========================================================================
  153. ///////////////////////////   MCR register setting   ////////////////////////
  154. //===========================================================================
  155. void  CWIFIMAC::REQ_Read_MCR_Setting_From_Reg_Start( S_WiFi_MCR &mcr )
  156. {
  157.     gs_wifi_mac_ptr = this;
  158.     m_bIsRunning    = true;
  159.     m_sMCR          = mcr;
  160.     ActiveMan->SetActiveFunction( ::REQ_Read_MCR_Setting_From_Reg );
  161. }
  162. //------------------------------------------------------------
  163. void  CWIFIMAC::REQ_Read_MCR_Setting_From_Reg( void )
  164. {
  165.     if( ! m_bIsRunning )
  166.     {   Confirm( STATE_MAC_FAIL );  return;  }
  167.     META_RESULT  MetaResult;
  168.    // for( int i=0; i<WIFI_MCR_TYPE_NUM; i++ )
  169.     {
  170.        // for(int j=0; j<WIFI_MCR_MAX_NUM; j++ )
  171.         {
  172.            // if( m_sMCR_Setting[i][j].checked )
  173.             {
  174.                // MetaResult = META_WiFi_MACRegRead( 500, m_sMCR_Setting[i][j].addr, &m_sMCR_Setting[i][j].value );
  175.                 MetaResult = META_WiFi_MACReg32Read_r( m_META_HANDLE_Obj.Get_MainHandle(), 100*m_sMCR.count, m_sMCR.mac_reg32, m_sMCR.count );
  176.             }
  177.         }
  178.     }        
  179.     if(MetaResult!=META_SUCCESS)
  180.     {
  181.         if( MetaResult!=META_TIMEOUT )
  182.         {   Confirm( STATE_MAC_FAIL );  return;  }
  183.         else
  184.         {   Confirm( STATE_MAC_TIMEOUT );  return;   }
  185.     }
  186.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  187. }
  188. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  189. void  CWIFIMAC::REQ_Write_MCR_Setting_To_Reg_Start( S_WiFi_MCR &mcr )
  190. {
  191.     gs_wifi_mac_ptr = this;
  192.     m_bIsRunning    = true;
  193.     m_sMCR          = mcr;
  194.     ActiveMan->SetActiveFunction( ::REQ_Write_MCR_Setting_To_Reg );
  195. }
  196. //------------------------------------------------------------
  197. void  CWIFIMAC::REQ_Write_MCR_Setting_To_Reg( void )
  198. {
  199.     if( ! m_bIsRunning )
  200.     {   Confirm( STATE_MAC_FAIL );  return;  }
  201.     META_RESULT  MetaResult;
  202.   //  for( int i=0; i<WIFI_MCR_TYPE_NUM; i++ )
  203.     {
  204.       //  for(int j=0; j<WIFI_MCR_MAX_NUM; j++ )
  205.         {
  206.            // if( m_sMCR_Setting[i][j].checked && (false == m_sMCR_Setting[i][j].RO) )
  207.             {
  208.                // MetaResult = META_WiFi_MACRegWrite_r(500, m_sMCR_Setting[i][j].addr, m_sMCR_Setting[i][j].value);
  209.                 MetaResult = META_WiFi_MACReg32Write_r( m_META_HANDLE_Obj.Get_MainHandle(), 100*m_sMCR.count, m_sMCR.mac_reg32, m_sMCR.count );
  210.             }
  211.             if(MetaResult!=META_SUCCESS)
  212.             {
  213.                 if( MetaResult!=META_TIMEOUT )
  214.                 {   Confirm( STATE_MAC_FAIL );  return;  }
  215.                 else
  216.                 {   Confirm( STATE_MAC_TIMEOUT );  return;   }
  217.             }
  218.         }
  219.     }
  220.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  221. }
  222. //==========================================================================
  223. void  CWIFIMAC::REQ_Read_MCR16_Setting_From_Reg_Start( S_WiFi_MCR16 &mcr16 )
  224. {
  225.     gs_wifi_mac_ptr = this;
  226.     m_bIsRunning    = true;
  227.     m_sMCR16        = mcr16;
  228.     ActiveMan->SetActiveFunction( ::REQ_Read_MCR16_Setting_From_Reg );
  229. }
  230. //------------------------------------------------------------
  231. void  CWIFIMAC::REQ_Read_MCR16_Setting_From_Reg( void )
  232. {
  233.     if( ! m_bIsRunning )
  234.     {   Confirm( STATE_MAC_FAIL );  return;  }
  235.     META_RESULT  MetaResult;
  236.     MetaResult = META_WiFi_MACReg16Read_r( m_META_HANDLE_Obj.Get_MainHandle(), 50*m_sMCR16.count, m_sMCR16.mac_reg16, m_sMCR16.count );
  237.     if(MetaResult!=META_SUCCESS)
  238.     {
  239.         if( MetaResult!=META_TIMEOUT )
  240.         {   Confirm( STATE_MAC_FAIL );  return;  }
  241.         else
  242.         {   Confirm( STATE_MAC_TIMEOUT );  return;   }
  243.     }
  244.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  245. }
  246. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  247. void  CWIFIMAC::REQ_Write_MCR16_Setting_To_Reg_Start( S_WiFi_MCR16 &mcr16 )
  248. {
  249.     gs_wifi_mac_ptr = this;
  250.     m_bIsRunning    = true;
  251.     m_sMCR16        = mcr16;
  252.     ActiveMan->SetActiveFunction( ::REQ_Write_MCR16_Setting_To_Reg );
  253. }
  254. //------------------------------------------------------------
  255. void  CWIFIMAC::REQ_Write_MCR16_Setting_To_Reg( void )
  256. {
  257.     if( ! m_bIsRunning )
  258.     {   Confirm( STATE_MAC_FAIL );  return;  }
  259.     META_RESULT  MetaResult;
  260.     MetaResult = META_WiFi_MACReg16Write_r( m_META_HANDLE_Obj.Get_MainHandle(), 100*m_sMCR16.count, m_sMCR16.mac_reg16, m_sMCR16.count );
  261.     if(MetaResult!=META_SUCCESS)
  262.     {
  263.         if( MetaResult!=META_TIMEOUT )
  264.         {   Confirm( STATE_MAC_FAIL );  return;  }
  265.         else
  266.         {   Confirm( STATE_MAC_TIMEOUT );  return;   }
  267.     }
  268.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  269. }
  270. //===========================================================================
  271. void  CWIFIMAC::REQ_Read_From_NVRAM( void )
  272. {
  273.     gs_wifi_mac_ptr = this;
  274.     m_bIsRunning = true;
  275.     META_RESULT  MetaResult;
  276.     if( 0 == m_pcMacAddrBuf )
  277.     {
  278.         MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_WIFI_MAC_ADDRESS_LID",
  279.                                           &m_iMacAddrBufSize );
  280.         if(MetaResult!=META_SUCCESS)
  281.         {  Confirm( STATE_MAC_FAIL );  return;  }
  282.         m_pcMacAddrBuf = new  char[m_iMacAddrBufSize];
  283.     }
  284.     NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
  285.     NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_WIFI_MAC_ADDRESS_LID",
  286.                                    1, // only one record
  287.                                    m_iMacAddrBufSize,
  288.                                    m_pcMacAddrBuf );
  289. }
  290. //-------------------------------------
  291. void  CWIFIMAC::CNF_ReadFromNVRAM( void )
  292. {
  293.     if( ! m_bIsRunning )  return;
  294.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  295.     if(state==METAAPP_SUCCESS)
  296.     {
  297.         if( !Decompose_MacAddress() )
  298.         {   Confirm( STATE_MAC_FAIL );  return;  }
  299.         ActiveMan->SetActiveFunction( ::REQ_Finish );
  300.     }
  301.     else if(state==METAAPP_TIMEOUT)
  302.     {   Confirm( STATE_MAC_TIMEOUT );
  303.     }
  304.     else if(state==METAAPP_STOP)
  305.     {   Confirm( STATE_MAC_STOP );
  306.     }
  307.     else
  308.     {   Confirm( STATE_MAC_FAIL );
  309.     }
  310. }
  311. //--------------------------------------------------------------------------
  312. bool  CWIFIMAC::Decompose_MacAddress( void )
  313. {
  314.     if( META_NVRAM_WiFi_Decompose_MacAddress (&m_mac_addr, m_pcMacAddrBuf, m_iMacAddrBufSize)!= META_SUCCESS )
  315.     {
  316.         return false;
  317.     }
  318.     return true;
  319. }
  320. //--------------------------------------------------------------------------
  321. bool  CWIFIMAC::Compose_MacAddress( void )
  322. {
  323.     if( META_NVRAM_WiFi_Compose_MacAddress (&m_mac_addr, m_pcMacAddrBuf, m_iMacAddrBufSize)!= META_SUCCESS )
  324.     {
  325.         return false;
  326.     }
  327.     return true;
  328. }
  329. //===========================================================================
  330. void  CWIFIMAC::REQ_Write_To_NVRAM( void )
  331. {
  332.     gs_wifi_mac_ptr = this;
  333.     m_bIsRunning = true;
  334.     if( 0 == m_pcMacAddrBuf )
  335.     {
  336.         META_RESULT MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_WIFI_MAC_ADDRESS_LID",
  337.                                           &m_iMacAddrBufSize );
  338.         if(MetaResult!=META_SUCCESS)
  339.         {  Confirm( STATE_MAC_FAIL );  return;  }
  340.         m_pcMacAddrBuf = new  char[m_iMacAddrBufSize];
  341.     }
  342.     if( !Compose_MacAddress() )
  343.     {  Confirm( STATE_MAC_FAIL );  return;  }
  344.     NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
  345.     NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_WIFI_MAC_ADDRESS_LID",
  346.                                     1,
  347.                                     m_iMacAddrBufSize,
  348.                                     m_pcMacAddrBuf );
  349. }
  350. //-------------------------------------
  351. void  CWIFIMAC::CNF_WriteToNVRAM( void )
  352. {
  353.     if( ! m_bIsRunning )  return;
  354.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  355.     if(state==METAAPP_SUCCESS)
  356.     {
  357.         ActiveMan->SetActiveFunction( ::REQ_Finish );
  358.     }
  359.     else if(state==METAAPP_TIMEOUT)
  360.     {  Confirm( STATE_MAC_TIMEOUT );
  361.     }
  362.     else if(state==METAAPP_STOP)
  363.     {  Confirm( STATE_MAC_STOP );
  364.     }
  365.     else
  366.     {  Confirm( STATE_MAC_FAIL );
  367.     }
  368. }
  369. //============================================================================
  370. /////////////////////////////  File read/write   /////////////////////////////
  371. //============================================================================
  372. static const AnsiString SECTION_NAME = "WiFi MT5911 MAC register";
  373. static const AnsiString KEY_NAME_MT5911_MCR[] =
  374. {
  375.     "system control register",
  376.     "miscellaneous and debug port register",
  377.     "phyical layer control interface register",
  378.     "MAC protocol timing control register",
  379.     "NVA control register",
  380.     "beacon generation register",
  381.     "security engine register",
  382.     "transmitter control register",
  383.     "receiver control register",
  384.     "HIF_SDIO register",
  385.     "HIF_SPI register"
  386. };
  387. static const AnsiString KEY_NAME_MT5911_MCR16[] =
  388. {
  389.     "HIF_HPI register"
  390. };
  391. //----------------------------------------------------------------------------
  392. bool  CWIFIMAC::REQ_Read_From_File( char *filename, WiFi_HostInterface_E host_inf )
  393. {
  394.     TIniFile   *ini_file;
  395.     AnsiString  as_data;
  396.     char        str[2048];
  397.     unsigned int      uidata[WIFI_MCR_MAX_NUM];
  398.     unsigned short    usdata[WIFI_MCR16_MAX_NUM];
  399.     int         i;
  400.     ini_file = new TIniFile( filename );
  401.     if( ini_file == NULL )  return false;
  402.     // System Control
  403.     as_data = ini_file->ReadString( SECTION_NAME,
  404.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_SC],
  405.                                      "0,0,0,0,");
  406.     strcpy( str, as_data.c_str() );
  407.     String_To_Array_UnsignedInteger( str, uidata, WIFI_SC_NUM );
  408.     for( i=0; i<WIFI_SC_NUM; i++ )
  409.     {  m_sMCR_Setting[WIFI_MCR_SC][i].value = uidata[i];  }
  410.     // Miscellaneous and Debug Port
  411.     as_data = ini_file->ReadString( SECTION_NAME,
  412.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_MDP],
  413.                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,");
  414.     strcpy( str, as_data.c_str() );
  415.     String_To_Array_UnsignedInteger( str, uidata, WIFI_MDP_NUM );
  416.     for( i=0; i<WIFI_MDP_NUM; i++ )
  417.     {  m_sMCR_Setting[WIFI_MCR_MDP][i].value = uidata[i];  }
  418.     // Phyical Layer Control Interface
  419.     as_data = ini_file->ReadString( SECTION_NAME,
  420.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_PLCI],
  421.                                      "0,0,0,0,0,0,0,0,0,0,0,0,");
  422.     strcpy( str, as_data.c_str() );
  423.     String_To_Array_UnsignedInteger( str, uidata, WIFI_PLCI_NUM );
  424.     for( i=0; i<WIFI_PLCI_NUM; i++ )
  425.     {  m_sMCR_Setting[WIFI_MCR_PLCI][i].value = uidata[i];  }
  426.     // MAC Protocol Timing Control
  427.     as_data = ini_file->ReadString( SECTION_NAME,
  428.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_MPTC],
  429.                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,");
  430.     strcpy( str, as_data.c_str() );
  431.     String_To_Array_UnsignedInteger( str, uidata, WIFI_MPTC_NUM );
  432.     for( i=0; i<WIFI_MPTC_NUM; i++ )
  433.     {  m_sMCR_Setting[WIFI_MCR_MPTC][i].value = uidata[i];  }
  434.     // NVA Control
  435.     as_data = ini_file->ReadString( SECTION_NAME,
  436.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_NC],
  437.                                      "0,0,0,0,");
  438.     strcpy( str, as_data.c_str() );
  439.     String_To_Array_UnsignedInteger( str, uidata, WIFI_NC_NUM );
  440.     for( i=0; i<WIFI_NC_NUM; i++ )
  441.     {  m_sMCR_Setting[WIFI_MCR_NC][i].value = uidata[i];  }
  442.     // Beacon Generation
  443.     as_data = ini_file->ReadString( SECTION_NAME,
  444.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_BG],
  445.                                      "0,0,0,0,0,0,0,0,");
  446.     strcpy( str, as_data.c_str() );
  447.     String_To_Array_UnsignedInteger( str, uidata, WIFI_BG_NUM );
  448.     for( i=0; i<WIFI_BG_NUM; i++ )
  449.     {  m_sMCR_Setting[WIFI_MCR_BG][i].value = uidata[i];  }
  450.     // Security Engine
  451.     as_data = ini_file->ReadString( SECTION_NAME,
  452.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_SE],
  453.                                      "0,0,0,0,0,0,0,0,0,0,0,");
  454.     strcpy( str, as_data.c_str() );
  455.     String_To_Array_UnsignedInteger( str, uidata, WIFI_SE_NUM );
  456.     for( i=0; i<WIFI_SE_NUM; i++ )
  457.     {  m_sMCR_Setting[WIFI_MCR_SE][i].value = uidata[i];  }
  458.     // Transmitter Control
  459.     as_data = ini_file->ReadString( SECTION_NAME,
  460.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_TC],
  461.                                      "0,0,0,0,0,0,0,0,0,0,0,0,");
  462.     strcpy( str, as_data.c_str() );
  463.     String_To_Array_UnsignedInteger( str, uidata, WIFI_TC_NUM );
  464.     for( i=0; i<WIFI_TC_NUM; i++ )
  465.     {  m_sMCR_Setting[WIFI_MCR_TC][i].value = uidata[i];  }
  466.     // Receiver Control
  467.     as_data = ini_file->ReadString( SECTION_NAME,
  468.                                      KEY_NAME_MT5911_MCR[WIFI_MCR_RC],
  469.                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,");
  470.     strcpy( str, as_data.c_str() );
  471.     String_To_Array_UnsignedInteger( str, uidata, WIFI_RC_NUM );
  472.     for( i=0; i<WIFI_RC_NUM; i++ )
  473.     {  m_sMCR_Setting[WIFI_MCR_RC][i].value = uidata[i];  }
  474.     switch( host_inf )
  475.     {
  476.         // HIF_HPI
  477.         case WNDRV_HOST_INTERFACE_SDIO:
  478.         {
  479.             as_data = ini_file->ReadString( SECTION_NAME,
  480.                                             KEY_NAME_MT5911_MCR[WIFI_MCR_HIF_SDIO],
  481.                                             "0,0,0,0,0,0,0,");
  482.             strcpy( str, as_data.c_str() );
  483.             String_To_Array_UnsignedInteger( str, uidata, WIFI_HIF_SDIO_NUM );
  484.             for( i=0; i<WIFI_HIF_SDIO_NUM; i++ )
  485.             {  m_sMCR_Setting[WIFI_MCR_HIF_SDIO][i].value = uidata[i];  }
  486.         }
  487.         break;
  488. case WNDRV_HOST_INTERFACE_HPI:
  489.         {
  490.             as_data = ini_file->ReadString( SECTION_NAME,
  491.                                      KEY_NAME_MT5911_MCR16[WIFI_MCR16_HIF_HPI],
  492.                                      "0,0,0,0,0,0,0,0,");
  493.             strcpy( str, as_data.c_str() );
  494.             String_To_Array_UnsignedShort( str, usdata, WIFI_HIF_HPI_NUM );
  495.             for( i=0; i<WIFI_HIF_HPI_NUM; i++ )
  496.             {  m_sMCR16_Setting[WIFI_MCR16_HIF_HPI][i].value = usdata[i];  }
  497.         }
  498.         break;
  499.         case WNDRV_HOST_INTERFACE_SPI:
  500.         {
  501.             as_data = ini_file->ReadString( SECTION_NAME,
  502.                                             KEY_NAME_MT5911_MCR[WIFI_MCR_HIF_SPI],
  503.                                             "0,0,0,0,0,0,");
  504.             strcpy( str, as_data.c_str() );
  505.             String_To_Array_UnsignedInteger( str, uidata, WIFI_HIF_SPI_NUM );
  506.             for( i=0; i<WIFI_HIF_SPI_NUM; i++ )
  507.             {  m_sMCR_Setting[WIFI_MCR_HIF_SPI][i].value = uidata[i];  }
  508.         }
  509.         break;
  510.     }
  511.     delete  ini_file;
  512.     return true;
  513. }
  514. //-----------------------------------------------------------------------------
  515. bool  CWIFIMAC::REQ_Write_To_File( char *filename, WiFi_HostInterface_E host_inf )
  516. {
  517.     TIniFile   *ini_file;
  518.     char        str[2048];
  519.     unsigned int         uidata[WIFI_MCR_MAX_NUM];
  520.     unsigned short       usdata[WIFI_MCR16_MAX_NUM];
  521.     int         i;
  522.     ini_file = new TIniFile( filename );
  523.     if( ini_file == NULL )  return  false;
  524.     // System Control
  525.     for( i=0; i<WIFI_SC_NUM; i++ )
  526.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_SC][i].value;  }
  527.     Array_To_String_UnsignedInteger( str, uidata, WIFI_SC_NUM, ',' );
  528.     ini_file->WriteString( SECTION_NAME,
  529.                            KEY_NAME_MT5911_MCR[WIFI_MCR_SC],
  530.                            str );
  531.     // Miscellaneous and Debug Port
  532.     for( i=0; i<WIFI_MDP_NUM; i++ )
  533.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_MDP][i].value;  }
  534.     Array_To_String_UnsignedInteger( str, uidata, WIFI_MDP_NUM, ',' );
  535.     ini_file->WriteString( SECTION_NAME,
  536.                            KEY_NAME_MT5911_MCR[WIFI_MCR_MDP],
  537.                            str );
  538.     // Phyical Layer Control Interface
  539.     for( i=0; i<WIFI_PLCI_NUM; i++ )
  540.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_PLCI][i].value;  }
  541.     Array_To_String_UnsignedInteger( str, uidata, WIFI_PLCI_NUM, ',' );
  542.     ini_file->WriteString( SECTION_NAME,
  543.                            KEY_NAME_MT5911_MCR[WIFI_MCR_PLCI],
  544.                            str );
  545.     // MAC Protocol Timing Control
  546.     for( i=0; i<WIFI_MPTC_NUM; i++ )
  547.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_MPTC][i].value;  }
  548.     Array_To_String_UnsignedInteger( str, uidata, WIFI_MPTC_NUM, ',' );
  549.     ini_file->WriteString( SECTION_NAME,
  550.                            KEY_NAME_MT5911_MCR[WIFI_MCR_MPTC],
  551.                            str );
  552.     // NVA Control
  553.     for( i=0; i<WIFI_NC_NUM; i++ )
  554.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_NC][i].value;  }
  555.     Array_To_String_UnsignedInteger( str, uidata, WIFI_NC_NUM, ',' );
  556.     ini_file->WriteString( SECTION_NAME,
  557.                            KEY_NAME_MT5911_MCR[WIFI_MCR_NC],
  558.                            str );
  559.     // Beacon Generation
  560.     for( i=0; i<WIFI_BG_NUM; i++ )
  561.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_BG][i].value;  }
  562.     Array_To_String_UnsignedInteger( str, uidata, WIFI_BG_NUM, ',' );
  563.     ini_file->WriteString( SECTION_NAME,
  564.                            KEY_NAME_MT5911_MCR[WIFI_MCR_BG],
  565.                            str );
  566.     // Security Engine
  567.     for( i=0; i<WIFI_SE_NUM; i++ )
  568.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_SE][i].value;  }
  569.     Array_To_String_UnsignedInteger( str, uidata, WIFI_SE_NUM, ',' );
  570.     ini_file->WriteString( SECTION_NAME,
  571.                            KEY_NAME_MT5911_MCR[WIFI_MCR_SE],
  572.                            str );
  573.     // Transmitter Control
  574.     for( i=0; i<WIFI_TC_NUM; i++ )
  575.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_TC][i].value;  }
  576.     Array_To_String_UnsignedInteger( str, uidata, WIFI_TC_NUM, ',' );
  577.     ini_file->WriteString( SECTION_NAME,
  578.                            KEY_NAME_MT5911_MCR[WIFI_MCR_TC],
  579.                            str );
  580.     // Receiver Control
  581.     for( i=0; i<WIFI_RC_NUM; i++ )
  582.     {   uidata[i] = m_sMCR_Setting[WIFI_MCR_RC][i].value;  }
  583.     Array_To_String_UnsignedInteger( str, uidata, WIFI_RC_NUM, ',' );
  584.     ini_file->WriteString( SECTION_NAME,
  585.                            KEY_NAME_MT5911_MCR[WIFI_MCR_RC],
  586.                            str );
  587.     switch( host_inf )
  588.     {
  589.         // HIF_HPI
  590.         case WNDRV_HOST_INTERFACE_SDIO:
  591.         {
  592.             for( i=0; i<WIFI_HIF_SDIO_NUM; i++ )
  593.             {   uidata[i] = m_sMCR_Setting[WIFI_MCR_HIF_SDIO][i].value;  }
  594.             Array_To_String_UnsignedInteger( str, uidata, WIFI_HIF_SDIO_NUM, ',' );
  595.             ini_file->WriteString( SECTION_NAME,
  596.                                    KEY_NAME_MT5911_MCR[WIFI_MCR_HIF_SDIO],
  597.                                    str );
  598.         }
  599.         break;
  600. case WNDRV_HOST_INTERFACE_HPI:
  601.         {
  602.             for( i=0; i<WIFI_HIF_HPI_NUM; i++ )
  603.             {   usdata[i] = m_sMCR16_Setting[WIFI_MCR16_HIF_HPI][i].value;  }
  604.             Array_To_String_UnsignedShort( str, usdata, WIFI_HIF_HPI_NUM, ',' );
  605.             ini_file->WriteString( SECTION_NAME,
  606.                                    KEY_NAME_MT5911_MCR16[WIFI_MCR16_HIF_HPI],
  607.                                    str );
  608.         }
  609.         break;
  610.         case WNDRV_HOST_INTERFACE_SPI:
  611.         {
  612.             for( i=0; i<WIFI_HIF_SPI_NUM; i++ )
  613.             {   uidata[i] = m_sMCR_Setting[WIFI_MCR_HIF_SPI][i].value;  }
  614.             Array_To_String_UnsignedInteger( str, uidata, WIFI_HIF_SPI_NUM, ',' );
  615.             ini_file->WriteString( SECTION_NAME,
  616.                                    KEY_NAME_MT5911_MCR[WIFI_MCR_HIF_SPI],
  617.                                    str );
  618.         }
  619.         break;
  620.     }
  621.     delete  ini_file;
  622.     return  true;
  623. }
  624. //===========================================================================
  625. ////////////////////////////   Global  information   ////////////////////////
  626. //===========================================================================
  627. //---------------------------------------------------------------------------
  628. int   CWIFIMAC::Get_ConfirmState( void )
  629. {
  630.     return  m_iConfirmState;
  631. }
  632. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  633. unsigned int  CWIFIMAC::Get_MCR_Setting_Value( int type, int idx )
  634. {
  635.     return  m_sMCR_Setting[type][idx].value;
  636. }
  637. //----------------------------------------------------------------------------
  638. void CWIFIMAC::Set_MCR_Setting_Value( int type, int idx, unsigned int value )
  639. {   m_sMCR_Setting[type][idx].value = value;
  640. }
  641. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  642. unsigned short  CWIFIMAC::Get_MCR16_Setting_Value( int type, int idx )
  643. {
  644.     return  m_sMCR16_Setting[type][idx].value;
  645. }
  646. //----------------------------------------------------------------------------
  647. void CWIFIMAC::Set_MCR16_Setting_Value( int type, int idx, unsigned short value )
  648. {   m_sMCR16_Setting[type][idx].value = value;
  649. }
  650. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  651. void CWIFIMAC::Set_MCR_Setting( int type, int idx, S_WIFI_MCR_SETTING mcr )
  652. {   m_sMCR_Setting[type][idx] = mcr;
  653. }
  654. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  655. void CWIFIMAC::Set_MCR16_Setting( int type, int idx, S_WIFI_MCR16_SETTING mcr16 )
  656. {   m_sMCR16_Setting[type][idx] = mcr16;
  657. }
  658. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  659. S_WiFi_MCR CWIFIMAC::Get_MCR( void )
  660. {   return  m_sMCR;
  661. }
  662. //----------------------------------------------------------------------------
  663. void CWIFIMAC::Set_MCR( S_WiFi_MCR &mcr )
  664. {   m_sMCR = mcr;
  665. }
  666. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  667. S_WiFi_MCR16 CWIFIMAC::Get_MCR16( void )
  668. {   return  m_sMCR16;
  669. }
  670. //----------------------------------------------------------------------------
  671. void CWIFIMAC::Set_MCR16( S_WiFi_MCR16 &mcr16 )
  672. {   m_sMCR16 = mcr16;
  673. }