How to use the ledgerblue.comm.Dongle function in ledgerblue

To help you get started, we’ve selected a few ledgerblue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / blue-loader-python / experimental / bluepy / commBLE.py View on Github external
WRITE_CHARACTERISTICS_UUID = "D973F2E2-B19E-11E2-9E96-0800200C9A66"
NOTIFY_CHARACTERISTICS_UUID = "D973F2E1-B19E-11E2-9E96-0800200C9A66"
CLIENT_CHARACTERISTICS_CONFIG_DESCRIPTOR_UUID = "00002902-0000-1000-8000-00805f9b34fb"
ENABLE_NOTIFICATION = "0100".decode('hex')
DEFAULT_BLE_CHUNK = 20
BLE_NOTIFICATION_TIMEOUT = 5.0

class BLEDongleDelegate(btle.DefaultDelegate):
	def __init__(self, dongle):
		btle.DefaultDelegate.__init__(self)
		self.dongle = dongle

	def handleNotification(self, cHandle, data):		
		self.dongle.result += bytearray(data)

class BLEDongle(Dongle):

	# Must be called with the Client Characteristics Configuration descriptor handle as bluepy fails to retrieve it
	# From gatttools
	# [device mac][LE]> char-desc
  # handle: 0x000f, uuid: 00002902-0000-1000-8000-00805f9b34fb
	def __init__(self, bleAddress, configDescriptor, debug=False):
		self.device = btle.Peripheral(bleAddress)		
		self.device.setDelegate(BLEDongleDelegate(self))
		self.service = self.device.getServiceByUUID(SERVICE_UUID)
		self.writeCharacteristic = self.service.getCharacteristics(forUUID=WRITE_CHARACTERISTICS_UUID)[0]
		self.device.writeCharacteristic(configDescriptor, ENABLE_NOTIFICATION, withResponse=True)
		self.debug = debug
		self.opened = True

	def exchange(self, apdu, timeout=20000):
		if self.debug: