Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. ### HEADER ##############################################################################
  2. #
  3. # @name synopsis_smp
  4. # @grp p2p
  5. # @sgrp jw
  6. # @type f
  7. # @role peripheral / central
  8. # @feat 39-0201
  9. # @brief Just works initiator
  10. # @param no specific
  11. # @time 2
  12. #
  13. ### END ##################################################################################
  14. ##########################################################################################
  15. # IMPORTS
  16. ##########################################################################################
  17. #hci and fe defines
  18. from api.hci.hci_def import *
  19. from api.fe.fe_def import *
  20. from api.fe.fe import *
  21. #title print functions
  22. from co.wvt_hdr import *
  23. #multiple objects functions
  24. from tc_utils.bt_utils import *
  25.  
  26. ##########################################################################################
  27. ##@brief SMP Test Case for Valid Behavior : Just Works STK generation method 01.
  28. ##########################################################################################
  29. class synopsis_smp:
  30.  
  31.  
  32. ######################################################################################
  33. ##@brief Class Constructor - Initialization of Test Case.
  34. #
  35. # @param env Environment with device instances and log
  36. ######################################################################################
  37. def __init__(self, env):
  38. #at least one device needed
  39. assert(env.devs != [])
  40.  
  41. #TC name for titles
  42. self.tcname = '['+self.__class__.__name__+']'
  43.  
  44. #init log
  45. self.logfile = None
  46.  
  47. #recover the device instance - the 1st in environment
  48. self.dph = env.devs[0]
  49.  
  50. #For final print out checks ok per device
  51. self.nbdevs = 2
  52.  
  53. #log file descriptor
  54. if env.dirpath != None: self.logfile= (env.dirpath+'log_'+self.tcname+'.txt')
  55. self.log = wvt_log(self.logfile, 'a')
  56.  
  57. #change log for device
  58. self.dph.set_log(self.log)
  59.  
  60. #reset device checks_ok
  61. self.dph.checks_ok = 0
  62.  
  63. #INIT DEVICE PARAMS FOR TEST
  64.  
  65. #Peripheral 0-----------------------------------------------------------------------
  66. self.dph.adv_intv_min = 160
  67. self.dph.adv_intv_max = 160
  68. self.dph.adv_type = ADVCUND
  69. self.dph.adv_ch_map = ADV3789
  70. self.dph.adv_pol = ADVALL
  71.  
  72. self.dph.adv_data = '\x0A\x09\x52\x57\x20\x42\x4C\x45\x20\x49\x50\x03\xFF\x00\x60'
  73. self.dph.le_scanrsp_data = '\x03\x08\x52\x57\x05\x14\x20\x00\x20\x01'
  74.  
  75.  
  76. ######################################################################################
  77. ##@brief TC Scenario
  78. ######################################################################################
  79. def run(self):
  80. #title of TC
  81. H1(self.log, self.tcname)
  82. self.dph.fe_set_config(role = gap_role.GAP_PERIPHERAL)
  83.  
  84.  
  85. self.dph.fe_start_advertise(adv_type = gapm.op.GAPM_ADV_UNDIRECT)
  86.  
  87. firstConnection = True
  88. firstBonding = False
  89. while True:
  90. lrx = self.dph.recv_evt()
  91.  
  92. if lrx[0] == gapc.GAPC_CONNECTION_REQ_IND:
  93. conidx = lrx[3]
  94. conhdl = lrx[4]
  95. if firstConnection:
  96. auth = 0
  97. firstConnection = False
  98. else:
  99. auth = 1
  100.  
  101. self.dph.fe.gapc.h2f_connection_cfm(conidx, auth)
  102.  
  103. if lrx[0] == gapc.GAPC_DISCONNECT_IND:
  104. import time
  105. time.sleep(2)
  106. self.dph.fe_start_advertise(adv_type = gapm.op.GAPM_ADV_UNDIRECT)
  107.  
  108. if lrx[0] == gapc.GAPC_BOND_REQ_IND:
  109. if lrx[4] == gapc_bond.GAPC_PAIRING_REQ:
  110. if firstBonding:
  111. firstBonding = False
  112. auth = gap_auth.GAP_AUTH_REQ_NO_MITM_NO_BOND
  113. else:
  114. auth = gap_auth.GAP_AUTH_REQ_NO_MITM_BOND
  115. self.dph.fe.gapc.h2f_bond_cfm_pairing_accept(conidx, OOB_NONE, gap_io_cap.GAP_IO_CAP_NO_INPUT_NO_OUTPUT, auth, 16, KEY_ENC, KEY_ENC, SEC_NONE)
  116. if lrx[4] == gapc_bond.GAPC_TK_EXCH:
  117. tk_ct = self.dph.rand_ltk_gen()
  118. self.dph.fe.gapc.h2f_bond_cfm_tk_exch_accept(conidx, tk_ct)
  119. if lrx[4] == gapc_bond.GAPC_LTK_EXCH:
  120. ltk = self.dph.rand_ltk_gen()
  121. randnb = self.dph.rand_ltk_gen()[0:8]
  122. ediv = 0x1234
  123. self.dph.fe.gapc.h2f_bond_cfm_ltk_exch(conidx, ltk, ediv, randnb, 16)
  124. print lrx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement