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

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_cptx.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *   WiFi continuous packet TX 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  _METAAPP_COMMON_H_
  44. #include "METAAPP_common.h"
  45. #endif
  46. #ifndef  _WIFI_CPTX_H_
  47. #include "wifi_cptx.h"
  48. #endif
  49. // man
  50. #ifndef  _MAN_ACTIVE_H_
  51. #include "man_active.h"
  52. #endif
  53. #ifndef  _MAN_FDM_H_
  54. #include "man_fdm.h"
  55. #endif
  56. // misc
  57. #ifndef  _FT_UTILS_H_
  58. #include "ft_utils.h"
  59. #endif
  60. //===========================================================================
  61. static bool  g_bIsRunning = false;
  62. static CWIFICPT*  gs_wifi_cptx_ptr;
  63. //===========================================================================
  64. //---------------------------------------------------------------------------
  65. static void REQ_SetRegDomain(void)
  66. {
  67.     gs_wifi_cptx_ptr->REQ_SetRegDomain();
  68. }
  69. //---------------------------------------------------------------------------
  70. static void REQ_ContinuousPktTx(void)
  71. {
  72.     gs_wifi_cptx_ptr->REQ_ContinuousPktTx();
  73. }
  74. //---------------------------------------------------------------------------
  75. static void REQ_Query_TxStatus(void)
  76. {
  77.     gs_wifi_cptx_ptr->REQ_Query_TxStatus();
  78. }
  79. //---------------------------------------------------------------------------
  80. static void REQ_SetDbmToDac(void)
  81. {
  82.     gs_wifi_cptx_ptr->REQ_SetDbmToDac();
  83. }
  84. //---------------------------------------------------------------------------
  85. static void REQ_Query_DbmToDac(void)
  86. {
  87.     gs_wifi_cptx_ptr->REQ_Query_DbmToDac();
  88. }
  89. //------------------------------------------------------------------------------
  90. static void REQ_TimeOut(void)
  91. {
  92.     gs_wifi_cptx_ptr->REQ_TimeOut();
  93. }
  94. //------------------------------------------------------------------------------
  95. static void  REQ_Finish(void)
  96. {
  97.     gs_wifi_cptx_ptr->REQ_Finish();
  98. }
  99. //===========================================================================
  100. CWIFICPT::CWIFICPT(void)
  101. {
  102.    g_bIsRunning = false;
  103.    ConfirmCallback = NULL;
  104.    m_pcTxPowerBuf = NULL;
  105.    m_iTxPowerBufSize = 0;
  106. }
  107. //---------------------------------------------------------------------------
  108. CWIFICPT::~CWIFICPT()
  109. {
  110.    g_bIsRunning = false;
  111.    ConfirmCallback = 0;
  112.    if (m_pcTxPowerBuf)
  113.    {
  114.        delete [] m_pcTxPowerBuf;
  115.        m_pcTxPowerBuf = NULL;
  116.    }
  117. }
  118. //---------------------------------------------------------------------------
  119. void CWIFICPT::REQ_Finish(void)
  120. {
  121.    if(! g_bIsRunning)  return;
  122.    Confirm(METAAPP_SUCCESS);
  123. }
  124. //---------------------------------------------------------------------------
  125. void CWIFICPT::REQ_Stop(void)
  126. {
  127.     if (!g_bIsRunning)
  128.     {
  129.         return;
  130.     }
  131.     Confirm(METAAPP_STOP);
  132. }
  133. //---------------------------------------------------------------------------
  134. void CWIFICPT::REQ_TimeOut(void)
  135. {
  136.     if (!g_bIsRunning)
  137.     {
  138.         return;
  139.     }
  140.     Confirm( METAAPP_TIMEOUT );;
  141. }
  142. //---------------------------------------------------------------------------
  143. void  CWIFICPT::Confirm( int confirm_state )
  144. {
  145.     if (!g_bIsRunning)
  146.     {
  147.         return;
  148.     }
  149.     g_bIsRunning = false;
  150.     if (NULL == ConfirmCallback)
  151.     {
  152.         return;
  153.     }
  154.     m_iConfirmState = confirm_state;
  155.     ActiveMan->SetActiveFunction(ConfirmCallback);
  156. }
  157. //===========================================================================
  158. void  CWIFICPT::REQ_Start(S_WIFICPT wificpt)
  159. {
  160.     gs_wifi_cptx_ptr           = this;
  161.     g_bIsRunning               = true;
  162.     m_sWiFiCPT                 = wificpt;
  163.     m_sPktTx.ch_freq           = wificpt.channel_freq;
  164.     m_sPktTx.tx_rate           = wificpt.tx_rate;
  165.     m_sPktTx.tx_gain_dac       = wificpt.tx_pwr_dac;
  166.     m_sPktTx.pktCount          = wificpt.pkt_count;
  167.     m_sPktTx.pktInterval       = wificpt.pkt_interval;
  168.     m_sPktTx.pktLength         = wificpt.pkt_length;
  169.     m_sPktTx.pattern           = wificpt.pattern;
  170.     m_sPktTx.txAnt             = 0;
  171.     m_sPktTx.is_short_preamble = wificpt.is_short_preamble;
  172.     m_sPktTx.txFlags           = wificpt.ui_txFlags;
  173.     m_sPktTx.targetAlc         = wificpt.ui_targetAlc;
  174.     ActiveMan->SetActiveFunction(::REQ_SetRegDomain);
  175. }
  176. //---------------------------------------------------------------------------
  177. void CWIFICPT::REQ_SetRegDomain(void)
  178. {
  179.     if (!g_bIsRunning)
  180.     {
  181.         return;
  182.     }
  183.     META_RESULT MetaResult = META_WiFi_SetRegDomain_r(m_META_HANDLE_Obj.Get_MainHandle(),  500, &m_sWiFiCPT.reg_domain);
  184.     if (MetaResult != META_SUCCESS)
  185.     {
  186.         if (MetaResult != META_TIMEOUT)
  187.         {
  188.             Confirm(METAAPP_FAIL);
  189.             return;
  190.         }
  191.         else
  192.         {
  193.             Confirm(METAAPP_TIMEOUT);
  194.             return;
  195.         }
  196.     }
  197.     ActiveMan->SetActiveFunction(::REQ_ContinuousPktTx);
  198. }
  199. //---------------------------------------------------------------------------
  200. void CWIFICPT::REQ_ContinuousPktTx( void )
  201. {
  202.     if (!g_bIsRunning)
  203.     {
  204.         return;
  205.     }
  206.     META_RESULT MetaResult;
  207.     Compose_MacHeader(m_sWiFiCPT.s_mac_header, m_sPktTx.mac_header);
  208.     if (m_sWiFiCPT.bAlcSupport)
  209.     {
  210.         MetaResult = META_WiFi_ContPktTx_Ex_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, &m_sPktTx);
  211.     }
  212.     else
  213.     {
  214.         WiFi_TestPktTx_S pkt_tx;
  215.         pkt_tx.ch_freq           = m_sPktTx.ch_freq;
  216.         pkt_tx.tx_rate           = m_sPktTx.tx_rate;
  217.         pkt_tx.tx_gain_dac       = m_sPktTx.tx_gain_dac;
  218.         pkt_tx.pktCount          = m_sPktTx.pktCount;
  219.         pkt_tx.pktInterval       = m_sPktTx.pktInterval;
  220.         pkt_tx.pktLength         = m_sPktTx.pktLength;
  221.         pkt_tx.pattern           = m_sPktTx.pattern;
  222.         pkt_tx.txAnt             = m_sPktTx.txAnt;
  223.         pkt_tx.is_short_preamble = m_sPktTx.is_short_preamble;
  224.         for (int i=0; i<WIFI_MAC_HEAD_LEN; i++)
  225.         {
  226.             pkt_tx.mac_header[i] = m_sPktTx.mac_header[i];
  227.         }
  228.         MetaResult = META_WiFi_ContPktTx_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, &pkt_tx);
  229.     }
  230.     if (MetaResult != META_SUCCESS)
  231.     {
  232.         if (MetaResult != META_TIMEOUT )
  233.         {
  234.             Confirm(METAAPP_FAIL );
  235.             return;
  236.         }
  237.     }
  238.     ActiveMan->SetActiveFunction(::REQ_Query_TxStatus);
  239. }
  240. //---------------------------------------------------------------------------
  241. void CWIFICPT::REQ_SetDbmToDac_Start( unsigned int channel_freq, WiFi_TestRate_E tx_rate, int dBm )
  242. {
  243.     gs_wifi_cptx_ptr = this;
  244.     g_bIsRunning = true;
  245.     m_sSetDbm2Dac.ch_freq = channel_freq;
  246.     m_sSetDbm2Dac.tx_rate = tx_rate;
  247.     m_sSetDbm2Dac.dbm     = dBm;
  248.     ActiveMan->SetActiveFunction( ::REQ_SetDbmToDac );
  249. }
  250. //---------------------------------------------------------------------------
  251. void CWIFICPT::REQ_SetDbmToDac( void )
  252. {
  253. #if 0
  254.     if (!g_bIsRunning)
  255.     {
  256.         return;
  257.     }
  258.     META_RESULT  MetaResult = META_WiFi_SetDbmToDac_r(m_META_HANDLE_Obj.Get_MainHandle(), 900, m_iChannelFreq, m_eTxRate, m_idBm);
  259.     if(MetaResult!=META_SUCCESS)
  260.     {
  261.         if( MetaResult!=META_TIMEOUT )
  262.         {   Confirm( METAAPP_FAIL );  return;  }
  263.         else
  264.         {   Confirm( METAAPP_TIMEOUT );  return;  }
  265.     }
  266.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  267. #endif
  268. }
  269. //===========================================================================
  270. ////////////////////////////          Query          ////////////////////////
  271. //===========================================================================
  272. void CWIFICPT::REQ_Query_TxStatus_Start(bool alc_support)
  273. {
  274.     gs_wifi_cptx_ptr = this;
  275.     g_bIsRunning = true;
  276.     m_sWiFiCPT.bAlcSupport = alc_support;
  277.     ActiveMan->SetActiveFunction(::REQ_Query_TxStatus);
  278. }
  279. //---------------------------------------------------------------------------
  280. void CWIFICPT::REQ_Query_TxStatus( void )
  281. {
  282.     if (!g_bIsRunning)
  283.     {
  284.         return;
  285.     }
  286.     META_RESULT MetaResult;
  287.     if (m_sWiFiCPT.bAlcSupport)
  288.     {
  289.         MetaResult = META_WiFi_QueryTxStatus_Ex_r(m_META_HANDLE_Obj.Get_MainHandle(), 900, &m_WiFiTxStatus);
  290.     }
  291.     else
  292.     {
  293.         WiFi_TxStatus_S tx_status;
  294.         MetaResult = META_WiFi_QueryTxStatus_r (m_META_HANDLE_Obj.Get_MainHandle(), 900, &tx_status);
  295.         m_WiFiTxStatus.pkt_sent_count = tx_status.pkt_sent_count;
  296.         m_WiFiTxStatus.pkt_sent_acked = tx_status.pkt_sent_acked;
  297.     }
  298.     
  299.     if (MetaResult != META_SUCCESS)
  300.     {
  301.         if (MetaResult != META_TIMEOUT)
  302.         {
  303.             Confirm(METAAPP_FAIL);
  304.             return;
  305.         }
  306.     }
  307.     ActiveMan->SetActiveFunction(::REQ_Finish);
  308. }
  309. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  310. void CWIFICPT::REQ_Query_DbmToDac_Start( void )
  311. {
  312.     gs_wifi_cptx_ptr = this;
  313.     g_bIsRunning = true;
  314.     ActiveMan->SetActiveFunction( ::REQ_Query_DbmToDac );
  315. }
  316. //---------------------------------------------------------------------------
  317. void CWIFICPT::REQ_Query_DbmToDac( void )
  318. {
  319. #if 0
  320.     META_RESULT MetaResult = META_WiFi_QueryDbmToDac_r ( m_META_HANDLE_Obj.Get_MainHandle(), 900, &m_usTxPwrDAC );
  321.     if(MetaResult!=META_SUCCESS)
  322.     {
  323.         if( MetaResult!=META_TIMEOUT )
  324.         {   Confirm(METAAPP_FAIL);  return;  }
  325.         else
  326.         {   Confirm( METAAPP_TIMEOUT );  return;  }
  327.     }
  328.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  329. #endif
  330. }
  331. //===========================================================================
  332. ////////////////////////////       MAC header        ////////////////////////
  333. //===========================================================================
  334. void  CWIFICPT::Compose_MacHeader( S_WiFiMacHead s_mac_head, char *p_mac_header )
  335. {
  336.     int i;
  337.     for( i=0; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN; i++ )
  338.         p_mac_header[WIFI_MAC_HEAD_LEN-i-1] = s_mac_head.seq_ctrl[i];
  339.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+WIFI_MAC_HEAD_ADDRESS_LEN; i++ )
  340.         p_mac_header[WIFI_MAC_HEAD_LEN-i-1] = s_mac_head.address3[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN];
  341.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+WIFI_MAC_HEAD_ADDRESS_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+2*WIFI_MAC_HEAD_ADDRESS_LEN; i++ )
  342.         p_mac_header[WIFI_MAC_HEAD_LEN-i-1] = s_mac_head.address2[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-WIFI_MAC_HEAD_ADDRESS_LEN];
  343.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+2*WIFI_MAC_HEAD_ADDRESS_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN; i++ )
  344.         p_mac_header[WIFI_MAC_HEAD_LEN-i-1] = s_mac_head.address1[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-2*WIFI_MAC_HEAD_ADDRESS_LEN];
  345.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN+WIFI_MAC_HEAD_DURATION_LEN; i++ )
  346.         p_mac_header[WIFI_MAC_HEAD_LEN-i-1] = s_mac_head.duration[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-3*WIFI_MAC_HEAD_ADDRESS_LEN];
  347.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN+WIFI_MAC_HEAD_DURATION_LEN; i<WIFI_MAC_HEAD_LEN; i++ )
  348.         p_mac_header[WIFI_MAC_HEAD_LEN-i-1] = s_mac_head.frame_ctrl[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-3*WIFI_MAC_HEAD_ADDRESS_LEN-WIFI_MAC_HEAD_DURATION_LEN];
  349. }
  350. //----------------------------------------------------------------------------
  351. void  CWIFICPT::DeCompose_MacHeader( char *p_mac_header, S_WiFiMacHead &s_mac_head )
  352. {
  353.     int i;
  354.     for( i=0; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN; i++ )
  355.         s_mac_head.seq_ctrl[i] = p_mac_header[WIFI_MAC_HEAD_SEQ_CTRL_LEN-i-1];
  356.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+WIFI_MAC_HEAD_ADDRESS_LEN; i++ )
  357.         s_mac_head.address3[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN] = p_mac_header[WIFI_MAC_HEAD_SEQ_CTRL_LEN-i-1];
  358.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+WIFI_MAC_HEAD_ADDRESS_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+2*WIFI_MAC_HEAD_ADDRESS_LEN; i++ )
  359.         s_mac_head.address2[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-WIFI_MAC_HEAD_ADDRESS_LEN] = p_mac_header[WIFI_MAC_HEAD_SEQ_CTRL_LEN-i-1];
  360.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+2*WIFI_MAC_HEAD_ADDRESS_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN; i++ )
  361.         s_mac_head.address1[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-2*WIFI_MAC_HEAD_ADDRESS_LEN] = p_mac_header[WIFI_MAC_HEAD_SEQ_CTRL_LEN-i-1];
  362.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN; i<WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN+WIFI_MAC_HEAD_DURATION_LEN; i++ )
  363.         s_mac_head.duration[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-3*WIFI_MAC_HEAD_ADDRESS_LEN] = p_mac_header[WIFI_MAC_HEAD_SEQ_CTRL_LEN-i-1];
  364.     for( i=WIFI_MAC_HEAD_SEQ_CTRL_LEN+3*WIFI_MAC_HEAD_ADDRESS_LEN+WIFI_MAC_HEAD_DURATION_LEN; i<WIFI_MAC_HEAD_LEN; i++ )
  365.         s_mac_head.frame_ctrl[i-WIFI_MAC_HEAD_SEQ_CTRL_LEN-3*WIFI_MAC_HEAD_ADDRESS_LEN-WIFI_MAC_HEAD_DURATION_LEN] = p_mac_header[WIFI_MAC_HEAD_SEQ_CTRL_LEN-i-1];
  366. }
  367. //===========================================================================
  368. ////////////////////////////   Global  information   ////////////////////////
  369. //===========================================================================
  370. int   CWIFICPT::Get_ConfirmState( void )
  371. {
  372.     return  m_iConfirmState;
  373. }
  374. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  375. WiFi_TxPower_2400M_S  CWIFICPT::Get_TxPwr2400M( void )
  376. {
  377.     return m_sTxPwr2400M;
  378. }
  379. //----------------------------------------------------------------------------
  380. void  CWIFICPT::Set_TxPwr2400M( WiFi_TxPower_2400M_S *p_tx_pwr_2400m )
  381. {
  382.     m_sTxPwr2400M = *p_tx_pwr_2400m;
  383. }
  384. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  385. WiFi_TxPower_5000M_S  CWIFICPT::Get_TxPwr5000M( void )
  386. {
  387.     return m_sTxPwr5000M;
  388. }
  389. //----------------------------------------------------------------------------
  390. void  CWIFICPT::Set_TxPwr5000M( WiFi_TxPower_5000M_S *p_tx_pwr_5000m )
  391. {
  392.     m_sTxPwr5000M = *p_tx_pwr_5000m;
  393. }
  394. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  395. WiFi_TxStatus_Ex_S  CWIFICPT::Get_TxStatus( void )
  396. {
  397.     return m_WiFiTxStatus;
  398. }