def __init__(self): self.sec_keyset = driver.ble_gap_sec_keyset_t() keys_own = driver.ble_gap_sec_keys_t() self.sec_keyset.keys_own = keys_own keys_peer = driver.ble_gap_sec_keys_t() keys_peer.p_enc_key = driver.ble_gap_enc_key_t() keys_peer.p_enc_key.enc_info = driver.ble_gap_enc_info_t() keys_peer.p_enc_key.master_id = driver.ble_gap_master_id_t() keys_peer.p_id_key = driver.ble_gap_id_key_t() keys_peer.p_id_key.id_info = driver.ble_gap_irk_t() keys_peer.p_id_key.id_addr_info = driver.ble_gap_addr_t() # keys_peer.p_sign_key = driver.ble_gap_sign_info_t() # keys_peer.p_pk = driver.ble_gap_lesc_p256_pk_t() self.sec_keyset.keys_peer = keys_peer
def ble_gap_encrypt(self, conn_handle, ediv, rand, ltk, lesc, auth): # TODO: Clean up # assert isinstance(sec_params, (BLEGapSecParams, NoneType)), 'Invalid argument type' # assert isinstance(sec_keyset, BLEGapSecKeyset), 'Invalid argument type' # print 'ediv %r' % master_id.ediv # print 'rand %r' % util.uint8_array_to_list(master_id.rand, 8) # print 'ltk %r' % util.uint8_array_to_list(enc_info.ltk, enc_info.ltk_len) # print 'len %r' % enc_info.ltk_len # print 'lesc %r' % enc_info.lesc # print 'auth %r' % enc_info.auth rand_arr = util.list_to_uint8_array(rand) ltk_arr = util.list_to_uint8_array(ltk) master_id = driver.ble_gap_master_id_t() master_id.ediv = ediv master_id.rand = rand_arr.cast() enc_info = driver.ble_gap_enc_info_t() enc_info.ltk_len = len(ltk) enc_info.ltk = ltk_arr.cast() enc_info.lesc = lesc enc_info.auth = auth return driver.sd_ble_gap_encrypt(self.rpc_adapter, conn_handle, master_id, enc_info)
def to_c(self): rand_array = util.list_to_uint8_array(self.rand) master_id = driver.ble_gap_master_id_t() master_id.ediv = self.ediv master_id.rand = rand_array.cast() return master_id