Esempio n. 1
0
	def readByType(self,packet):
		if self.getStage() == BLEMitmStage.ACTIVE_MITM:
			io.info("Read By Type Request (from master) : startHandle = "+hex(packet.startHandle)+
				" / endHandle = "+hex(packet.endHandle)+" / uuid = "+hex(packet.uuid))
			io.info("Redirecting to slave ...")
			self.a2sEmitter.sendp(ble.BLEReadByTypeRequest( startHandle=packet.startHandle,
										endHandle=packet.endHandle,
										uuid=packet.uuid))
Esempio n. 2
0
    def characteristicsDiscovery(self, startHandle=0x0001, endHandle=0xFFFF):
        characteristicDeclarationUUID = ble.UUID(
            name="Characteristic Declaration").UUID16
        start, end, continuer = startHandle, endHandle, True
        characteristics = []
        while continuer:
            request = ble.BLEReadByTypeRequest(
                startHandle=start,
                endHandle=end,
                uuid=characteristicDeclarationUUID)
            self.emitter.sendp(request)

            p = self.receive([ble.BLEReadByTypeResponse, ble.BLEErrorResponse],
                             retry=request)

            if isinstance(p, ble.BLEReadByTypeResponse):

                for i in p.attributes:

                    characteristicDeclaration = ble.CharacteristicDeclaration(
                        data=i['value'][::-1])
                    characteristic = {
                        "declarationHandle": i["attributeHandle"],
                        "valueHandle": characteristicDeclaration.valueHandle,
                        "uuid": characteristicDeclaration.UUID,
                        "permissionsFlag":
                        characteristicDeclaration.permissionsFlag,
                        "value": b""
                    }
                    if "Read" in characteristicDeclaration.permissionsFlag:
                        request = ble.BLEReadRequest(
                            handle=characteristicDeclaration.valueHandle)
                        self.emitter.sendp(request)
                        p = self.receive(
                            [ble.BLEReadResponse, ble.BLEErrorResponse],
                            retry=request)
                        if isinstance(p, ble.BLEReadResponse):
                            characteristic["value"] = p.value

                    characteristics.append(characteristic)
                    start = i["attributeHandle"]

                start = start + 1
                continuer = (start <= 0xFFFF)

            elif isinstance(p, ble.BLEErrorResponse):
                continuer = False
            else:
                pass
        return characteristics