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

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.  *   bt_hci_ft.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *   BT HCI command compose/event decompose 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 <stdio.h>
  42. #pragma hdrstop
  43. // BT
  44. #ifndef  _BT_HCI_FT_H_
  45. #include "bt_hci_ft.h"
  46. #endif
  47. #ifndef  _BT_HCI_COMMON_H_
  48. #include "bt_hci_common.h"
  49. #endif
  50. //==============================================================================
  51. static CBTHCIFT*  gs_bt_ft_ptr;
  52. //===========================================================================
  53. CBTHCIFT::CBTHCIFT(void)
  54. {
  55. }
  56. //---------------------------------------------------------------------------
  57. CBTHCIFT::~CBTHCIFT(void)
  58. {
  59. }
  60. //===========================================================================
  61. //////////////////////////  Compose/decompose HCI command  //////////////////
  62. //===========================================================================
  63. void CBTHCIFT::Reset_HCI_Command(BT_HCI_COMMAND &hci_cmd)
  64. {
  65.     for( int i=0; i<(sizeof(hci_cmd.m_cmd)/sizeof(hci_cmd.m_cmd[0])); i++ )
  66.     {
  67.         hci_cmd.m_cmd[i] = 0;
  68.     }
  69. }
  70. //---------------------------------------------------------------------------
  71. void CBTHCIFT::Compose_Reset_HCI_Command(BT_HCI_COMMAND &hci_cmd)
  72. {
  73.     hci_cmd.m_opcode = 0x0C03;
  74.     hci_cmd.m_len    = 0x00;
  75. }
  76. //---------------------------------------------------------------------------
  77. bool CBTHCIFT::DeCompose_Reset_HCI_Event(BT_HCI_EVENT hci_event)
  78. {
  79.     if ((hci_event.m_len      != 0x04) ||
  80.         (hci_event.m_parms[0] != 0x01) ||
  81.         (hci_event.m_parms[1] != 0x03) ||
  82.         (hci_event.m_parms[2] != 0x0C) ||
  83.         (hci_event.m_parms[3] != 0x00)
  84.       )
  85.     {
  86.         return false;
  87.     }
  88.     return true;
  89. }
  90. //--------------------------------------------------------------------------
  91. void  CBTHCIFT::Compose_Read_BD_Addr_HCI_Command(BT_HCI_COMMAND &hci_cmd)
  92. {
  93.     hci_cmd.m_opcode = 0x1009;
  94.     hci_cmd.m_len    = 0;
  95.     Reset_HCI_Command( hci_cmd );
  96. }
  97. //--------------------------------------------------------------------------
  98. bool CBTHCIFT::DeCompose_Read_BD_Addr_HCI_Event(BT_HCI_EVENT hci_event, S_BD_ADDR &bd_addr)
  99. {
  100.     if ((0x09 != hci_event.m_parms[1]) ||
  101.         (0x10 != hci_event.m_parms[2]) ||
  102.         (0x00 != hci_event.m_parms[3])
  103.        )
  104.     {
  105.         return false;
  106.     }
  107.     for (int i=0; i<BD_ADDRESS_LEN; i++)
  108.     {
  109.         bd_addr.uc_BD_Addr[i] = hci_event.m_parms[4+i];
  110.     }
  111.     return true;
  112. }
  113. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  114. void  CBTHCIFT::Compose_Enter_Test_Mode_HCI_Command( BT_HCI_COMMAND &hci_cmd )
  115. {
  116.     hci_cmd.m_opcode = 0x1803;
  117.     hci_cmd.m_len    = 0;
  118.     Reset_HCI_Command( hci_cmd );
  119. }
  120. //---------------------------------------------------------------------------
  121. bool CBTHCIFT::DeCompose_Enter_Test_Mode_HCI_Event(BT_HCI_EVENT hci_event)
  122. {
  123.     if ((0x03 != hci_event.m_parms[1]) ||
  124.         (0x18 != hci_event.m_parms[2]) ||
  125.         (0x00 != hci_event.m_parms[3])
  126.        )
  127.     {
  128.         return false;
  129.     }
  130.     return true;
  131. }
  132. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  133. void  CBTHCIFT::Compose_Scan_Enable_HCI_Command( BT_HCI_COMMAND &hci_cmd )
  134. {
  135.     hci_cmd.m_opcode = 0x0C1A;
  136.     hci_cmd.m_len    = 1;
  137.     Reset_HCI_Command( hci_cmd );
  138.     hci_cmd.m_cmd[0] = 0x03;
  139. }
  140. //---------------------------------------------------------------------------
  141. bool  CBTHCIFT::DeCompose_Scan_Enable_HCI_Event(BT_HCI_EVENT hci_event)
  142. {
  143.     if ((0x1A != hci_event.m_parms[1]) ||
  144.         (0x0C != hci_event.m_parms[2]) ||
  145.         (0x00 != hci_event.m_parms[3])
  146.        )
  147.     {
  148.         return false;
  149.     }
  150.     return true;
  151. }
  152. //--------------------------------------------------------------------------
  153. void  CBTHCIFT::Compose_Auto_Accept_HCI_Command( BT_HCI_COMMAND &hci_cmd )
  154. {
  155.     hci_cmd.m_opcode = 0x0C05;
  156.     hci_cmd.m_len    = 3;
  157.     Reset_HCI_Command( hci_cmd );
  158.     hci_cmd.m_cmd[0] = 0x02;
  159.     hci_cmd.m_cmd[1] = 0x00;
  160.     hci_cmd.m_cmd[2] = 0x02;
  161. }
  162. //---------------------------------------------------------------------------
  163. bool CBTHCIFT::DeCompose_Auto_Accept_HCI_Event(BT_HCI_EVENT hci_event)
  164. {
  165.     if ((0x05 != hci_event.m_parms[1]) ||
  166.         (0x0C != hci_event.m_parms[2]) ||
  167.         (0x00 != hci_event.m_parms[3])
  168.        )
  169.     {
  170.         return false;
  171.     }
  172.     return true;
  173. }
  174. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175. void  CBTHCIFT::Compose_ACL_Connect_HCI_Command( S_BD_ADDR &bd_addr, BT_HCI_COMMAND &hci_cmd )
  176. {
  177.     int i;
  178.     hci_cmd.m_opcode = 0x0405;
  179.     hci_cmd.m_len = 13;
  180.     Reset_HCI_Command( hci_cmd );
  181.     for( i=0; i<BD_ADDRESS_LEN; i++ )
  182.         hci_cmd.m_cmd[i] = bd_addr.uc_BD_Addr[i];
  183.     hci_cmd.m_cmd[6]  = 0x18;
  184.     hci_cmd.m_cmd[7]  = 0xCC;
  185.     hci_cmd.m_cmd[8]  = 0x01;
  186.     hci_cmd.m_cmd[9]  = 0x00;
  187.     hci_cmd.m_cmd[10] = 0xA7;
  188.     hci_cmd.m_cmd[11] = 0xFC;
  189.     hci_cmd.m_cmd[12] = 0x00;
  190.     
  191. }
  192. //---------------------------------------------------------------------------
  193. bool CBTHCIFT::DeCompose_ACL_Connect_HCI_Event1(BT_HCI_EVENT hci_event)
  194. {
  195.     if ((0x05 != hci_event.m_parms[2]) ||
  196.         (0x04 != hci_event.m_parms[3])
  197.        )
  198.     {
  199.         return false;
  200.     }
  201.     return true;
  202. }
  203. //---------------------------------------------------------------------------
  204. bool  CBTHCIFT::DeCompose_ACL_Connect_HCI_Event2(BT_HCI_EVENT hci_event, S_BD_ADDR &bd_addr, unsigned char &h1, unsigned char &h2)
  205. {
  206.     // 03 0B 00 (H1 H2) 08 FF 00 22 2D AE 01 00
  207.     if ((0x00 != hci_event.m_parms[0]) ||  // connect not successfully
  208.         (0x00 != hci_event.m_parms[2]) ||
  209.         (0x01 != hci_event.m_parms[9]) ||
  210.         (0x00 != hci_event.m_parms[10])
  211.        )
  212.     {
  213.         return false;
  214.     }
  215.     for (int i=0; i<BD_ADDRESS_LEN; i++)
  216.     {
  217.         if (bd_addr.uc_BD_Addr[i] != hci_event.m_parms[i+3])
  218.         {
  219.             return false;
  220.         }    
  221.     }
  222.     h1 = hci_event.m_parms[1];
  223.     h2 = hci_event.m_parms[2];
  224.     return true;
  225. }
  226. //---------------------------------------------------------------------------
  227. bool  CBTHCIFT::DeCompose_ACL_Connect_HCI_Event3(BT_HCI_EVENT hci_event, unsigned char &h1, unsigned char &h2 )
  228. {
  229.     // 1B 03 (H1 H2) 05
  230.     if ((0x1B != hci_event.m_parms[0]) ||
  231.         (0x03 != hci_event.m_parms[1])  ||
  232.         (0x05 != hci_event.m_parms[4])
  233.        )
  234.     {  return false;
  235.     }
  236.     h1 = hci_event.m_parms[2];
  237.     h2 = hci_event.m_parms[3];
  238.     return true;
  239. }
  240. //---------------------------------------------------------------------------
  241. bool CBTHCIFT::DeCompose_ACL_Connect_HCI_Event4(BT_HCI_EVENT hci_event, unsigned char &h1, unsigned char &h2 )
  242. {
  243.     // 1D 05 00 (H1 H2) 18 CC
  244.     if ((0x1D != hci_event.m_parms[0]) ||
  245.         (0x05 != hci_event.m_parms[1]) ||
  246.         (0x00 != hci_event.m_parms[2]) ||
  247.         (0x18 != hci_event.m_parms[5]) ||
  248.         (0xCC != hci_event.m_parms[6])
  249.        )
  250.     {
  251.         return false;
  252.     }
  253.     h1 = hci_event.m_parms[3];
  254.     h2 = hci_event.m_parms[4];
  255.     return true;
  256. }
  257. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  258. void  CBTHCIFT::Compose_TCI_Activate_Remote_DUT_HCI_Command( unsigned char h1, unsigned char h2, BT_HCI_COMMAND &hci_cmd)
  259. {
  260.     hci_cmd.m_opcode = 0xFC02;
  261.     hci_cmd.m_len = 2;
  262.     Reset_HCI_Command( hci_cmd );
  263.     hci_cmd.m_cmd[0]  = h1;
  264.     hci_cmd.m_cmd[7]  = h2;
  265. }
  266. //---------------------------------------------------------------------------
  267. bool CBTHCIFT::DeCompose_TCI_Activate_Remote_DUT_HCI_Event1(BT_HCI_EVENT hci_event)
  268. {
  269.     if ((0x02 != hci_event.m_parms[2]) ||
  270.         (0xFC != hci_event.m_parms[3])
  271.        )
  272.     {  return false;
  273.     }
  274.     return true;
  275. }
  276. //---------------------------------------------------------------------------
  277. bool CBTHCIFT::DeCompose_TCI_Activate_Remote_DUT_HCI_Event2(BT_HCI_EVENT hci_event)
  278. {
  279.     // 0E 04 01 02 FC 00
  280.     if((0x02 != hci_event.m_parms[1]) ||
  281.        (0xFC != hci_event.m_parms[2]) ||
  282.        (0x00 != hci_event.m_parms[3])
  283.        )
  284.     {
  285.         return false;
  286.     }
  287.     return true;
  288. }
  289. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  290. void  CBTHCIFT::Compose_TCI_Control_Remote_DUT_HCI_Command(unsigned char h1,
  291.                                                            unsigned char h2,
  292.                                                            S_BT_PKT_TCI req,
  293.                                                            BT_HCI_COMMAND &hci_cmd)
  294. {
  295.     // 03 FC 1B (H1 H2) 07 01 00 00 00 02 03 11 00 00 00 01 00 00 00 00 00 00 00 00 00 (N1 N2 N3 N4)
  296.     hci_cmd.m_opcode = 0xFC03;
  297.     hci_cmd.m_len    = 0x1B;
  298.     Reset_HCI_Command( hci_cmd );
  299.     hci_cmd.m_cmd[0] = h1;
  300.     hci_cmd.m_cmd[1] = h2;
  301.     hci_cmd.m_cmd[2] = 0x07;
  302.     hci_cmd.m_cmd[3] = 0x01;
  303.     hci_cmd.m_cmd[4] = 0x00;
  304.     hci_cmd.m_cmd[5] = 0x00;
  305.     hci_cmd.m_cmd[6] = 0x00;
  306.     hci_cmd.m_cmd[7] = req.uc_poll_period;
  307.    // hci_cmd.m_cmd[8] = 0x03;
  308.     hci_cmd.m_cmd[9] = req.us_packet_length & 0x00FF;
  309.     hci_cmd.m_cmd[10]= (req.us_packet_length & 0xFF00)>>8;
  310.     hci_cmd.m_cmd[11]= 0x00;
  311.     hci_cmd.m_cmd[12]= 0x00;
  312.     hci_cmd.m_cmd[13]= 0x01;
  313.     hci_cmd.m_cmd[14]= 0x00;
  314.     hci_cmd.m_cmd[15]= 0x00;
  315.     hci_cmd.m_cmd[16]= 0x00;
  316.     hci_cmd.m_cmd[17]= 0x00;
  317.     hci_cmd.m_cmd[18]= 0x00;
  318.     hci_cmd.m_cmd[19]= 0x00;
  319.     hci_cmd.m_cmd[20]= 0x00;
  320.     hci_cmd.m_cmd[21]= 0x00;
  321.     hci_cmd.m_cmd[22]= 0x00;
  322.     hci_cmd.m_cmd[23]= req.ui_packet_count & 0x000000FF;
  323.     hci_cmd.m_cmd[24]= (req.ui_packet_count & 0x0000FF00)>>8;
  324.     hci_cmd.m_cmd[25]= (req.ui_packet_count & 0x00FF0000)>>16;
  325.     hci_cmd.m_cmd[26]= (req.ui_packet_count & 0xFF000000)>>24;
  326.     switch( req.e_idx )
  327.     {
  328.         case BT_PACKET_IDX_DM1:
  329.         {
  330.             hci_cmd.m_cmd[8] = 0x03; // type
  331.         }
  332.         break;
  333.         case BT_PACKET_IDX_DH1:
  334.         {
  335.             hci_cmd.m_cmd[8] = 0x04;
  336.         }
  337.         break;
  338.         case BT_PACKET_IDX_DM3:
  339.         {
  340.             hci_cmd.m_cmd[8] = 0x0A;
  341.         }
  342.         break;
  343.         case BT_PACKET_IDX_DH3:
  344.         {
  345.             hci_cmd.m_cmd[8] = 0x0B;
  346.         }
  347.         break;
  348.         case BT_PACKET_IDX_DM5:
  349.         {
  350.             hci_cmd.m_cmd[8] = 0x0E;
  351.         }
  352.         break;
  353.         case BT_PACKET_IDX_DH5:
  354.         {
  355.             hci_cmd.m_cmd[8] = 0x0F;
  356.         }
  357.         break;
  358.         case BT_PACKET_IDX_HV1:
  359.         {
  360.             hci_cmd.m_cmd[8] = 0x05;
  361.         }
  362.         break;
  363.         case BT_PACKET_IDX_HV2:
  364.         {
  365.             hci_cmd.m_cmd[8] = 0x06;
  366.         }
  367.         break;
  368.         case BT_PACKET_IDX_HV3:
  369.         {
  370.             hci_cmd.m_cmd[8] = 0x07;
  371.         }
  372.         break;
  373.         case BT_PACKET_IDX_EV3:
  374.         {
  375.             hci_cmd.m_cmd[8] = 0x17;
  376.         }
  377.         break;
  378.         case BT_PACKET_IDX_EV4:
  379.         {
  380.             hci_cmd.m_cmd[8] = 0x1C;
  381.         }
  382.         break;
  383.         case BT_PACKET_IDX_EV5:
  384.         {
  385.             hci_cmd.m_cmd[8] = 0x1D;
  386.         }
  387.         break;
  388.         case BT_PACKET_IDX_2DH1:
  389.         {
  390.             hci_cmd.m_cmd[8] = 0x24;
  391.         }
  392.         break;
  393.         case BT_PACKET_IDX_2EV3:
  394.         {
  395.             hci_cmd.m_cmd[8] = 0x36;
  396.         }
  397.         break;
  398.         case BT_PACKET_IDX_2DH3:
  399.         {
  400.             hci_cmd.m_cmd[8] = 0x2A;
  401.         }
  402.         break;
  403.         case BT_PACKET_IDX_2EV5:
  404.         {
  405.             hci_cmd.m_cmd[8] = 0x3C;
  406.         }
  407.         break;
  408.         case BT_PACKET_IDX_2DH5:
  409.         {
  410.             hci_cmd.m_cmd[8] = 0x2E;
  411.         }
  412.         break;
  413.         case BT_PACKET_IDX_3EV3:
  414.         {
  415.             hci_cmd.m_cmd[8] = 0x37;
  416.         }
  417.         break;
  418.         case BT_PACKET_IDX_3DH1:
  419.         {
  420.             hci_cmd.m_cmd[8] = 0x28;
  421.         }
  422.         break;
  423.         case BT_PACKET_IDX_3DH3:
  424.         {
  425.             hci_cmd.m_cmd[8] = 0x2B;
  426.         }
  427.         break;
  428.         case BT_PACKET_IDX_3EV5:
  429.         {
  430.             hci_cmd.m_cmd[8] = 0x3D;
  431.         }
  432.         break;
  433.         case BT_PACKET_IDX_3DH5:
  434.         {
  435.             hci_cmd.m_cmd[8] = 0x2F;
  436.         }
  437.         break;
  438.     }
  439. }
  440. //---------------------------------------------------------------------------
  441. bool  CBTHCIFT::DeCompose_TCI_Control_Remote_DUT_HCI_Event1(BT_HCI_EVENT hci_event)
  442. {
  443.     //  0F 04 00 01 03 FC
  444.     if ((0x03 != hci_event.m_parms[1]) ||
  445.         (0xFC != hci_event.m_parms[2]) ||
  446.         (0x00 != hci_event.m_parms[3])
  447.        )
  448.     {
  449.         return false;
  450.     }
  451.     return true;
  452. }
  453. //---------------------------------------------------------------------------
  454. bool CBTHCIFT::DeCompose_TCI_Control_Remote_DUT_HCI_Event2(BT_HCI_EVENT hci_event)
  455. {
  456.     //  0E 04 01 03 FC 00
  457.     if ((0x03 != hci_event.m_parms[1]) ||
  458.         (0xFC != hci_event.m_parms[2]) ||
  459.         (0x00 != hci_event.m_parms[3])
  460.        )
  461.     {
  462.         return false;
  463.     }
  464.     return true;
  465. }
  466. #if 0
  467. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  468. void  CBTHCIFT::Compose_Enable_SCO_Connect_HCI_Command1( BT_HCI_COMMAND &hci_cmd )
  469. {
  470.    // 05,0C,01,00
  471.    hci_cmd.m_opcode = 0x0C05;
  472.    hci_cmd.m_len    = 1;
  473.    Reset_HCI_Command( hci_cmd );
  474. }
  475. //---------------------------------------------------------------------------
  476. bool  CBTHCIFT::DeCompose_Enable_SCO_Connect_HCI_Event1( BT_HCI_EVENT &hci_event )
  477. {
  478.     // 0E,04,01,05,0C,00
  479.     if(
  480.         0x05 != hci_event.m_parms[1]  ||
  481.         0x0C != hci_event.m_parms[2]  ||
  482.         0x00 != hci_event.m_parms[3]
  483.        )
  484.     {  return false;
  485.     }
  486.     return true;
  487. }
  488. //---------------------------------------------------------------------------
  489. void  CBTHCIFT::Compose_Enable_SCO_Connect_HCI_Command2( S_BD_ADDR &bd_addr, E_BT_SCO sco, BT_HCI_COMMAND &hci_cmd )
  490. {
  491.     // 29,04,15,Y1,Y2,Y3,Y4,Y5,Y6,40,1F,00,00,40,1F,00,00,05,00,AF,00,00,KK,00
  492.     hci_cmd.m_opcode = 0x0429;
  493.     hci_cmd.m_len     = 21;
  494.     Reset_HCI_Command( hci_cmd );
  495.     for( int i=0; i<BD_ADDRESS_LEN; i++ )
  496.     {
  497.         hci_cmd.m_cmd[i] = bd_addr.uc_BD_Addr[i];
  498.     }
  499.     hci_cmd.m_cmd[6]  = 0x40;
  500.     hci_cmd.m_cmd[7]  = 0x1F;
  501.     hci_cmd.m_cmd[8]  = 0x00;
  502.     hci_cmd.m_cmd[9]  = 0x00;
  503.     hci_cmd.m_cmd[10] = 0x40;
  504.     hci_cmd.m_cmd[11] = 0x1F;
  505.     hci_cmd.m_cmd[12] = 0x00;
  506.     hci_cmd.m_cmd[13] = 0x00;
  507.     hci_cmd.m_cmd[14] = 0x05;
  508.     hci_cmd.m_cmd[15] = 0x00;
  509.     hci_cmd.m_cmd[16] = 0xAF;
  510.     hci_cmd.m_cmd[17] = 0x00;
  511.     hci_cmd.m_cmd[18] = 0x00;
  512.     hci_cmd.m_cmd[19] = sco;
  513.     hci_cmd.m_cmd[20] = 0x00;
  514. }
  515. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  516. void  CBTHCIFT::Compose_Create_SCO_Connect_HCI_Command( E_BT_ACL_P1 p1, E_BT_ACL_P1 p2, E_BT_SCO sco, BT_HCI_COMMAND &hci_cmd )
  517. {
  518.    // 28,04,11,H1,H2,40,1F,00,00,40,1F,00,00,05,00,AF,00,00,KK,00
  519.    hci_cmd.m_opcode = 0x0428;
  520.    hci_cmd.m_len     = 17;
  521.    Reset_HCI_Command( hci_cmd );
  522.    hci_cmd.m_cmd[0]  = p1;
  523.    hci_cmd.m_cmd[1]  = p2;
  524.    hci_cmd.m_cmd[2]  = 0x40;
  525.    hci_cmd.m_cmd[3]  = 0x1F;
  526.    hci_cmd.m_cmd[4]  = 0x00;
  527.    hci_cmd.m_cmd[5]  = 0x00;
  528.    hci_cmd.m_cmd[6]  = 0x40;
  529.    hci_cmd.m_cmd[7]  = 0x1F;
  530.    hci_cmd.m_cmd[8]  = 0x00;
  531.    hci_cmd.m_cmd[9]  = 0x00;
  532.    hci_cmd.m_cmd[10] = 0x05;
  533.    hci_cmd.m_cmd[11] = 0x00;
  534.    hci_cmd.m_cmd[12] = 0xAF;
  535.    hci_cmd.m_cmd[13] = 0x00;
  536.    hci_cmd.m_cmd[14] = 0x00;
  537.    hci_cmd.m_cmd[15] = sco;
  538.    hci_cmd.m_cmd[16] = 0x00;
  539. }
  540. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  541. void  CBTHCIFT::Compose_Start_TX_Packet_HCI_Command( E_BT_ACL_P1 p1, E_BT_ACL_P1 p2, unsigned char poll_period,
  542.                                                    unsigned short packet_length, BT_HCI_COMMAND &hci_cmd )
  543. {
  544.     // 000: 03,FC,17,
  545.     // 003: H1,H2
  546.     // 005: scenario (01)
  547.     // 006: hop_mode (01)
  548.     // 007: tx_freq  (00)
  549.     // 008: rx_freq  (00)
  550.     // 009: power_control_mode (00)
  551.     // 010: poll_period
  552.     // 011: packet_type (P2)
  553.     // 012: packet_length
  554.     // 014: system_test_group (01,00,01,00)
  555.     // 018: system_test_subgroup (06,P1,00,00)
  556.     // 022: test_number (E8,03,00,00)
  557.     hci_cmd.m_opcode = 0xFC03;
  558.     hci_cmd.m_len     = 23;
  559.     Reset_HCI_Command( hci_cmd );
  560.     hci_cmd.m_cmd[0]  = p1;
  561.     hci_cmd.m_cmd[1]  = p2;
  562.     hci_cmd.m_cmd[2]  = 0x01;
  563.     hci_cmd.m_cmd[3]  = 0x01;
  564.     hci_cmd.m_cmd[4]  = 0x00;
  565.     hci_cmd.m_cmd[5]  = 0x00;
  566.     hci_cmd.m_cmd[6]  = 0x00;
  567.     hci_cmd.m_cmd[7]  = poll_period;
  568.     hci_cmd.m_cmd[8]  = p2;
  569.     hci_cmd.m_cmd[9]  = packet_length & 0x00FF;
  570.     hci_cmd.m_cmd[10] = (packet_length & 0xFF00) >> 8;
  571.     hci_cmd.m_cmd[11] = 0x01;
  572.     hci_cmd.m_cmd[12] = 0x00;
  573.     hci_cmd.m_cmd[13] = 0x01;
  574.     hci_cmd.m_cmd[14] = 0x00;
  575.     hci_cmd.m_cmd[15] = 0x06;
  576.     hci_cmd.m_cmd[16] = p1;
  577.     hci_cmd.m_cmd[17] = 0x00;
  578.     hci_cmd.m_cmd[18] = 0x00;
  579.     hci_cmd.m_cmd[19] = 0xE8;
  580.     hci_cmd.m_cmd[20] = 0x03;
  581.     hci_cmd.m_cmd[21] = 0x00;
  582.     hci_cmd.m_cmd[22] = 0x00;
  583. }
  584. //---------------------------------------------------------------------------
  585. bool  CBTHCIFT::DeCompose_Start_TX_Packet_HCI_Event( BT_HCI_EVENT &hci_event )
  586. {
  587.     // 0E,04,01,03,FC,00
  588.     if(
  589.         0x03 != hci_event.m_parms[1]  ||
  590.         0xFC != hci_event.m_parms[2]  ||
  591.         0x00 != hci_event.m_parms[3]
  592.        )
  593.     {  return false;
  594.     }
  595.     return true;
  596. }
  597. #endif
  598. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  599. void  CBTHCIFT::Compose_Read_TX_RX_Count_HCI_Command( BT_HCI_COMMAND &hci_cmd )
  600. {
  601.     hci_cmd.m_opcode = 0xFC3F;
  602.     hci_cmd.m_len     = 0;
  603.     Reset_HCI_Command( hci_cmd );
  604. }
  605. //---------------------------------------------------------------------------
  606. bool CBTHCIFT::DeCompose_Read_TX_RX_Count_HCI_Event(BT_HCI_EVENT hci_event, S_BT_PKT_MONITOR_TXRX_CNF &monitor )
  607. {
  608.     // 04,0E,F8,01 3F FC 00
  609.     if ((0x3F != hci_event.m_parms[1]) ||
  610.         (0xFC != hci_event.m_parms[2]) ||
  611.         (0x00 != hci_event.m_parms[3])
  612.        )
  613.     {
  614.         return false;
  615.     }
  616.     
  617.     // TX
  618.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_DM1] =  hci_event.m_parms[48]        |
  619.                                                  (hci_event.m_parms[49] << 8)  |
  620.                                                  (hci_event.m_parms[50] << 16) |
  621.                                                  (hci_event.m_parms[51] << 24) ;
  622.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_DH1] =  hci_event.m_parms[52]        |
  623.                                                  (hci_event.m_parms[53] << 8)  |
  624.                                                  (hci_event.m_parms[54] << 16) |
  625.                                                  (hci_event.m_parms[55] << 24);
  626.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_HV1] =  hci_event.m_parms[56]        |
  627.                                                  (hci_event.m_parms[57] << 8)  |
  628.                                                  (hci_event.m_parms[58] << 16) |
  629.                                                  (hci_event.m_parms[59] << 24);
  630.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_HV2] =  hci_event.m_parms[60]        |
  631.                                                  (hci_event.m_parms[61] <<  8) |
  632.                                                  (hci_event.m_parms[62] << 16) |
  633.                                                  (hci_event.m_parms[63] << 24);
  634.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_HV3] = hci_event.m_parms[64]         |
  635.                                                  (hci_event.m_parms[65] << 8)  |
  636.                                                  (hci_event.m_parms[66] << 16) |
  637.                                                  (hci_event.m_parms[67] << 24);
  638.    // monitor.ui_tx_pkt_count[BT_PACKET_IDX_DV] =  hci_event.m_parms[68]  |
  639.    //                                              (hci_event.m_parms[69] << 8) |
  640.    //                                              (hci_event.m_parms[70] << 16) |
  641.    //                                              ( hci_event.m_parms[71]<<24);
  642.    // monitor.ui_tx_pkt_count[BT_PACKET_IDX_AUX] = hci_event.m_parms[72]  |
  643.    //                                              (hci_event.m_parms[73] << 8) |
  644.    //                                              (hci_event.m_parms[74] << 16) |
  645.    //                                              (hci_event.m_parms[75] << 24);
  646.    //
  647.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_DM3] = hci_event.m_parms[76]         |
  648.                                                  (hci_event.m_parms[77] << 8)  |
  649.                                                  (hci_event.m_parms[78] << 16) |
  650.                                                  (hci_event.m_parms[79] << 24);
  651.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_DH3] = hci_event.m_parms[80]         |
  652.                                                  (hci_event.m_parms[81] << 8)  |
  653.                                                  (hci_event.m_parms[82] << 16) |
  654.                                                  (hci_event.m_parms[83] << 24);
  655.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_EV4] =  hci_event.m_parms[84]        |
  656.                                                  (hci_event.m_parms[85] << 8)  |
  657.                                                  (hci_event.m_parms[86] << 16) |
  658.                                                  (hci_event.m_parms[87] << 24);
  659.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_EV5] =  hci_event.m_parms[88]        |
  660.                                                  (hci_event.m_parms[89] << 8)  |
  661.                                                  (hci_event.m_parms[90] << 16) |
  662.                                                  (hci_event.m_parms[91] << 24);
  663.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_DM5] =  hci_event.m_parms[92]        |
  664.                                                  (hci_event.m_parms[93] << 8)  |
  665.                                                  (hci_event.m_parms[94] << 16) |
  666.                                                  (hci_event.m_parms[95] << 24);
  667.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_DH5] =  hci_event.m_parms[96]        |
  668.                                                  (hci_event.m_parms[97] <<  8) |
  669.                                                  (hci_event.m_parms[98] << 16) |
  670.                                                  (hci_event.m_parms[99] << 24);
  671.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_EV3] =  hci_event.m_parms[128]       |
  672.                                                  (hci_event.m_parms[129] <<  8)|
  673.                                                  (hci_event.m_parms[130] << 16)|
  674.                                                  (hci_event.m_parms[131] << 24);
  675.     // RX
  676.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_DM1] =  hci_event.m_parms[144]       |
  677.                                                  (hci_event.m_parms[145] << 8) |
  678.                                                  (hci_event.m_parms[146] << 16)|
  679.                                                  (hci_event.m_parms[147] << 24);
  680.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_DH1] =  hci_event.m_parms[148]       |
  681.                                                  (hci_event.m_parms[149] << 8) |
  682.                                                  (hci_event.m_parms[150] << 16)|
  683.                                                  (hci_event.m_parms[151] << 24);
  684.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_HV1] =  hci_event.m_parms[152]       |
  685.                                                  (hci_event.m_parms[153] << 8) |
  686.                                                  (hci_event.m_parms[154] << 16)|
  687.                                                  (hci_event.m_parms[155] << 24);
  688.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_HV2] =  hci_event.m_parms[156]       |
  689.                                                  (hci_event.m_parms[157] << 8) |
  690.                                                  (hci_event.m_parms[158] << 16)|
  691.                                                  (hci_event.m_parms[159] << 24);
  692.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_HV3] =  hci_event.m_parms[160]       |
  693.                                                  (hci_event.m_parms[161] <<  8)|
  694.                                                  (hci_event.m_parms[162] << 16)|
  695.                                                  (hci_event.m_parms[163] << 24);
  696.    // monitor.ui_rx_pkt_count[BT_PACKET_IDX_DV] =  hci_event.m_parms[164]  |
  697.    //                                              (hci_event.m_parms[165] << 8) |
  698.    //                                              (hci_event.m_parms[166] << 16) |
  699.    //                                              (hci_event.m_parms[167] << 24);
  700.   //  monitor.ui_rx_pkt_count[BT_PACKET_IDX_AUX] = hci_event.m_parms[168]  |
  701.   //                                               (hci_event.m_parms[169] << 8) |
  702.   //                                               (hci_event.m_parms[170] << 16) |
  703.   //                                               (hci_event.m_parms[171] << 24);
  704.   //
  705.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_DM3] = hci_event.m_parms[172]        |
  706.                                                  (hci_event.m_parms[173] << 8) |
  707.                                                  (hci_event.m_parms[174] << 16)|
  708.                                                  (hci_event.m_parms[175] << 24);
  709.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_DH3] = hci_event.m_parms[176]        |
  710.                                                  (hci_event.m_parms[177] << 8) |
  711.                                                  (hci_event.m_parms[178] << 16)|
  712.                                                  (hci_event.m_parms[179] << 24);
  713.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_EV4] = hci_event.m_parms[180]        |
  714.                                                  (hci_event.m_parms[181] << 8) |
  715.                                                  (hci_event.m_parms[182] << 16)|
  716.                                                  (hci_event.m_parms[183] << 24);
  717.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_EV5] = hci_event.m_parms[184]        |
  718.                                                  (hci_event.m_parms[185] << 8) |
  719.                                                  (hci_event.m_parms[186] << 16)|
  720.                                                  (hci_event.m_parms[187] << 24);
  721.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_DM5] =  hci_event.m_parms[188]       |
  722.                                                  (hci_event.m_parms[189] << 8) |
  723.                                                  (hci_event.m_parms[190] << 16)|
  724.                                                  (hci_event.m_parms[191] << 24);
  725.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_DH5] =  hci_event.m_parms[192]       |
  726.                                                  (hci_event.m_parms[193] << 8) |
  727.                                                  (hci_event.m_parms[194] << 16)|
  728.                                                  (hci_event.m_parms[195] << 24);
  729.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_EV3] =  hci_event.m_parms[224]       |
  730.                                                  (hci_event.m_parms[225] << 8) |
  731.                                                  (hci_event.m_parms[226] << 16)|
  732.                                                  (hci_event.m_parms[227] << 24);
  733.     return true;
  734. }
  735. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  736. void CBTHCIFT::Compose_Read_EDR_TX_RX_Count_HCI_Command(BT_HCI_COMMAND &hci_cmd)
  737. {
  738.     hci_cmd.m_opcode = 0xFCDA;
  739.     hci_cmd.m_len     = 0;
  740.     Reset_HCI_Command(hci_cmd);
  741. }
  742. //---------------------------------------------------------------------------
  743. bool CBTHCIFT::DeCompose_Read_EDR_TX_RX_Count_HCI_Event(BT_HCI_EVENT hci_event, S_BT_PKT_MONITOR_TXRX_CNF &monitor)
  744. {
  745.     // 04,0E,94,01,DA,FC,00
  746.     if ((0xDA != hci_event.m_parms[1]) ||
  747.         (0xFC != hci_event.m_parms[2]) ||
  748.         (0x00 != hci_event.m_parms[3])
  749.        )
  750.     {
  751.         return false;
  752.     }
  753.     // TX
  754.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_2DH1] = hci_event.m_parms[4]        |
  755.                                                  (hci_event.m_parms[5] << 8)  |
  756.                                                  (hci_event.m_parms[6] << 16) |
  757.                                                  (hci_event.m_parms[7] << 24);
  758.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_2EV3] = hci_event.m_parms[8]         |
  759.                                                  (hci_event.m_parms[9]  << 8)  |
  760.                                                  (hci_event.m_parms[10] << 16) |
  761.                                                  (hci_event.m_parms[11] << 24);
  762.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_3EV3] = hci_event.m_parms[12]        |
  763.                                                  (hci_event.m_parms[13] << 8)  |
  764.                                                  (hci_event.m_parms[14] << 16) |
  765.                                                  (hci_event.m_parms[15] << 24);
  766.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_3DH1] = hci_event.m_parms[16]        |
  767.                                                  (hci_event.m_parms[17] <<  8) |
  768.                                                  (hci_event.m_parms[18] << 16) |
  769.                                                  (hci_event.m_parms[19] << 24);
  770.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_2DH3] = hci_event.m_parms[20]         |
  771.                                                  (hci_event.m_parms[21] << 8)  |
  772.                                                  (hci_event.m_parms[22] << 16) |
  773.                                                  (hci_event.m_parms[23] << 24);
  774.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_3DH3] = hci_event.m_parms[24]        |
  775.                                                  (hci_event.m_parms[25] << 8)  |
  776.                                                  (hci_event.m_parms[26] << 16) |
  777.                                                  (hci_event.m_parms[27] << 24);
  778.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_2EV5] = hci_event.m_parms[28]         |
  779.                                                  (hci_event.m_parms[29] << 8)  |
  780.                                                  (hci_event.m_parms[30] << 16) |
  781.                                                  (hci_event.m_parms[31] << 24);
  782.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_3EV5] = hci_event.m_parms[32]        |
  783.                                                  (hci_event.m_parms[33] << 8)  |
  784.                                                  (hci_event.m_parms[34] << 16) |
  785.                                                  (hci_event.m_parms[35] << 24);
  786.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_2DH5] = hci_event.m_parms[36]        |
  787.                                                  (hci_event.m_parms[37] << 8)  |
  788.                                                  (hci_event.m_parms[38] << 16) |
  789.                                                  (hci_event.m_parms[39] << 24);
  790.     monitor.ui_tx_pkt_count[BT_PACKET_IDX_3DH5] = hci_event.m_parms[40]        |
  791.                                                  (hci_event.m_parms[41] << 8)  |
  792.                                                  (hci_event.m_parms[42] << 16) |
  793.                                                  (hci_event.m_parms[43] << 24);
  794.     // RX
  795.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_2DH1] = hci_event.m_parms[64]        |
  796.                                                  (hci_event.m_parms[65] << 8)  |
  797.                                                  (hci_event.m_parms[66] << 16) |
  798.                                                  (hci_event.m_parms[67] << 24);
  799.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_2EV3] = hci_event.m_parms[68]         |
  800.                                                  (hci_event.m_parms[69]  << 8)  |
  801.                                                  (hci_event.m_parms[70] << 16) |
  802.                                                  (hci_event.m_parms[71] << 24);
  803.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_3EV3] = hci_event.m_parms[72]        |
  804.                                                  (hci_event.m_parms[73] << 8)  |
  805.                                                  (hci_event.m_parms[74] << 16) |
  806.                                                  (hci_event.m_parms[75] << 24);
  807.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_3DH1] = hci_event.m_parms[76]        |
  808.                                                  (hci_event.m_parms[77] <<  8) |
  809.                                                  (hci_event.m_parms[78] << 16) |
  810.                                                  (hci_event.m_parms[79] << 24);
  811.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_2DH3] = hci_event.m_parms[80]         |
  812.                                                  (hci_event.m_parms[81] << 8)  |
  813.                                                  (hci_event.m_parms[82] << 16) |
  814.                                                  (hci_event.m_parms[83] << 24);
  815.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_3DH3] = hci_event.m_parms[84]        |
  816.                                                  (hci_event.m_parms[85] << 8)  |
  817.                                                  (hci_event.m_parms[86] << 16) |
  818.                                                  (hci_event.m_parms[87] << 24);
  819.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_2EV5] = hci_event.m_parms[88]         |
  820.                                                  (hci_event.m_parms[89] << 8)  |
  821.                                                  (hci_event.m_parms[90] << 16) |
  822.                                                  (hci_event.m_parms[91] << 24);
  823.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_3EV5] = hci_event.m_parms[92]        |
  824.                                                  (hci_event.m_parms[93] << 8)  |
  825.                                                  (hci_event.m_parms[94] << 16) |
  826.                                                  (hci_event.m_parms[95] << 24);
  827.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_2DH5] = hci_event.m_parms[96]        |
  828.                                                  (hci_event.m_parms[97] << 8)  |
  829.                                                  (hci_event.m_parms[98] << 16) |
  830.                                                  (hci_event.m_parms[99] << 24);
  831.     monitor.ui_rx_pkt_count[BT_PACKET_IDX_3DH5] = hci_event.m_parms[100]        |
  832.                                                  (hci_event.m_parms[101] << 8)  |
  833.                                                  (hci_event.m_parms[102] << 16) |
  834.                                                  (hci_event.m_parms[103] << 24);
  835.     return true;
  836. }