Merge: hardware abstraction layer for ARM
This commit is contained in:
200 files changed
+15503
-3576
No files matched your search
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# Option to build the firmware for the Proxmark3/5. This will include the armsrc and bootrom directories.
|
||||
option(BUILD_FIRMWARE "Build the firmware for the Proxmark3/5" ON)
|
||||
|
||||
# If building for pm3 device, not client, the compiler will be arm-none-eabi-gcc, so the test program will not compile.
|
||||
# This is a workaround to prevent CMake from trying to compile the test program,
|
||||
# which will fail because the compiler is not for the host system.
|
||||
if (BUILD_FIRMWARE)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/tools/FixCompileTest.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/tools/ToolchainForArm.cmake)
|
||||
endif ()
|
||||
|
||||
# Project name and languages
|
||||
project(Proxmark3 C CXX ASM)
|
||||
|
||||
# add subdirectories, which will contain their own CMakeLists.txt files
|
||||
if (BUILD_FIRMWARE)
|
||||
add_subdirectory(armsrc)
|
||||
add_subdirectory(bootrom)
|
||||
else ()
|
||||
add_subdirectory(client)
|
||||
endif ()
|
||||
@@ -0,0 +1,40 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# See LICENSE.txt for the text of the license.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(PLATFORM),PM5)
|
||||
|
||||
ARMLIB_EXPORT_DEFS = -DCHIP_AT32F435_37 -DAT32F435RGT7 -DUSE_STDPERIPH_DRIVER -DAT_START_F435_V1 -DUSBD_SUPPORT_WINUSB=1
|
||||
ARMLIB_EXPORT_DEFS += -DCRM_MODULE_ENABLED -DMISC_MODULE_ENABLED -DGPIO_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DUSB_MODULE_ENABLED -DQSPI_MODULE_ENABLED -DTMR_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DERTC_MODULE_ENABLED -DPWC_MODULE_ENABLED -DSPI_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DI2C_MODULE_ENABLED -DDMA_MODULE_ENABLED -DADC_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DUSART_MODULE_ENABLED -DEXINT_MODULE_ENABLED -DSCFG_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DFLASH_MODULE_ENABLED -DCRC_MODULE_ENABLED -DWDT_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DWWDT_MODULE_ENABLED -DCAN_MODULE_ENABLED -DDAC_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DDEBUG_MODULE_ENABLED -DDVP_MODULE_ENABLED -DEDMA_MODULE_ENABLED
|
||||
ARMLIB_EXPORT_DEFS += -DSDIO_MODULE_ENABLED -DACC_MODULE_ENABLED
|
||||
|
||||
ARMLIB_EXPORT_INCLUDES = -I.
|
||||
ARMLIB_EXPORT_INCLUDES += -isystem ../armlib/at32_sys -isystem ../armlib/at32_sys/cmsis/cm4/core_support
|
||||
ARMLIB_EXPORT_INCLUDES += -isystem ../armlib/at32_sys/cmsis/cm4/device_support -isystem ../armlib/at32_sys/drivers/inc
|
||||
ARMLIB_EXPORT_INCLUDES += -isystem ../armlib/at32_usb -isystem ../armlib/at32_usb/usb_drivers/inc -isystem ../armlib/at32_usb/usbd_class/cdc
|
||||
ARMLIB_EXPORT_INCLUDES += -isystem ../armlib/at32_i2c
|
||||
|
||||
ARMLIB_EXPORT_CFLAGS = $(ARMLIB_EXPORT_DEFS) $(ARMLIB_EXPORT_INCLUDES)
|
||||
|
||||
ARMLIB_EXPORT_LIBNAME = libarmlib.a
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,97 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# See LICENSE.txt for the text of the license.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(PLATFORM),PM5)
|
||||
|
||||
# Flags + Inc
|
||||
include ../armlib/Exports.mk
|
||||
|
||||
# Toolchain + dirs
|
||||
include ../common_arm/Makefile.common
|
||||
|
||||
# Allow standalone invocation when parent make doesn't export toolchain vars.
|
||||
CROSS ?= arm-none-eabi-
|
||||
CROSS_CC ?= $(CROSS)gcc
|
||||
CROSS_CFLAGS ?=
|
||||
CROSS_AR ?= $(CROSS)ar
|
||||
OBJDIR ?= obj
|
||||
|
||||
ARMLIBSRC = \
|
||||
../armlib/at32_sys/cmsis/cm4/device_support/system_at32f435_437.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_crm.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_misc.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_gpio.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_usb.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_qspi.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_tmr.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_ertc.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_pwc.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_spi.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_i2c.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_dma.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_adc.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_usart.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_exint.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_scfg.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_flash.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_crc.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_wdt.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_wwdt.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_can.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_dac.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_debug.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_dvp.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_edma.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_sdio.c \
|
||||
../armlib/at32_sys/drivers/src/at32f435_437_acc.c \
|
||||
../armlib/at32_usb/usb_drivers/src/usb_core.c \
|
||||
../armlib/at32_usb/usb_drivers/src/usbd_core.c \
|
||||
../armlib/at32_usb/usb_drivers/src/usbd_int.c \
|
||||
../armlib/at32_usb/usb_drivers/src/usbd_sdr.c \
|
||||
../armlib/at32_usb/usbd_class/cdc/cdc_class.c \
|
||||
../armlib/at32_i2c/at32f435_437_i2c_app.c
|
||||
|
||||
ARMLIB = $(OBJDIR)/$(ARMLIB_EXPORT_LIBNAME)
|
||||
ARMLIB_OBJ_FROM_SRC = $(OBJDIR)/armlib_$(subst /,_,$(patsubst ../armlib/%.c,%,$(1))).o
|
||||
ARMLIB_OBJ = $(foreach src,$(ARMLIBSRC),$(call ARMLIB_OBJ_FROM_SRC,$(src)))
|
||||
ARMLIB_DEP = $(ARMLIB_OBJ:.o=.d)
|
||||
.DEFAULT_GOAL := $(ARMLIB)
|
||||
|
||||
# TODO Artery's library has many warnings, which we can only ignore for now, unfortunately.
|
||||
ARMLIB_PRIVATE_CFLAGS = -mcpu=cortex-m4 -Wno-missing-prototypes -Wno-missing-declarations
|
||||
ARMLIB_CFLAGS = $(ARMLIB_EXPORT_CFLAGS) $(ARMLIB_PRIVATE_CFLAGS)
|
||||
|
||||
define ARMLIB_COMPILE_RULE
|
||||
$(2): $(1) $(INCLUDES) | $(OBJDIR)
|
||||
$$(info [-] CC $$(notdir $(1)))
|
||||
$$(Q)$$(CROSS_CC) $$(CROSS_CFLAGS) $$(ARMLIB_CFLAGS) -MMD -MP -MF $(2:.o=.d) -mthumb -c -o $(2) $(1)
|
||||
endef
|
||||
|
||||
define ARMLIB_REGISTER_RULES
|
||||
$(foreach src,$(ARMLIBSRC),$(eval $(call ARMLIB_COMPILE_RULE,$(src),$(call ARMLIB_OBJ_FROM_SRC,$(src)))))
|
||||
endef
|
||||
|
||||
$(OBJDIR):
|
||||
$(Q)mkdir -p $@
|
||||
|
||||
$(ARMLIB): $(ARMLIB_OBJ) | $(OBJDIR)
|
||||
$(info [-] AR $@)
|
||||
$(Q)$(CROSS_AR) rcs $@ $^
|
||||
|
||||
$(call ARMLIB_REGISTER_RULES)
|
||||
-include $(ARMLIB_DEP)
|
||||
|
||||
endif
|
||||
@@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_can.h"
|
||||
#include "at32f435_437_crm.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_crc.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_dac.h"
|
||||
#include "at32f435_437_crm.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_debug.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_dvp.h"
|
||||
#include "at32f435_437_crm.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_edma.h"
|
||||
#include "at32f435_437_crm.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_sdio.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_crm.h"
|
||||
#include "at32f435_437_tmr.h"
|
||||
#include "at32f435_437_crm.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_wdt.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_wwdt.h"
|
||||
#include "at32f435_437_crm.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "at32f435_437_conf.h"
|
||||
#include "at32f435_437_xmc.h"
|
||||
|
||||
/** @addtogroup AT32F435_437_periph_driver
|
||||
* @{
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
#include "stdio.h"
|
||||
#include "usbd_core.h"
|
||||
#include "usb_cdc_desc.h"
|
||||
|
||||
|
||||
static usbd_desc_t *get_device_descriptor(void);
|
||||
|
||||
static usbd_desc_t *get_device_qualifier(void);
|
||||
|
||||
static usbd_desc_t *get_device_configuration(void);
|
||||
|
||||
static usbd_desc_t *get_device_other_speed(void);
|
||||
|
||||
static usbd_desc_t *get_device_lang_id(void);
|
||||
|
||||
static usbd_desc_t *get_device_manufacturer_string(void);
|
||||
|
||||
static usbd_desc_t *get_device_product_string(void);
|
||||
|
||||
static usbd_desc_t *get_device_serial_string(void);
|
||||
|
||||
static usbd_desc_t *get_device_interface_string(void);
|
||||
|
||||
static usbd_desc_t *get_device_config_string(void);
|
||||
|
||||
static usbd_desc_t *get_winusb_os_string(void);
|
||||
|
||||
/**
|
||||
* @brief device descriptor handler structure
|
||||
*/
|
||||
usbd_desc_handler cdc_desc_handler =
|
||||
{
|
||||
get_device_descriptor,
|
||||
get_device_qualifier,
|
||||
get_device_configuration,
|
||||
get_device_other_speed,
|
||||
get_device_lang_id,
|
||||
// ---
|
||||
get_device_manufacturer_string,
|
||||
get_device_product_string,
|
||||
get_device_serial_string,
|
||||
get_device_interface_string,
|
||||
get_device_config_string,
|
||||
// ---
|
||||
get_winusb_os_string,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* device descriptor */
|
||||
static usbd_desc_t device_descriptor =
|
||||
{
|
||||
sizeof(devDescriptor),
|
||||
(uint8_t *) devDescriptor
|
||||
};
|
||||
|
||||
/* config descriptor */
|
||||
static usbd_desc_t config_descriptor =
|
||||
{
|
||||
sizeof(cfgDescriptor),
|
||||
(uint8_t *) cfgDescriptor
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
sizeof(StrLanguageCodes),
|
||||
(uint8_t *) StrLanguageCodes
|
||||
};
|
||||
|
||||
/* serial descriptor */
|
||||
static usbd_desc_t serial_descriptor =
|
||||
{
|
||||
sizeof(StrSerialNumber),
|
||||
(uint8_t *) StrSerialNumber
|
||||
};
|
||||
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_descriptor(void) {
|
||||
return &device_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_qualifier(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_configuration(void) {
|
||||
return &config_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_other_speed(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_lang_id(void) {
|
||||
return &langid_descriptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_manufacturer_string(void) {
|
||||
vp_desc.length = StrManufacturer[0];
|
||||
vp_desc.descriptor = (uint8_t *) StrManufacturer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_product_string(void) {
|
||||
vp_desc.length = StrProduct[0];
|
||||
vp_desc.descriptor = (uint8_t *) StrProduct;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_serial_string(void) {
|
||||
return &serial_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_interface_string(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_device_config_string(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
static usbd_desc_t *get_winusb_os_string(void) {
|
||||
vp_desc.length = StrMS_OSDescriptor[0];
|
||||
vp_desc.descriptor = (uint8_t *) StrMS_OSDescriptor;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
if (PM5 AND NOT TARGET pm5_at32_armlib)
|
||||
add_library(pm5_at32_armlib STATIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/cmsis/cm4/device_support/system_at32f435_437.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_crm.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_misc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_gpio.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_usb.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_qspi.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_tmr.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_ertc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_pwc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_spi.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_i2c.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_dma.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_adc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_usart.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_exint.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_scfg.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_flash.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_crc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_wdt.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_wwdt.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_can.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_dac.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_debug.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_dvp.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_edma.c
|
||||
# ${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_emac.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_sdio.c
|
||||
# ${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_xmc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_acc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usb_core.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usbd_core.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usbd_int.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usbd_sdr.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usbd_class/cdc/cdc_class.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_i2c/at32f435_437_i2c_app.c
|
||||
)
|
||||
|
||||
target_compile_options(pm5_at32_armlib
|
||||
PRIVATE ${CROSS_CFLAGS}
|
||||
PUBLIC -mcpu=cortex-m4 -Wno-missing-prototypes -Wno-missing-declarations
|
||||
)
|
||||
target_compile_definitions(pm5_at32_armlib PUBLIC
|
||||
AT32F435RGT7
|
||||
USE_STDPERIPH_DRIVER
|
||||
AT_START_F435_V1
|
||||
CRM_MODULE_ENABLED
|
||||
MISC_MODULE_ENABLED
|
||||
GPIO_MODULE_ENABLED
|
||||
USB_MODULE_ENABLED
|
||||
QSPI_MODULE_ENABLED
|
||||
TMR_MODULE_ENABLED
|
||||
ERTC_MODULE_ENABLED
|
||||
PWC_MODULE_ENABLED
|
||||
SPI_MODULE_ENABLED
|
||||
I2C_MODULE_ENABLED
|
||||
DMA_MODULE_ENABLED
|
||||
ADC_MODULE_ENABLED
|
||||
USART_MODULE_ENABLED
|
||||
EXINT_MODULE_ENABLED
|
||||
SCFG_MODULE_ENABLED
|
||||
FLASH_MODULE_ENABLED
|
||||
CRC_MODULE_ENABLED
|
||||
WDT_MODULE_ENABLED
|
||||
WWDT_MODULE_ENABLED
|
||||
CAN_MODULE_ENABLED
|
||||
DAC_MODULE_ENABLED
|
||||
DEBUG_MODULE_ENABLED
|
||||
DVP_MODULE_ENABLED
|
||||
EDMA_MODULE_ENABLED
|
||||
# EMAC_MODULE_ENABLED
|
||||
SDIO_MODULE_ENABLED
|
||||
# XMC_MODULE_ENABLED
|
||||
ACC_MODULE_ENABLED
|
||||
USBD_SUPPORT_WINUSB=1
|
||||
)
|
||||
target_include_directories(pm5_at32_armlib PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/cmsis/cm4/core_support
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/cmsis/cm4/device_support
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/inc
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/inc
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usbd_class/cdc
|
||||
${CMAKE_CURRENT_LIST_DIR}/at32_i2c
|
||||
)
|
||||
set_property(TARGET pm5_at32_armlib PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif ()
|
||||
@@ -0,0 +1,556 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# Fix error when 'compile a simple test program.'
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../tools/FixCompileTest.cmake)
|
||||
|
||||
# Ensure direct armsrc builds also select ARM cross-compilers.
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../tools/ToolchainForArm.cmake)
|
||||
|
||||
# Set variables needs before the project defining.
|
||||
project(fullimage C CXX ASM)
|
||||
|
||||
# Compile tools for project build step, preprocessor and postprocessor
|
||||
# So this compiler need run on host platform
|
||||
find_program(C_COMPILER_HOST gcc)
|
||||
if (NOT C_COMPILER_HOST)
|
||||
message(FATAL_ERROR "GCC for tools build on host is no found, Plz give the cmake arg like 'cmake -DC_COMPILER_HOST=/your path/'")
|
||||
endif ()
|
||||
|
||||
# Genarate version info by mkversion script
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../tools/MKVersionScript.cmake)
|
||||
|
||||
# Import options for standalone mode
|
||||
# Used 'STANDALONE_REQ_DEFS' & 'STANDALONE_PLATFORM_DEFS' variables.
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Standalone/StandAloneOption.cmake)
|
||||
|
||||
# Hardware abstraction layer for ARM platform.
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../common_arm/Hal.cmake)
|
||||
|
||||
# Setup FPGA Compress.
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../tools/FpgaCompress.cmake)
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
set(APP_CFLAGS ${PLATFORM_DEFS} -ffunction-sections -fdata-sections)
|
||||
|
||||
set(INC_DIRS
|
||||
../include
|
||||
../common_arm
|
||||
../common_arm/rssi
|
||||
../common_arm/ticks
|
||||
../common_arm/usb
|
||||
../common_arm/flash_data
|
||||
../common_arm/flash_code
|
||||
../common_arm/gpio
|
||||
../common_arm/sys
|
||||
../common_arm/fpga
|
||||
../common_arm/wdt
|
||||
../common_fpga
|
||||
../common
|
||||
../common/lz4
|
||||
.
|
||||
)
|
||||
|
||||
# Hal for platform
|
||||
if (PM5)
|
||||
set(SRC_TICKS ../common_arm/ticks/ticks_hw_at32.c)
|
||||
set(SRC_GPIO ../common_arm/gpio/gpio_hw_at32.c)
|
||||
set(SRC_WDT ../common_arm/wdt/wdt_hw_at32.c)
|
||||
set(SRC_RSSI ../common_arm/rssi/rssi_hw_at32.c)
|
||||
set(SRC_SYS ../common_arm/sys/sys_hw_at32.c)
|
||||
set(SRC_FLASH_DATA ../common_arm/flash_data/flashmem_hw_at32.c)
|
||||
set(SRC_USB_CDC ../common_arm/usb/usb_cdc_at32.c)
|
||||
set(SRC_FPGA ../common_arm/fpga/fpga_hw_at32.c ../common_arm/fpga/fpga_gw_jtag.c)
|
||||
set(LDSCRIPT ${CMAKE_CURRENT_LIST_DIR}/ldscript.osimage.at32)
|
||||
else ()
|
||||
set(SRC_TICKS ../common_arm/ticks/ticks_hw_at91.c)
|
||||
set(SRC_GPIO ../common_arm/gpio/gpio_hw_at91.c)
|
||||
set(SRC_WDT ../common_arm/wdt/wdt_hw_at91.c)
|
||||
set(SRC_RSSI ../common_arm/rssi/rssi_hw_at91.c)
|
||||
set(SRC_SYS ../common_arm/sys/sys_hw_at91.c)
|
||||
set(SRC_FLASH_DATA ../common_arm/flash_data/flashmem_hw_at91.c)
|
||||
set(SRC_USB_CDC ../common_arm/usb/usb_cdc_at91.c)
|
||||
set(SRC_FPGA ../common_arm/fpga/fpga_hw_at91.c)
|
||||
set(LDSCRIPT ${CMAKE_CURRENT_LIST_DIR}/ldscript.osimage.at91)
|
||||
endif ()
|
||||
|
||||
set(SRC_LF
|
||||
lfops.c
|
||||
lfsampling.c
|
||||
pcf7931.c
|
||||
../common/lfdemod.c
|
||||
lfadc.c
|
||||
)
|
||||
|
||||
set(SRC_HF hfops.c)
|
||||
|
||||
set(SRC_ISO15693
|
||||
iso15693.c
|
||||
../common/iso15693tools.c)
|
||||
|
||||
set(SRC_ISO14443a
|
||||
iso14443a.c
|
||||
secc.c
|
||||
mifareutil.c
|
||||
mifarecmd.c
|
||||
epa.c
|
||||
mifaresim.c
|
||||
sam_common.c
|
||||
sam_mfc.c
|
||||
sam_seos.c
|
||||
sam_sc.c
|
||||
)
|
||||
|
||||
#UNUSED: mifaresniff.c
|
||||
|
||||
set(SRC_ISO14443b iso14443b.c)
|
||||
|
||||
set(SRC_FELICA felica.c felicasim.c)
|
||||
|
||||
set(SRC_CRAPTO1
|
||||
../common/crapto1/crypto1.c
|
||||
desfire_crypto.c
|
||||
mifaredesfire.c
|
||||
../common/mbedtls/des.c
|
||||
../common/mbedtls/aes.c
|
||||
../common/mbedtls/platform_util.c
|
||||
)
|
||||
|
||||
set(SRC_CRC
|
||||
../common/crc.c
|
||||
../common/crc16.c
|
||||
../common/crc32.c)
|
||||
|
||||
set(SRC_ICLASS
|
||||
iclass.c
|
||||
optimized_cipherutils.c
|
||||
optimized_ikeys.c
|
||||
optimized_elite.c
|
||||
optimized_cipher.c
|
||||
sam_picopass.c
|
||||
)
|
||||
|
||||
set(SRC_SEOS
|
||||
seos.c
|
||||
../common/mbedtls/sha1.c
|
||||
../common/mbedtls/sha256.c)
|
||||
|
||||
set(SRC_LEGIC
|
||||
legicrf.c
|
||||
legicrfsim.c
|
||||
../common/legic_prng.c)
|
||||
|
||||
set(SRC_NFCBARCODE thinfilm.c)
|
||||
|
||||
# SRC_BEE = bee.c
|
||||
# set(SRC_BEE bee.c)
|
||||
|
||||
message(STATUS "APP_CFLAGS = ${APP_CFLAGS}")
|
||||
|
||||
# RDV4 or PM5 related hardware support
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_FLASH")
|
||||
set(SRC_FLASH ${SRC_FLASH_DATA} ../common_arm/flash_data/flashmem_core.c)
|
||||
set(SRC_SPIFFS
|
||||
spiffs.c
|
||||
spiffs_cache.c
|
||||
spiffs_check.c
|
||||
spiffs_gc.c
|
||||
spiffs_nucleus.c
|
||||
spiffs_hydrogen.c
|
||||
)
|
||||
else ()
|
||||
set(SRC_FLASH)
|
||||
set(SRC_SPIFFS)
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_SMARTCARD")
|
||||
set(SRC_SMARTCARD i2c.c i2c_direct.c emvsim.c)
|
||||
else ()
|
||||
set(SRC_SMARTCARD)
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_FPC_USART")
|
||||
set(SRC_FPC usart.c)
|
||||
else ()
|
||||
set(SRC_FPC)
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_HITAG")
|
||||
set(SRC_HITAG
|
||||
../common/hitag2/hitag2_crypto.c
|
||||
hitag_common.c
|
||||
hitag2.c
|
||||
hitagS.c
|
||||
hitagu.c
|
||||
hitag2_crack.c
|
||||
)
|
||||
list(APPEND INC_DIRS ../common/hitag2)
|
||||
else ()
|
||||
set(SRC_HITAG)
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_EM4x50")
|
||||
set(SRC_EM4x50
|
||||
em4x50.c
|
||||
../common/bruteforce.c)
|
||||
else ()
|
||||
set(SRC_EM4x50)
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_EM4x70")
|
||||
set(SRC_EM4x70 em4x70.c)
|
||||
else ()
|
||||
set(SRC_EM4x70)
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_LCD")
|
||||
# LCD module is disabled. file name is fonts_disabled.c and LCD_disabled.c
|
||||
# So, if WITH_LCD enable, we need show error for DEV.
|
||||
set(SRC_LCD fonts.c LCD.c)
|
||||
message(FATAL_ERROR "LCD functions is unavailable")
|
||||
else ()
|
||||
set(SRC_LCD)
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_ZX8211")
|
||||
set(SRC_ZX lfzx.c)
|
||||
else ()
|
||||
set(SRC_ZX)
|
||||
endif ()
|
||||
|
||||
# Generic standalone Mode injection of source code
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Standalone/StandAloneSource.cmake)
|
||||
|
||||
# The lz4 source files required for decompressing the fpga config at run time
|
||||
set(SRC_LZ4 ../common/lz4/lz4.c)
|
||||
# Additional defines required to compile lz4
|
||||
set(LZ4_CFLAGS "-DLZ4_MEMORY_USAGE=8" "-DLZ4_HEAPMODE=0")
|
||||
list(APPEND APP_CFLAGS ${LZ4_CFLAGS})
|
||||
# lz4 includes:
|
||||
list(APPEND INC_DIRS ../common/lz4)
|
||||
|
||||
# stdint.h provided locally until GCC 4.5 becomes C99 compliant,
|
||||
# stack-protect , no-pie reduces size on Gentoo Hardened 8.2 gcc
|
||||
list(APPEND APP_CFLAGS -I. -fno-stack-protector -fno-pie)
|
||||
|
||||
# Compile these in thumb mode (small size)
|
||||
set(THUMBSRC
|
||||
start.c
|
||||
${SRC_LCD}
|
||||
${SRC_ISO15693}
|
||||
${SRC_NFCBARCODE}
|
||||
${SRC_LF}
|
||||
${SRC_LZ4}
|
||||
${SRC_LEGIC}
|
||||
${SRC_FLASH}
|
||||
${SRC_SMARTCARD}
|
||||
${SRC_FPC}
|
||||
${SRC_HITAG}
|
||||
${SRC_EM4x50}
|
||||
${SRC_EM4x70}
|
||||
${SRC_SPIFFS}
|
||||
${SRC_HF}
|
||||
${SRC_ISO14443a}
|
||||
${SRC_ISO14443b}
|
||||
${SRC_CRAPTO1}
|
||||
${SRC_ICLASS}
|
||||
${SRC_SEOS}
|
||||
${SRC_EMV}
|
||||
${SRC_CRC}
|
||||
${SRC_FELICA}
|
||||
${SRC_STANDALONE}
|
||||
${SRC_ZX}
|
||||
appmain.c
|
||||
printf.c
|
||||
dbprint.c
|
||||
../common/commonutil.c
|
||||
util.c
|
||||
string.c
|
||||
BigBuf.c
|
||||
${SRC_RSSI}
|
||||
${SRC_TICKS}
|
||||
${SRC_GPIO}
|
||||
${SRC_WDT}
|
||||
${SRC_SYS}
|
||||
../common_arm/rssi/rssi_core.c
|
||||
../common_arm/ticks/ticks_core.c
|
||||
hfsnoop.c
|
||||
../common/generator.c
|
||||
cmac_calc.c
|
||||
cmac_3des.c
|
||||
)
|
||||
|
||||
if (PM5)
|
||||
list(APPEND THUMBSRC startup_at32f435_437.s)
|
||||
list(APPEND THUMBSRC i2c.c)
|
||||
list(APPEND THUMBSRC at32_unit_test.c) # TODO DXL: AT32单元测试代码
|
||||
endif ()
|
||||
|
||||
# These are to be compiled in ARM mode
|
||||
set(ARMSRC
|
||||
../common_arm/fpga/fpga_loader.c
|
||||
../common_arm/fpga/fpga_core.c
|
||||
${SRC_FPGA}
|
||||
../common_arm/usb/usb_read_ng.c
|
||||
../common_arm/usb/usb_cdc_desc.c
|
||||
${SRC_USB_CDC} # AT32 or AT91 usb module, api defs all in usb_cdc.h
|
||||
cmd.c
|
||||
)
|
||||
|
||||
set(VERSIONSRC version_pm3.c fpga_version_info.c)
|
||||
|
||||
# Import common settings for arm build, such as common cflags, etc.
|
||||
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../common_arm/Common.cmake)
|
||||
|
||||
if (PM5)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../armlib/pm5_at32_armlib.cmake)
|
||||
set(LIBS ${LIBS} pm5_at32_armlib)
|
||||
# set(CROSS_LDFLAGS ${CROSS_LDFLAGS} -mfloat-abi=hard -mfpu=fpv4-sp-d16) # TODO DXL: Hardware float core enable?
|
||||
set(CROSS_LDFLAGS ${CROSS_LDFLAGS} -mcpu=cortex-m4)
|
||||
endif ()
|
||||
|
||||
message(STATUS "LDSCRIPT = ${LDSCRIPT}")
|
||||
message(STATUS "CROSS_CFLAGS = ${CROSS_CFLAGS}")
|
||||
|
||||
# =====================================================
|
||||
# FPGA_COMPRESS_EXE -> 可执行文件完整路径(如 /path/to/fpga_compress)
|
||||
# FPGA_BITSTREAMS -> 所有 .bit 文件列表
|
||||
# OBJDIR -> 构建输出目录(如 ${CMAKE_BINARY_DIR}/obj)
|
||||
# APP_CFLAGS -> 编译标志(如 "WITH_COMPRESSION")
|
||||
# THUMBSRC -> 需用 -mthumb 编译的 C 源文件
|
||||
# ARMSRC -> 可用 ARM 模式编译的 C 源文件
|
||||
# ASMSRC -> 汇编文件(.s)
|
||||
# VERSIONSRC -> version_pm3.c和fpga_version_info.c(或其路径)
|
||||
# INC_DIRS -> 包含目录列表
|
||||
# CROSS_CFLAGS -> 通用编译标志(如 -O2, -Wall)
|
||||
# CROSS_LDFLAGS -> 链接标志(如 -nostartfiles)
|
||||
# CMAKE_OBJCOPY -> objcopy 工具路径
|
||||
# LDSCRIPT -> 链接脚本路径
|
||||
# DEFAULT_VERSION_C -> 默认 version 模板文件
|
||||
# =====================================================
|
||||
|
||||
#[[
|
||||
# Firmware and Compressed Data Integration: LZ4-based .data Section Compression Scheme
|
||||
|
||||
1. Compile Firmware
|
||||
- Compile C/C++ source code normally to generate an ELF file with the original .data section.
|
||||
- The linker calculates the .data size and reserves VMA (Virtual Memory Address) space in RAM.
|
||||
|
||||
2. Extract .data Section to Binary
|
||||
- Use objcopy to extract the raw .data section from the ELF, generating an uncompressed binary (e.g., data.bin).
|
||||
|
||||
3. Compress Data and Add Metadata
|
||||
- Compress data.bin using LZ4 (or similar) to produce a compressed stream (e.g., data.bin.z).
|
||||
- Prepend a 4-byte header containing the original .data size (avail_out), used for decompression bounds checking.
|
||||
|
||||
4. Update .data Content in ELF
|
||||
- Use objcopy --update-section to replace the .data section in the ELF with the compressed data (including 4-byte header).
|
||||
- This operation only changes the content and LMA (Load Memory Address) size, not the VMA (RAM address or reserved space).
|
||||
|
||||
5. Generate Final Firmware Image
|
||||
- Convert the updated ELF to .bin or .hex format for flashing.
|
||||
- The .data section in Flash now contains compressed data, significantly reducing firmware size.
|
||||
|
||||
6. Runtime Decompression
|
||||
- At startup, read the .data section start address (__data_src_start__) from Flash.
|
||||
- Read the first 4 bytes to get the original size (avail_out).
|
||||
- Call LZ4_decompress_safe to decompress the data into the RAM region from __data_start__ to __data_end__.
|
||||
- After decompression, .data variables are restored and the program continues.
|
||||
|
||||
# Key Insight: VMA Reservation Mechanism
|
||||
- The linker reserves sufficient RAM space for the .data section at link time, based on the original (uncompressed) size.
|
||||
- Compression only affects storage in Flash (LMA), not the runtime layout in RAM (VMA).
|
||||
- The decompression target is precisely defined by linker symbols __data_start__ and __data_end__, ensuring safety and correctness.
|
||||
]]
|
||||
|
||||
set(OBJDIR ${CMAKE_BINARY_DIR}/obj)
|
||||
set(DEFAULT_VERSION_C ${CMAKE_CURRENT_LIST_DIR}/../common/default_version_pm3.c)
|
||||
|
||||
# ---------------- Output dir ----------------
|
||||
file(MAKE_DIRECTORY ${OBJDIR})
|
||||
get_filename_component(OBJDIR_NAME ${OBJDIR} NAME)
|
||||
|
||||
# ---------------- Output files ----------------
|
||||
get_filename_component(FPGA_VERSION_C ${CMAKE_CURRENT_LIST_DIR}/fpga_version_info.c ABSOLUTE)
|
||||
get_filename_component(FPGA_BIT_Z ${OBJDIR}/fpga_all.bit.z ABSOLUTE)
|
||||
get_filename_component(FPGA_BIT_Z_NAME ${FPGA_BIT_Z} NAME)
|
||||
get_filename_component(FPGA_ALL_O ${OBJDIR}/fpga_all.o ABSOLUTE)
|
||||
get_filename_component(VERSION_PM3_C ${CMAKE_CURRENT_LIST_DIR}/version_pm3.c ABSOLUTE)
|
||||
get_filename_component(STAGE1_ELF ${OBJDIR}/fullimage.stage1.elf ABSOLUTE)
|
||||
get_filename_component(DATA_BIN ${OBJDIR}/fullimage.data.bin ABSOLUTE)
|
||||
get_filename_component(DATA_BIN_Z ${OBJDIR}/fullimage.data.bin.z ABSOLUTE)
|
||||
get_filename_component(FINAL_ELF ${OBJDIR}/fullimage.elf ABSOLUTE)
|
||||
get_filename_component(OUTPUT_S19 ${OBJDIR}/fullimage.s19 ABSOLUTE)
|
||||
get_filename_component(OUTPUT_STAGE1_HEX ${OBJDIR}/fullimage.stage1.hex ABSOLUTE)
|
||||
get_filename_component(OUTPUT_STAGE1_BIN ${OBJDIR}/fullimage.stage1.bin ABSOLUTE)
|
||||
get_filename_component(OUTPUT_FINAL_HEX ${OBJDIR}/fullimage.hex ABSOLUTE)
|
||||
get_filename_component(OUTPUT_FINAL_BIN ${OBJDIR}/fullimage.bin ABSOLUTE)
|
||||
|
||||
# ---------------- 1. Create fpga_version_info.c ----------------
|
||||
set(FPGA_BITSTREAMS_ABSOLUTE_PATH) # Convert all .bit files from relative to absolute path
|
||||
foreach (bitFile ${FPGA_BITSTREAMS})
|
||||
get_filename_component(bitFileAbPath ${bitFile} ABSOLUTE) # get absolute path
|
||||
list(APPEND FPGA_BITSTREAMS_ABSOLUTE_PATH ${bitFileAbPath}) # append to list
|
||||
endforeach ()
|
||||
add_custom_command(
|
||||
OUTPUT ${FPGA_VERSION_C}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(1) fpga_version_info.c"
|
||||
COMMAND ${FPGA_COMPRESS_EXE} -v ${FPGA_BITSTREAMS_ABSOLUTE_PATH} ${FPGA_VERSION_C}
|
||||
DEPENDS ${FPGA_BITSTREAMS_ABSOLUTE_PATH}
|
||||
DEPENDS ${FPGA_COMPRESS_EXE} # Before this step run, we need to build 'fpga_compress' executable
|
||||
COMMAND_EXPAND_LISTS
|
||||
COMMENT "Call the 'fpga_compress' to generate 'fpga_version_info.c' for armsrc"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# ---------------- 2. Create fpga_all.bit.z ----------------
|
||||
# If no fpga pack to arm fw required, skip this.
|
||||
add_custom_command(
|
||||
OUTPUT ${FPGA_BIT_Z}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(2) fpga_all.bit.z"
|
||||
COMMAND ${FPGA_COMPRESS_EXE} ${FPGA_BITSTREAMS_ABSOLUTE_PATH} ${FPGA_BIT_Z}
|
||||
DEPENDS ${FPGA_BITSTREAMS_ABSOLUTE_PATH}
|
||||
DEPENDS ${FPGA_COMPRESS_EXE} # Ensure host tool is built before running it.
|
||||
COMMAND_EXPAND_LISTS
|
||||
COMMENT "Call the 'fpga_compress' to compress fpga bit files, output 'fpga_all.bit.z'"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# ---------------- 3. Create fpga_all.o ----------------
|
||||
# If no fpga pack to arm fw required, skip this step.
|
||||
# The _binary_obj_fpga_all_bit_z_start and _binary_obj_fpga_all_bit_z_end will generate by 'objcopy'
|
||||
# Yes, fpga_all.o contain 'binary<path>_<format>_start', 'binary<path>_<format>_size', 'binary<path>_<format>_end'
|
||||
# More info view: https://stackoverflow.com/questions/60295013/is-it-possible-to-make-a-hardcoding-with-the-help-of-the-command-objcopy
|
||||
# Tips: the binary file put in '.data' section.
|
||||
add_custom_command(
|
||||
OUTPUT ${FPGA_ALL_O}
|
||||
# !!! Important !!! Must enter parent dir of obj output dir, to create fpga_all.o
|
||||
# The objcopy command needs to generate object file for 'fpga_all.bit.z' outside the obj directory.
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(3) fpga_all.o"
|
||||
COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm -I binary -B arm --prefix-sections=fpga_all_bit ${OBJDIR_NAME}/${FPGA_BIT_Z_NAME} ${FPGA_ALL_O}
|
||||
DEPENDS ${FPGA_BIT_Z}
|
||||
COMMENT "Call the objcopy to convert binary to elf file."
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# ---------------- 4. Create version_pm3.c ----------------
|
||||
if (SKIP_FPGA_EMBED) # If pack fpga bit files to arm, we need from step1,2,3 start build, otherwise skip step2,3.
|
||||
set(FPGA_ALL_O_MKVERSION_DEP) # <-- Important, unset it will let this step(4) no DEPENDS with 'FPGA_ALL_O'.
|
||||
else ()
|
||||
set(FPGA_ALL_O_MKVERSION_DEP ${FPGA_ALL_O})
|
||||
endif ()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${VERSION_PM3_C}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(4) version_pm3.c"
|
||||
DEPENDS ${DEFAULT_VERSION_C} ${FPGA_VERSION_C} ${FPGA_ALL_O_MKVERSION_DEP}
|
||||
COMMAND ${MKVERSION_CMD} ${VERSION_PM3_C} || ${CMAKE_COMMAND} -E copy ${DEFAULT_VERSION_C} ${VERSION_PM3_C}
|
||||
COMMENT "Call mkversion.xx script to generate 'version_pm3.c', if mkversion return fail, fallback is default_version_pm3.c"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# ---------------- 5. Build fulliamge elf but stage1, not '.data' section compressed ----------------
|
||||
set(ALL_SRCS ${THUMBSRC} ${ARMSRC} ${ASMSRC} ${VERSIONSRC})
|
||||
|
||||
add_executable(fullimage.stage1.elf ${ALL_SRCS})
|
||||
set_target_properties(fullimage.stage1.elf PROPERTIES # The 'fullimage.stage1.elf' output to ${OBJDIR}
|
||||
RUNTIME_OUTPUT_DIRECTORY "${OBJDIR}"
|
||||
OUTPUT_NAME "fullimage.stage1"
|
||||
SUFFIX ".elf" # OK, OBJDIR + OUTPUT_NAME + SUFFIX = /xxx/obj/fullimage.stage1.elf
|
||||
)
|
||||
target_link_options(fullimage.stage1.elf PRIVATE -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map) # output map file
|
||||
target_link_options(fullimage.stage1.elf PRIVATE -L ${CMAKE_CURRENT_LIST_DIR} -T ${LDSCRIPT} ${CROSS_LDFLAGS})
|
||||
target_compile_options(fullimage.stage1.elf PRIVATE ${CROSS_CFLAGS}) # !!!! WARN !!!! No -mthumb on here
|
||||
set_source_files_properties(${THUMBSRC} PROPERTIES COMPILE_OPTIONS "-mthumb") # THUMBSRC is '-mthumb' flag required.
|
||||
target_include_directories(fullimage.stage1.elf PRIVATE ${INC_DIRS})
|
||||
target_link_libraries(fullimage.stage1.elf ${LIBS})
|
||||
if (NOT SKIP_FPGA_EMBED) # Link fpga data(not compressed)
|
||||
set_property(TARGET fullimage.stage1.elf APPEND PROPERTY LINK_LIBRARIES ${FPGA_ALL_O})
|
||||
endif ()
|
||||
|
||||
# Generate HEX and BIN files for stage 1 for easy downloading to device and debugging device.
|
||||
add_custom_command(TARGET ${PROJECT_NAME}.stage1.elf POST_BUILD
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(5) ${PROJECT_NAME}.stage1.(HEX,BIN)"
|
||||
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.stage1.elf> ${OUTPUT_STAGE1_HEX}
|
||||
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.stage1.elf> ${OUTPUT_STAGE1_BIN}
|
||||
COMMENT "Build ${PROJECT_NAME}.stage1.hex & ${PROJECT_NAME}.stage1.bin"
|
||||
)
|
||||
|
||||
# ---------------- 6. Pull '.data' section from 'fullimage.stage1.elf' ----------------
|
||||
# Tips: fpga_all.o maybe pack to elf on stage1, is uncompress data binary, next step will compress(all '.data' section).
|
||||
# When this step is reached, the linker has allocated a specific vma for the data segment. Compression is only to reduce the firmware volume.
|
||||
add_custom_command(
|
||||
OUTPUT ${DATA_BIN}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(6) pull '.data'(uncompressed)"
|
||||
COMMAND ${CMAKE_OBJCOPY} -O binary --only-section .data ${STAGE1_ELF} ${DATA_BIN}
|
||||
DEPENDS fullimage.stage1.elf
|
||||
COMMENT "Call the 'objcopy' to pull the '.data' section from 'fullimage.stage1.elf'"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# ---------------- 7. Compress '.data' section binary to 'fullimage.data.bin.z' ----------------
|
||||
# About '.data' section compress: https://www.eevblog.com/forum/microcontrollers/compression-of-data-(initialized-variables)-section/
|
||||
add_custom_command(
|
||||
OUTPUT ${DATA_BIN_Z}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(7) fullimage.data.bin.z"
|
||||
COMMAND ${FPGA_COMPRESS_EXE} ${DATA_BIN} ${DATA_BIN_Z}
|
||||
DEPENDS ${DATA_BIN}
|
||||
DEPENDS ${FPGA_COMPRESS_EXE} # Ensure host tool is built before running it.
|
||||
COMMENT "Call the 'fpga_compress' to compress '.data' section from 'fullimage.stage1.elf'"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# ---------------- 8. Pack data bin and gen fullimage.elf ----------------
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_COMPRESSION|WITH_COMPRESSION=1")
|
||||
add_custom_command(
|
||||
OUTPUT ${FINAL_ELF}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] LD(8) fullimage.elf (with compression)"
|
||||
COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm --strip-all --update-section .data=${DATA_BIN_Z} ${STAGE1_ELF} ${FINAL_ELF}
|
||||
DEPENDS ${STAGE1_ELF} ${DATA_BIN_Z}
|
||||
COMMENT "Put the compressed '.data' section to 'fullimage.stage1.elf' for build 'fullimage.elf'"
|
||||
VERBATIM
|
||||
)
|
||||
else ()
|
||||
add_custom_command(
|
||||
OUTPUT ${FINAL_ELF}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] MIN(8) fullimage.elf (without compression) "
|
||||
COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm --strip-all ${STAGE1_ELF} ${FINAL_ELF}
|
||||
DEPENDS ${STAGE1_ELF}
|
||||
COMMENT "Copy 'fullimage.stage1.elf' to 'fullimage.elf' if no compress required"
|
||||
VERBATIM
|
||||
)
|
||||
endif ()
|
||||
|
||||
# ---------------- 9. Generate S19 format file ----------------
|
||||
add_custom_command(
|
||||
OUTPUT ${OUTPUT_S19}
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(9) S19 file"
|
||||
COMMAND ${CMAKE_OBJCOPY}
|
||||
-Osrec
|
||||
--srec-forceS3
|
||||
--strip-debug
|
||||
--no-change-warnings
|
||||
--change-addresses=-0x100000
|
||||
--change-start=0
|
||||
--change-section-address=.bss+0
|
||||
--change-section-address=.data-0x100000
|
||||
--change-section-address=.commonarea+0
|
||||
${FINAL_ELF}
|
||||
${OUTPUT_S19}
|
||||
DEPENDS ${FINAL_ELF}
|
||||
COMMENT "Call the objcopy to convert ELF to S19 format"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# ---------------- 10. Finally, start build the fullimage, the 'All' build will from here start ----------------
|
||||
add_custom_target(fullimage ALL DEPENDS ${OUTPUT_S19} COMMENT "Build fullimage")
|
||||
add_dependencies(fullimage fullimage.stage1.elf) # fullimage dependencies tree start, 9 -> 1 -> 9
|
||||
# Generate HEX and BIN files for fullimage finally
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(10) ${PROJECT_NAME}(HEX,BIN)"
|
||||
COMMAND ${CMAKE_OBJCOPY} -Oihex ${FINAL_ELF} ${OUTPUT_FINAL_HEX}
|
||||
COMMAND ${CMAKE_OBJCOPY} -Obinary ${FINAL_ELF} ${OUTPUT_FINAL_BIN}
|
||||
COMMENT "Build ${PROJECT_NAME}.hex & ${PROJECT_NAME}.bin"
|
||||
)
|
||||
+65
-10
@@ -29,10 +29,43 @@ ifeq ($(PLTNAME),)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Proxmark5 requires armlib.
|
||||
include ../armlib/Exports.mk
|
||||
|
||||
#remove one of the following defines and comment out the relevant line
|
||||
#in the next section to remove that particular feature from compilation.
|
||||
# NO space,TABs after the "\" sign.
|
||||
APP_CFLAGS = $(PLATFORM_DEFS)
|
||||
APP_CFLAGS += $(ARMLIB_EXPORT_CFLAGS)
|
||||
|
||||
# HAL for platform
|
||||
ifeq ($(PLATFORM),PM5)
|
||||
SRC_STARTUP = startup_at32f435_437.s
|
||||
SRC_TICKS = ../common_arm/ticks/ticks_hw_at32.c i2c.c # TODO DXL: It always depends on I2C, so the compilation location of this source file needs to be optimized.
|
||||
SRC_GPIO = ../common_arm/gpio/gpio_hw_at32.c
|
||||
SRC_WDT = ../common_arm/wdt/wdt_hw_at32.c
|
||||
SRC_RSSI = ../common_arm/rssi/rssi_hw_at32.c
|
||||
SRC_SYS = ../common_arm/sys/sys_hw_at32.c
|
||||
SRC_FPGA = ../common_arm/fpga/fpga_hw_at32.c ../common_arm/fpga/fpga_gw_jtag.c
|
||||
SRC_USB_CDC = ../common_arm/usb/usb_cdc_at32.c
|
||||
SRC_FLASH_DATA = ../common_arm/flash_data/flashmem_hw_at32.c
|
||||
APP_CFLAGS += -mcpu=cortex-m4
|
||||
CROSS_LDFLAGS += -mcpu=cortex-m4
|
||||
LD_SCRIPT = ldscript.osimage.at32
|
||||
ARMLIB_OBJ = $(OBJDIR)/$(ARMLIB_EXPORT_LIBNAME)
|
||||
LIBS += $(ARMLIB_OBJ)
|
||||
else
|
||||
SRC_STARTUP =
|
||||
SRC_TICKS = ../common_arm/ticks/ticks_hw_at91.c
|
||||
SRC_GPIO = ../common_arm/gpio/gpio_hw_at91.c
|
||||
SRC_WDT = ../common_arm/wdt/wdt_hw_at91.c
|
||||
SRC_RSSI = ../common_arm/rssi/rssi_hw_at91.c
|
||||
SRC_SYS = ../common_arm/sys/sys_hw_at91.c
|
||||
SRC_FPGA = ../common_arm/fpga/fpga_hw_at91.c
|
||||
SRC_USB_CDC = ../common_arm/usb/usb_cdc_at91.c
|
||||
SRC_FLASH_DATA = ../common_arm/flash_data/flashmem_hw_at91.c
|
||||
LD_SCRIPT = ldscript.osimage.at91
|
||||
endif
|
||||
|
||||
SRC_LF = lfops.c lfsampling.c pcf7931.c lfdemod.c lfadc.c
|
||||
SRC_HF = hfops.c
|
||||
@@ -51,9 +84,9 @@ SRC_NFCBARCODE = thinfilm.c
|
||||
|
||||
# SRC_BEE = bee.c
|
||||
|
||||
# RDV40 related hardware support
|
||||
# RDV40 or PM5 related hardware support
|
||||
ifneq (,$(findstring WITH_FLASH,$(APP_CFLAGS)))
|
||||
SRC_FLASH = flashmem.c
|
||||
SRC_FLASH = flashmem_core.c $(SRC_FLASH_DATA)
|
||||
SRC_SPIFFS = spiffs.c spiffs_cache.c spiffs_check.c spiffs_gc.c spiffs_nucleus.c spiffs_hydrogen.c
|
||||
else
|
||||
SRC_FLASH =
|
||||
@@ -143,6 +176,11 @@ THUMBSRC = start.c \
|
||||
$(SRC_FELICA) \
|
||||
$(SRC_STANDALONE) \
|
||||
$(SRC_ZX) \
|
||||
$(SRC_RSSI) \
|
||||
$(SRC_TICKS) \
|
||||
$(SRC_GPIO) \
|
||||
$(SRC_WDT) \
|
||||
$(SRC_SYS) \
|
||||
appmain.c \
|
||||
printf.c \
|
||||
dbprint.c \
|
||||
@@ -150,8 +188,8 @@ THUMBSRC = start.c \
|
||||
util.c \
|
||||
string.c \
|
||||
BigBuf.c \
|
||||
ticks.c \
|
||||
clocks.c \
|
||||
ticks_core.c \
|
||||
rssi_core.c \
|
||||
hfsnoop.c \
|
||||
generator.c \
|
||||
cmac_calc.c \
|
||||
@@ -159,10 +197,16 @@ THUMBSRC = start.c \
|
||||
|
||||
|
||||
# These are to be compiled in ARM mode
|
||||
ARMSRC = fpgaloader.c \
|
||||
usb_cdc.c \
|
||||
ARMSRC = fpga_loader.c \
|
||||
fpga_core.c \
|
||||
$(SRC_FPGA) \
|
||||
usb_cdc_desc.c \
|
||||
usb_read_ng.c \
|
||||
$(SRC_USB_CDC) \
|
||||
cmd.c
|
||||
|
||||
ASMSRC = $(SRC_STARTUP)
|
||||
|
||||
VERSIONSRC = version_pm3.c \
|
||||
fpga_version_info.c
|
||||
|
||||
@@ -176,6 +220,11 @@ else
|
||||
INSTALLFWTAG = $(notdir $(INSTALLFW))
|
||||
endif
|
||||
|
||||
# On some platforms, the FPGA firmware does not need to be packaged into the ARM, because the FPGA has its own flash.
|
||||
ifneq ($(strip $(SKIP_FPGA_EMBED)),true)
|
||||
FPGA_ALL_O_DEP = $(OBJDIR)/fpga_all.o
|
||||
endif
|
||||
|
||||
OBJS = $(OBJDIR)/fullimage.s19
|
||||
FPGA_COMPRESSOR = ../tools/fpga_compress/fpga_compress
|
||||
|
||||
@@ -187,7 +236,7 @@ showinfo:
|
||||
.DELETE_ON_ERROR:
|
||||
|
||||
# version_pm3.c should be checked on every time fullimage.stage1.elf should be remade
|
||||
version_pm3.c: default_version_pm3.c $(OBJDIR)/fpga_version_info.o $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ) .FORCE
|
||||
version_pm3.c: default_version_pm3.c $(OBJDIR)/fpga_version_info.o $(FPGA_ALL_O_DEP) $(THUMBOBJ) $(ARMOBJ) $(ASMOBJ) .FORCE
|
||||
$(info [-] CHECK $@)
|
||||
$(Q)$(SH) ../tools/mkversion.sh $@ || $(CP) $< $@
|
||||
|
||||
@@ -211,10 +260,16 @@ $(FPGA_COMPRESSOR):
|
||||
$(error [!] MISSING $@ => To build it, go the root of the repo and do "make $(notdir $@)")
|
||||
$(error [!] MISSING $@)
|
||||
|
||||
$(OBJDIR)/fullimage.stage1.elf: $(VERSIONOBJ) $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ)
|
||||
ifeq ($(PLATFORM),PM5)
|
||||
$(ARMLIB_OBJ):
|
||||
$(info [=] MAKE $(notdir $@))
|
||||
@$(MAKE) --no-print-directory -f ../armlib/Makefile
|
||||
endif
|
||||
|
||||
$(OBJDIR)/fullimage.stage1.elf: $(VERSIONOBJ) $(FPGA_ALL_O_DEP) $(THUMBOBJ) $(ARMOBJ) $(ASMOBJ) $(ARMLIB_OBJ)
|
||||
$(info [=] LD $@)
|
||||
# Using -T instead of -Wl,-T is needed to prevent the linker from using the default ldscript when using picolibc instead of newlib
|
||||
$(Q)$(CROSS_LD) $(CROSS_LDFLAGS) -T ldscript -Wl,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS)
|
||||
$(Q)$(CROSS_LD) $(CROSS_LDFLAGS) -T $(LD_SCRIPT) -Wl,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS)
|
||||
|
||||
$(OBJDIR)/fullimage.data.bin: $(OBJDIR)/fullimage.stage1.elf
|
||||
$(info [-] GEN $@)
|
||||
@@ -243,6 +298,7 @@ tarbin: $(OBJS)
|
||||
clean:
|
||||
$(Q)$(RM) $(DEPENDENCY_FILES)
|
||||
$(Q)$(RM) $(OBJDIR)$(PATHSEP)*.o
|
||||
$(Q)$(RM) $(OBJDIR)$(PATHSEP)*.a
|
||||
$(Q)$(RM) $(OBJDIR)$(PATHSEP)*.elf
|
||||
$(Q)$(RM) $(OBJDIR)$(PATHSEP)*.s19
|
||||
$(Q)$(RM) $(OBJDIR)$(PATHSEP)*.map
|
||||
@@ -266,4 +322,3 @@ help:
|
||||
@echo Possible targets:
|
||||
@echo + all - Build the full image $(OBJDIR)/fullimage.s19
|
||||
@echo + clean - Clean $(OBJDIR)
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
#[[
|
||||
+==========================================================+
|
||||
| STANDALONE | DESCRIPTION |
|
||||
+==========================================================+
|
||||
| (empty) | No standalone mode |
|
||||
+----------------------------------------------------------+
|
||||
| LF_SKELETON | standalone mode skeleton |
|
||||
| | - iceman |
|
||||
+----------------------------------------------------------+
|
||||
| LF_EM4100EMUL | Simulate predefined em4100 tags only |
|
||||
| | |
|
||||
+----------------------------------------------------------+
|
||||
| LF_EM4100RSWB | Read/simulate/brute em4100 tags & |
|
||||
| | clone it to T555x tags |
|
||||
+----------------------------------------------------------+
|
||||
| LF_EM4100RSWW | Read/simulate/validate em4100 tags & |
|
||||
| | clone it to T55xx tags, wipe T55xx tags|
|
||||
+----------------------------------------------------------+
|
||||
| LF_EM4100RWC | Read/simulate em4100 tags & clone it |
|
||||
| | to T555x tags |
|
||||
+----------------------------------------------------------+
|
||||
| LF_HIDBRUTE | HID corporate 1000 bruteforce |
|
||||
| | - Federico dotta & Maurizio Agazzini |
|
||||
+----------------------------------------------------------+
|
||||
| LF_HIDFCBRUTE | HID Facility Code bruteforce |
|
||||
| (RDV4 only) | |
|
||||
+----------------------------------------------------------+
|
||||
| LF_ICEHID | LF HID collector to flashmem |
|
||||
| (RDV4 only) | |
|
||||
+----------------------------------------------------------+
|
||||
| LF_MULTIHID | LF HID 26 Bit (H1031) multi simulator |
|
||||
| | - Shain Lakin |
|
||||
+----------------------------------------------------------+
|
||||
| LF_NEDAP_SIM | LF Nedap ID simple simulator |
|
||||
| | |
|
||||
+----------------------------------------------------------+
|
||||
| LF_NEXID | LF Nexwatch collector to flashmem |
|
||||
| (RDV4 only) | |
|
||||
+----------------------------------------------------------+
|
||||
| LF_PROXBRUTE | HID ProxII bruteforce |
|
||||
| | - Brad Antoniewicz |
|
||||
+----------------------------------------------------------+
|
||||
| LF_PROX2BRUTE | HID ProxII bruteforce v2 |
|
||||
| | |
|
||||
+----------------------------------------------------------+
|
||||
| LF_SAMYRUN | HID26 read/clone/sim |
|
||||
| (default) | - Samy Kamkar |
|
||||
+----------------------------------------------------------+
|
||||
| LF_THAREXDE | Simulate/read EM4x50 tags |
|
||||
| (RDV4 only) | storing in flashmem |
|
||||
+----------------------------------------------------------+
|
||||
| HF_14ASNIFF | 14a sniff to flashmem (rdv4) or ram |
|
||||
| | |
|
||||
+----------------------------------------------------------+
|
||||
| HF_14BSNIFF | 14b sniff to flashmem (rdv4) or ram |
|
||||
| | |
|
||||
+----------------------------------------------------------+
|
||||
| HF_15SNIFF | 15693 sniff to flashmem (rdv4) or ram |
|
||||
| | |
|
||||
+----------------------------------------------------------+
|
||||
| HF_15SIM | 15693 tag simulator |
|
||||
| | |
|
||||
+----------------------------------------------------------+
|
||||
| HF_AVEFUL | Mifare ultralight read/simulation |
|
||||
| | - Ave Ozkal |
|
||||
+----------------------------------------------------------+
|
||||
| HF_BOG | 14a sniff with ULC/ULEV1/NTAG auth |
|
||||
| (RDV4 only) | storing in flashmem - Bogito |
|
||||
+----------------------------------------------------------+
|
||||
| HF_CARDHOPPER | Relay 14a protocols over long distances|
|
||||
| (RDV4 only) | (w/ IP backbone) - Sam Haskins |
|
||||
+----------------------------------------------------------+
|
||||
| HF_COLIN | Mifare ultra fast sniff/sim/clone |
|
||||
| (RDV4 only) | - Colin Brigato |
|
||||
+----------------------------------------------------------+
|
||||
| HF_CRAFTBYTE | UID stealer - Emulates scanned 14a UID |
|
||||
| | - Anze Jensterle |
|
||||
+----------------------------------------------------------+
|
||||
| HF_ICECLASS | Simulate HID iCLASS legacy ags |
|
||||
| (RDV4 only) | storing in flashmem |
|
||||
+----------------------------------------------------------+
|
||||
| HF_LEGIC | Read/simulate Legic Prime tags |
|
||||
| | storing in flashmem |
|
||||
+----------------------------------------------------------+
|
||||
| HF_LEGICSIM | Simulate Legic Prime tags |
|
||||
| (RDV4 only) | stored on flashmem |
|
||||
+----------------------------------------------------------+
|
||||
| HF_MATTYRUN | Mifare sniff/clone |
|
||||
| | - Matías A. Ré Medina |
|
||||
+----------------------------------------------------------+
|
||||
| HF_MFCSIM | Simulate Mifare Classic 1k card |
|
||||
| (RDV4 only) | storing in flashmem - Ray Lee |
|
||||
+----------------------------------------------------------+
|
||||
| HF_MSDSAL | Read and emulate MSD Visa cards |
|
||||
| | - Salvador Mendoza |
|
||||
+----------------------------------------------------------+
|
||||
| HF_REBLAY | 14A Relay over BT |
|
||||
| (RDV4 only) | - Salvador Mendoza |
|
||||
+----------------------------------------------------------+
|
||||
| HF_ST25_TEAROFF | Store/restore ST25TB tags with |
|
||||
| | tear-off for counters - SecLabz |
|
||||
+----------------------------------------------------------+
|
||||
| HF_TCPRST | IKEA Rothult read/sim/dump/emul |
|
||||
| | - Nick Draffen |
|
||||
+----------------------------------------------------------+
|
||||
| HF_TMUDFORD | Read and emulate 15 tags |
|
||||
| | - Tim Mudford |
|
||||
+----------------------------------------------------------+
|
||||
| HF_UNISNIFF | Sniff 14a/14b/15 (optionally to flash) |
|
||||
| | - hazardousvoltage |
|
||||
+----------------------------------------------------------+
|
||||
| HF_YOUNG | Mifare sniff/simulation |
|
||||
| | - Craig Young |
|
||||
+----------------------------------------------------------+
|
||||
| DANKARMULTI | Load multiple standalone modes. |
|
||||
| | - Daniel Karling |
|
||||
+----------------------------------------------------------+
|
||||
| HF_EMVPNG | Read and emulate EMV Visa cards |
|
||||
| | - Davi Mikael (Penegui) |
|
||||
+----------------------------------------------------------+
|
||||
]]
|
||||
|
||||
# Default standalone if no standalone specified
|
||||
set(DEFAULT_STANDALONE LF_SAMYRUN)
|
||||
# (you can set explicitly STANDALONE= to disable standalone modes)
|
||||
if (NOT DEFINED STANDALONE)
|
||||
set(STANDALONE ${DEFAULT_STANDALONE})
|
||||
endif ()
|
||||
set(STANDALONE_REQ_DEFS)
|
||||
|
||||
# List of all standalone modes, and which ones require bluetooth, smartcard or flash.
|
||||
# (for now, we only support one standalone mode at a time)
|
||||
set(STANDALONE_MODES
|
||||
LF_SKELETON LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RSWW LF_EM4100RWC
|
||||
LF_HIDBRUTE LF_HIDFCBRUTE LF_ICEHID LF_MULTIHID LF_NEDAP_SIM LF_NEXID
|
||||
LF_PROXBRUTE LF_PROX2BRUTE LF_SAMYRUN LF_THAREXDE
|
||||
HF_14ASNIFF HF_14BSNIFF HF_15SNIFF HF_15SIM
|
||||
HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_CRAFTBYTE HF_ICECLASS
|
||||
HF_LEGIC HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY
|
||||
HF_ST25_TEAROFF HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG HF_EMVPNG DANKARMULTI)
|
||||
# List of modes that require bluetooth
|
||||
set(STANDALONE_MODES_REQ_BT HF_CARDHOPPER HF_REBLAY)
|
||||
# List of modes that require smartcard
|
||||
set(STANDALONE_MODES_REQ_SMARTCARD)
|
||||
# List of modes that require flash
|
||||
set(STANDALONE_MODES_REQ_FLASH
|
||||
LF_HIDFCBRUTE LF_ICEHID LF_NEXID LF_THAREXDE HF_BOG HF_COLIN
|
||||
HF_ICECLASS HF_LEGICSIM HF_MFCSIM)
|
||||
|
||||
message(STATUS "STANDALONE = ${STANDALONE}")
|
||||
message(STATUS "STANDALONE_MODES = ${STANDALONE_MODES}")
|
||||
|
||||
# Check if the specified standalone mode is valid, and set the corresponding definitions.
|
||||
# 'MATCHES' is used to check if the specified standalone mode is in the list of valid modes.
|
||||
if (DEFINED STANDALONE)
|
||||
if ("${STANDALONE_MODES}" MATCHES "${STANDALONE}")
|
||||
string(TOUPPER ${STANDALONE} STANDALONE_UPPER)
|
||||
set(STANDALONE_PLATFORM_DEFS ${STANDALONE_PLATFORM_DEFS} "-DWITH_STANDALONE_${STANDALONE_UPPER}")
|
||||
# Required for SmartCard, set '-DWITH_SMARTCARD'
|
||||
if ("${STANDALONE_MODES_REQ_SMARTCARD}" MATCHES "${STANDALONE}")
|
||||
set(STANDALONE_REQ_DEFS ${STANDALONE_REQ_DEFS} -DWITH_SMARTCARD)
|
||||
endif ()
|
||||
# Required for Flash, set '-DWITH_FLASH'
|
||||
if ("${STANDALONE_MODES_REQ_FLASH}" MATCHES "${STANDALONE}")
|
||||
set(STANDALONE_REQ_DEFS ${STANDALONE_REQ_DEFS} -DWITH_FLASH)
|
||||
endif ()
|
||||
# Required for Bluetooth, set '-DWITH_FPC_USART_HOST'
|
||||
# (we use USART host for bluetooth communication in standalone modes)
|
||||
if ("${STANDALONE_MODES_REQ_BT}" MATCHES "${STANDALONE}")
|
||||
set(STANDALONE_REQ_DEFS ${STANDALONE_REQ_DEFS} -DWITH_FPC_USART_HOST)
|
||||
endif ()
|
||||
else ()
|
||||
message(FATAL_ERROR "Invalid STANDALONE: ${STANDALONE}. ${KNOWN_DEFINITIONS}")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Export the definitions for standalone mode to be used in the main CMakeLists.txt
|
||||
# --- Usually referenced externally:
|
||||
# STANDALONE_REQ_DEFS -> Definitions required by the selected standalone mode (e.g., -DWITH_FLASH)
|
||||
# STANDALONE_PLATFORM_DEFS -> Definitions for the selected standalone mode (e.g., -DWITH_STANDALONE_LF_SAMYRUN)
|
||||
# --- It is not usually used externally:
|
||||
# STANDALONE_MODES -> List of all valid standalone modes (for error checking)
|
||||
# STANDALONE_MODES_REQ_BT -> List of standalone modes that require bluetooth (for error checking)
|
||||
# STANDALONE_MODES_REQ_SMARTCARD -> List of standalone modes that require smartcard (for error checking)
|
||||
# STANDALONE_MODES_REQ_FLASH -> List of standalone modes that require flash (for error checking)
|
||||
@@ -0,0 +1,161 @@
|
||||
# --------------------- Standalone Source Files ---------------------
|
||||
|
||||
set(DIR_STANDALONE ${CMAKE_CURRENT_LIST_DIR})
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/placeholder.c")
|
||||
|
||||
# Check which standalone mode is selected, and set the corresponding source file.
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_SKELETON")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_skeleton.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100EMUL")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100emul.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100RSWB")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100rswb.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100RSWW")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100rsww.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100RWC")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100rwc.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_HIDBRUTE")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_hidbrute.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_HIDFCBRUTE")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_hidfcbrute.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_ICEHID")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_icehid.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_MULTIHID")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_multihid.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_NEDAP_SIM")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_nedap_sim.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_NEXID")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_nexid.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_SAMYRUN")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_samyrun.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_PROXBRUTE")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_proxbrute.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_PROX2BRUTE")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_prox2brute.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_THAREXDE")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_tharexde.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_14ASNIFF")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_14asniff.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_14BSNIFF")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_14bsniff.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_15SNIFF")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_15sniff.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_15SIM")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_15sim.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_AVEFUL")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_aveful.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_BOG")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_bog.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_CARDHOPPER")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_cardhopper.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_COLIN")
|
||||
set(SRC_STANDALONE
|
||||
"${DIR_STANDALONE}/vtsend.c"
|
||||
"${DIR_STANDALONE}/hf_colin.c"
|
||||
"${DIR_STANDALONE}/frozen.c"
|
||||
"${DIR_STANDALONE}/nprintf.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_CRAFTBYTE")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_craftbyte.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_ICECLASS")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_iceclass.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_LEGIC")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_legic.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_LEGICSIM")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_legicsim.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_MATTYRUN")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_mattyrun.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_MFCSIM")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_mfcsim.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_MSDSAL")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_msdsal.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_REBLAY")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_reblay.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_TCPRST")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_tcprst.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_TMUDFORD")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_tmudford.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_UNISNIFF")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_unisniff.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_YOUNG")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_young.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_ST25_TEAROFF")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_st25_tearoff.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_EMVPNG")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_emvpng.c")
|
||||
endif ()
|
||||
|
||||
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_DANKARMULTI")
|
||||
set(SRC_STANDALONE "${DIR_STANDALONE}/dankarmulti.c")
|
||||
endif ()
|
||||
@@ -19,8 +19,9 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
#include "spiffs.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
#define HF_14ASNIFF_LOGFILE "hf_14asniff.trace"
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "spiffs.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
#define HF_14BSNIFF_LOGFILE "hf_14bsniff.trace"
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "iso15693.h"
|
||||
#include "iso15.h"
|
||||
#include "protocols.h"
|
||||
@@ -30,7 +31,7 @@
|
||||
#include "spiffs.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "BigBuf.h"
|
||||
#include "crc16.h"
|
||||
|
||||
|
||||
@@ -67,14 +67,15 @@
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "iso15693.h"
|
||||
#include "iso15.h"
|
||||
#include "util.h"
|
||||
#include "spiffs.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
|
||||
|
||||
@@ -33,11 +33,12 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
|
||||
#include "ticks.h" // SpinDelay
|
||||
#include "ticks_apis.h" // SpinDelay
|
||||
#include "protocols.h" // MIFARE_ULEV1_VERSION, MIFARE_ULEV1_READSIG, MIFARE_ULEV1_READ_CNT, MIFARE_ULEV1_CHECKTEAR
|
||||
#include <string.h> // memcmp
|
||||
#include "mifareutil.h"
|
||||
|
||||
@@ -37,9 +37,10 @@ from the client to view the stored quadlets.
|
||||
#include "util.h"
|
||||
#include "spiffs.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "BigBuf.h"
|
||||
#include "string.h"
|
||||
|
||||
@@ -89,9 +90,9 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
Uart14aInit(receivedCmd, MAX_FRAME_SIZE, receivedCmdPar);
|
||||
|
||||
// Setup and start DMA.
|
||||
if (FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE) == false) {
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *)dmaBuf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) {
|
||||
Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
Dbprintf("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -118,7 +119,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
LED_A_ON();
|
||||
|
||||
int register readBufDataP = data - dmaBuf;
|
||||
int register dmaBufDataP = DMA_BUFFER_SIZE - AT91C_BASE_PDC_SSC->PDC_RCR;
|
||||
int register dmaBufDataP = DMA_BUFFER_SIZE - FPGA_SSC_DMA_RX_Remaining_Count();
|
||||
if (readBufDataP <= dmaBufDataP)
|
||||
dataLen = dmaBufDataP - readBufDataP;
|
||||
else
|
||||
@@ -132,16 +133,8 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
if (dataLen < 1)
|
||||
continue;
|
||||
|
||||
// primary buffer was stopped( <-- we lost data!
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t)dmaBuf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||
// Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
||||
}
|
||||
// secondary buffer sets as primary, secondary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)dmaBuf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
if (FPGA_SSC_DMA_RX_Done()) {
|
||||
FPGA_SSC_DMA_RX_Refresh_Repeat(dmaBuf, DMA_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
LED_A_OFF();
|
||||
@@ -216,7 +209,7 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
|
||||
}
|
||||
} // end main loop
|
||||
|
||||
FpgaDisableSscDma();
|
||||
FPGA_SSC_DMA_RX_Disable();
|
||||
set_tracing(false);
|
||||
|
||||
Dbprintf("Stopped sniffing");
|
||||
|
||||
@@ -19,16 +19,17 @@
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "dbprint.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "iso14443a.h"
|
||||
#include "protocols.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "standalone.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "util.h"
|
||||
#include "usart.h"
|
||||
#include "cmd.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "usb_cdc_apis.h"
|
||||
|
||||
#ifdef CARDHOPPER_USB
|
||||
#define cardhopper_write usb_write
|
||||
@@ -535,7 +536,7 @@ static bool GetIso14443aCommandFromReaderInterruptible(uint8_t *received, uint16
|
||||
|
||||
Uart14aInit(received, received_max_len, par);
|
||||
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
uint8_t b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
(void)b;
|
||||
|
||||
uint8_t flip = 0;
|
||||
@@ -555,8 +556,8 @@ static bool GetIso14443aCommandFromReaderInterruptible(uint8_t *received, uint16
|
||||
checker = 4000;
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
if (MillerDecoding(b, 0)) {
|
||||
*len = GetUart14a()->len;
|
||||
return true;
|
||||
|
||||
@@ -22,9 +22,10 @@
|
||||
#include "hf_colin.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "iso14443a.h"
|
||||
|
||||
@@ -67,12 +67,13 @@
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "iso14443a.h"
|
||||
#include "util.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "protocols.h"
|
||||
#include "mifareutil.h"
|
||||
#include "string.h"
|
||||
@@ -208,8 +209,8 @@ static bool RAMFUNC sniff_wait_for_rnda_reply(tag_t type) {
|
||||
uint8_t *data = dma->buf;
|
||||
|
||||
// Setup and start DMA.
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -222,7 +223,7 @@ static bool RAMFUNC sniff_wait_for_rnda_reply(tag_t type) {
|
||||
uint32_t ledb_counter = 0;
|
||||
while (BUTTON_PRESS() == false) {
|
||||
register int readBufDataP = data - dma->buf;
|
||||
register int dmaBufDataP = DMA_BUFFER_SIZE - AT91C_BASE_PDC_SSC->PDC_RCR;
|
||||
register int dmaBufDataP = DMA_BUFFER_SIZE - FPGA_SSC_DMA_RX_Remaining_Count();
|
||||
if (readBufDataP <= dmaBufDataP) {
|
||||
dataLen = dmaBufDataP - readBufDataP;
|
||||
} else {
|
||||
@@ -246,17 +247,7 @@ static bool RAMFUNC sniff_wait_for_rnda_reply(tag_t type) {
|
||||
ledb_counter = 0;
|
||||
}
|
||||
|
||||
// primary buffer was stopped( <-- we lost data!
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||
// Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
||||
}
|
||||
// secondary buffer sets as primary, secondary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
|
||||
|
||||
// Need two samples to feed Miller and Manchester-Decoder
|
||||
if (rx_samples & 0x01) {
|
||||
@@ -328,7 +319,7 @@ out:
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
}
|
||||
FpgaDisableTracing();
|
||||
FpgaDisableSscDma();
|
||||
FPGA_SSC_DMA_RX_Disable();
|
||||
return found_rnda_reply;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,12 +67,13 @@
|
||||
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "iso14443a.h"
|
||||
#include "util.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "protocols.h"
|
||||
#include "mifareutil.h"
|
||||
#include "string.h"
|
||||
@@ -184,8 +185,8 @@ static bool RAMFUNC sniff_wait_for_commit(tag_t type) {
|
||||
uint8_t *data = dma->buf;
|
||||
|
||||
// Setup and start DMA.
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -195,7 +196,7 @@ static bool RAMFUNC sniff_wait_for_commit(tag_t type) {
|
||||
uint32_t ledb_counter = 0;
|
||||
while (BUTTON_PRESS() == false) {
|
||||
register int readBufDataP = data - dma->buf;
|
||||
register int dmaBufDataP = DMA_BUFFER_SIZE - AT91C_BASE_PDC_SSC->PDC_RCR;
|
||||
register int dmaBufDataP = DMA_BUFFER_SIZE - FPGA_SSC_DMA_RX_Remaining_Count();
|
||||
if (readBufDataP <= dmaBufDataP) {
|
||||
dataLen = dmaBufDataP - readBufDataP;
|
||||
} else {
|
||||
@@ -219,17 +220,7 @@ static bool RAMFUNC sniff_wait_for_commit(tag_t type) {
|
||||
ledb_counter = 0;
|
||||
}
|
||||
|
||||
// primary buffer was stopped( <-- we lost data!
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||
// Dbprintf("[-] RxEmpty ERROR | data length %d", dataLen); // temporary
|
||||
}
|
||||
// secondary buffer sets as primary, secondary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
|
||||
|
||||
// Need two samples to feed Miller and Manchester-Decoder
|
||||
if (rx_samples & 0x01) {
|
||||
@@ -294,7 +285,7 @@ out:
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
}
|
||||
FpgaDisableTracing();
|
||||
FpgaDisableSscDma();
|
||||
FPGA_SSC_DMA_RX_Disable();
|
||||
return found_commit;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "iso14443a.h"
|
||||
|
||||
@@ -26,9 +26,10 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "spiffs.h"
|
||||
#include "iclass.h"
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "legicrf.h"
|
||||
#include "legicrfsim.h"
|
||||
#include "legic.h" // legic_card_select_t struct
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
// main code for legic prime simulator aka LEGICSIM
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "commonutil.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "dbprint.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "iso14443a.h"
|
||||
#include "mifarecmd.h"
|
||||
#include "mifaresim.h" // mifare1ksim
|
||||
@@ -36,7 +37,7 @@
|
||||
#include "spiffs.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "string.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "util.h"
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
// main code for mifare classic simulator aka MFCSIM
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "commonutil.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "iso14443a.h"
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "iso14443a.h"
|
||||
|
||||
@@ -59,12 +59,13 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "iso14443b.h" // ISO14443B operations
|
||||
#include "util.h"
|
||||
#include "spiffs.h" // Flash memory filesystem access
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "BigBuf.h"
|
||||
#include "protocols.h"
|
||||
#include "crc16.h" // compute_crc
|
||||
@@ -368,7 +369,7 @@ static void iso14443b_setup_light(void) {
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
|
||||
// Signal field is on with the appropriate LED
|
||||
#ifdef RDV4
|
||||
#if defined RDV4 || defined PM5
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SEND_SHALLOW_MOD_RDV4);
|
||||
#else
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SEND_SHALLOW_MOD);
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "iso14443a.h"
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
|
||||
#include "iso15693.h"
|
||||
#include "iso15.h"
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
#include "spiffs.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "BigBuf.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
#include <inttypes.h>
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "commonutil.h"
|
||||
#include "mifarecmd.h"
|
||||
|
||||
@@ -20,11 +20,12 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "lfops.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "commonutil.h"
|
||||
|
||||
@@ -46,10 +46,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
@@ -47,10 +47,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
@@ -28,11 +28,12 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "lfops.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
#include "spiffs.h"
|
||||
|
||||
@@ -33,10 +33,11 @@
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "lfops.h"
|
||||
|
||||
#define OPTS 3
|
||||
|
||||
@@ -40,15 +40,15 @@
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "lfsampling.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "spiffs.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "lfops.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "parity.h"
|
||||
|
||||
// What card number should be used for the bruteforce?
|
||||
|
||||
@@ -23,12 +23,13 @@
|
||||
#include "lfops.h"
|
||||
#include "lfsampling.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "printf.h"
|
||||
#include "spiffs.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "lfdemod.h"
|
||||
/*
|
||||
* `lf_hidcollect` sniffs after LF HID credentials, and stores them in internal
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "lfops.h"
|
||||
|
||||
#define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "lfops.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
#include "lfops.h"
|
||||
#include "lfsampling.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "printf.h"
|
||||
#include "spiffs.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "lfdemod.h"
|
||||
#include "commonutil.h"
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "lfops.h"
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "lfops.h"
|
||||
|
||||
void ModInfo(void) {
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "lfops.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
|
||||
#define OPTS 2
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
// main code for EM4x50 simulator and collector aka THAREXDE
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "commonutil.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "spiffs.h"
|
||||
@@ -279,11 +279,7 @@ void RunMod(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// reset timer
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // re-enable timer and wait for TC0
|
||||
AT91C_BASE_TC0->TC_RC = 0; // set TIOA (carry bit) on overflow, return to zero
|
||||
AT91C_BASE_TC0->TC_RA = 1; // clear carry bit on next clock cycle
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // reset and re-enable timer
|
||||
ResetTicks();
|
||||
}
|
||||
|
||||
if (state == STATE_READ) {
|
||||
|
||||
+423
-98
@@ -20,13 +20,15 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "appmain.h"
|
||||
|
||||
#include "clocks.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "sys_apis.h"
|
||||
#include "usb_cdc_apis.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "dbprint.h"
|
||||
#include "pmflash.h"
|
||||
#include "fpga.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "rssi_apis.h"
|
||||
#include "string.h"
|
||||
#include "printf.h"
|
||||
#include "legicrf.h"
|
||||
@@ -62,7 +64,7 @@
|
||||
#include "pcf7931.h"
|
||||
#include "Standalone/standalone.h"
|
||||
#include "util.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "protocols.h"
|
||||
@@ -72,6 +74,7 @@
|
||||
#include "sam_mfc.h"
|
||||
#include "sam_sc.h"
|
||||
#include "cmac_calc.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#ifdef WITH_LCD
|
||||
#include "LCD_disabled.h"
|
||||
@@ -146,47 +149,6 @@ void send_wtx(uint16_t wtx) {
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Read an ADC channel and block till it completes, then return the result
|
||||
// in ADC units (0 to 1023). Also a routine to sum up a number of samples and
|
||||
// return that.
|
||||
//-----------------------------------------------------------------------------
|
||||
static uint16_t ReadAdc(uint8_t ch) {
|
||||
|
||||
// Note: ADC_MODE_PRESCALE and ADC_MODE_SAMPLE_HOLD_TIME are set to the maximum allowed value.
|
||||
// AMPL_HI is are high impedance (10MOhm || 1MOhm) output, the input capacitance of the ADC is 12pF (typical). This results in a time constant
|
||||
// of RC = (0.91MOhm) * 12pF = 10.9us. Even after the maximum configurable sample&hold time of 40us the input capacitor will not be fully charged.
|
||||
//
|
||||
// The maths are:
|
||||
// If there is a voltage v_in at the input, the voltage v_cap at the capacitor (this is what we are measuring) will be
|
||||
//
|
||||
// v_cap = v_in * (1 - exp(-SHTIM/RC)) = v_in * (1 - exp(-40us/10.9us)) = v_in * 0,97 (i.e. an error of 3%)
|
||||
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
|
||||
AT91C_BASE_ADC->ADC_MR =
|
||||
ADC_MODE_PRESCALE(63) // ADC_CLK = MCK / ((63+1) * 2) = 48MHz / 128 = 375kHz
|
||||
| ADC_MODE_STARTUP_TIME(1) // Startup Time = (1+1) * 8 / ADC_CLK = 16 / 375kHz = 42,7us Note: must be > 20us
|
||||
| ADC_MODE_SAMPLE_HOLD_TIME(15); // Sample & Hold Time SHTIM = 15 / ADC_CLK = 15 / 375kHz = 40us
|
||||
|
||||
AT91C_BASE_ADC->ADC_CHER = ADC_CHANNEL(ch);
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
||||
|
||||
while (!(AT91C_BASE_ADC->ADC_SR & ADC_END_OF_CONVERSION(ch))) {};
|
||||
|
||||
return (AT91C_BASE_ADC->ADC_CDR[ch] & 0x3FF);
|
||||
}
|
||||
|
||||
// was static - merlok
|
||||
uint16_t AvgAdc(uint8_t ch) {
|
||||
return SumAdc(ch, 32) >> 5;
|
||||
}
|
||||
|
||||
uint16_t SumAdc(uint8_t ch, uint8_t NbSamples) {
|
||||
uint16_t a = 0;
|
||||
for (uint8_t i = 0; i < NbSamples; i++)
|
||||
a += ReadAdc(ch);
|
||||
return (a + (NbSamples >> 1) - 1);
|
||||
}
|
||||
#ifdef WITH_LF
|
||||
static void MeasureAntennaTuning(void) {
|
||||
|
||||
@@ -230,7 +192,7 @@ static void MeasureAntennaTuning(void) {
|
||||
WDT_HIT();
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, i);
|
||||
SpinDelay(20);
|
||||
uint32_t adcval = ((MAX_ADC_LF_VOLTAGE * (SumAdc(ADC_CHAN_LF, 32) >> 1)) >> 14);
|
||||
uint32_t adcval = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_LF);
|
||||
if (i == LF_DIVISOR_125)
|
||||
payload.v_lf125 = adcval; // voltage at 125kHz
|
||||
|
||||
@@ -255,24 +217,15 @@ static void MeasureAntennaTuning(void) {
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER);
|
||||
SpinDelay(50);
|
||||
|
||||
payload.v_hf = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
payload.v_hf = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
reply_ng(CMD_MEASURE_ANTENNA_TUNING, PM3_SUCCESS, (uint8_t *)&payload, sizeof(payload));
|
||||
LEDsoff();
|
||||
}
|
||||
#endif
|
||||
// Measure HF in milliVolt
|
||||
static uint16_t MeasureAntennaTuningHfData(void) {
|
||||
|
||||
return (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
|
||||
}
|
||||
|
||||
// Measure LF in milliVolt
|
||||
static uint32_t MeasureAntennaTuningLfData(void) {
|
||||
return (MAX_ADC_LF_VOLTAGE * (SumAdc(ADC_CHAN_LF, 32) >> 1)) >> 14;
|
||||
}
|
||||
#ifndef PM5 // TODO DXL: PM5 is temporarily incompatible.
|
||||
|
||||
// Measure HF antenna decay after field-off.
|
||||
// Captures peak-detect capacitor discharge curve via burst ADC sampling.
|
||||
@@ -297,7 +250,7 @@ static void MeasureAntennaTuningHfDecay(const hf_decay_params_t *params) {
|
||||
SpinDelay(stabilize_ms);
|
||||
|
||||
// Baseline measurement (averaged)
|
||||
payload.baseline_mv = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
payload.baseline_mv = (MAX_ADC_HF_VOLTAGE * AdcRssiSum(ADC_RSSI_CH_HF, 32)) >> 15;
|
||||
|
||||
// Configure ADC for fast burst mode.
|
||||
// Faster ADC clock + shorter S&H trades absolute accuracy for speed.
|
||||
@@ -354,6 +307,8 @@ static void MeasureAntennaTuningHfDecay(const hf_decay_params_t *params) {
|
||||
LEDsoff();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void print_stack_usage(void) {
|
||||
for (uint32_t *p = _stack_start; ; ++p) {
|
||||
if (*p != 0xdeadbeef) {
|
||||
@@ -429,7 +384,10 @@ static void SendVersion(void) {
|
||||
} PACKED;
|
||||
|
||||
struct p payload;
|
||||
payload.id = *(AT91C_DBGU_CIDR);
|
||||
|
||||
// Set a CHIP ID(not unique id)
|
||||
payload.id = GetChipId();
|
||||
|
||||
#ifndef WITH_COMPRESSION
|
||||
payload.section_size = (uint32_t)_bootrom_end - (uint32_t)_bootrom_start + (uint32_t)__os_size__;
|
||||
#else
|
||||
@@ -441,6 +399,8 @@ static void SendVersion(void) {
|
||||
reply_ng(CMD_VERSION, PM3_SUCCESS, (uint8_t *)&payload, 12 + payload.versionstr_len);
|
||||
}
|
||||
|
||||
#ifdef CHIP_AT91SAM7S // Only AT91SAM7S chip series need calibration.
|
||||
|
||||
static void TimingIntervalAcquisition(void) {
|
||||
// trigger new acquisition by turning main oscillator off and on
|
||||
mck_from_pll_to_slck();
|
||||
@@ -449,6 +409,8 @@ static void TimingIntervalAcquisition(void) {
|
||||
StartTickCount();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void print_debug_level(void) {
|
||||
char dbglvlstr[20] = {0};
|
||||
switch (g_dbglevel) {
|
||||
@@ -529,6 +491,9 @@ static void SendStatus(uint32_t wait) {
|
||||
tosend_t *ts = get_tosend();
|
||||
Dbprintf(" ToSendMax........... %d", ts->max);
|
||||
Dbprintf(" ToSend BUFFERSIZE... %d", TOSEND_BUFFER_SIZE);
|
||||
|
||||
#ifdef CHIP_AT91SAM7S
|
||||
|
||||
while ((AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINRDY) == 0); // Wait for MAINF value to become available...
|
||||
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINF; // Get # main clocks within 16 slow clocks
|
||||
Dbprintf(" Slow clock.......... %d Hz", (16 * MAINCK) / mainf);
|
||||
@@ -543,6 +508,9 @@ static void SendStatus(uint32_t wait) {
|
||||
Dbprintf(_YELLOW_(" Slow Clock actual speed seems closer to %d kHz"),
|
||||
(16 * MAINCK / 1000) / mainf * delta_time / SLCK_CHECK_MS);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DbpString(_CYAN_("Installed StandAlone Mode"));
|
||||
ModInfo();
|
||||
|
||||
@@ -816,7 +784,7 @@ void ListenReaderField(uint8_t limit) {
|
||||
LEDsoff();
|
||||
|
||||
if (limit == LF_ONLY || limit == LF_HF_BOTH) {
|
||||
lf_av = lf_max = (MAX_ADC_LF_VOLTAGE * SumAdc(ADC_CHAN_LF, 32)) >> 15;
|
||||
lf_av = lf_max = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_LF);
|
||||
Dbprintf("LF 125/134kHz Baseline: %dmV", lf_av);
|
||||
lf_baseline = lf_av;
|
||||
}
|
||||
@@ -824,7 +792,7 @@ void ListenReaderField(uint8_t limit) {
|
||||
if (limit == HF_ONLY || limit == LF_HF_BOTH) {
|
||||
|
||||
// iceman, useless, since we are measuring readerfield, not our field. My tests shows a max of 20v from a reader.
|
||||
hf_av = hf_max = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
hf_av = hf_max = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);;
|
||||
Dbprintf("HF 13.56MHz Baseline: %dmV", hf_av);
|
||||
hf_baseline = hf_av;
|
||||
}
|
||||
@@ -864,7 +832,7 @@ void ListenReaderField(uint8_t limit) {
|
||||
LED_D_OFF();
|
||||
}
|
||||
|
||||
lf_av_new = (MAX_ADC_LF_VOLTAGE * SumAdc(ADC_CHAN_LF, 32)) >> 15;
|
||||
lf_av_new = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_LF);
|
||||
// see if there's a significant change
|
||||
if (ABS(lf_av - lf_av_new) > REPORT_CHANGE) {
|
||||
Dbprintf("LF 125/134kHz Field Change: %5dmV", lf_av_new);
|
||||
@@ -882,7 +850,7 @@ void ListenReaderField(uint8_t limit) {
|
||||
LED_B_OFF();
|
||||
}
|
||||
|
||||
hf_av_new = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
hf_av_new = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);
|
||||
// see if there's a significant change
|
||||
if (ABS(hf_av - hf_av_new) > REPORT_CHANGE) {
|
||||
Dbprintf("HF 13.56MHz Field Change: %5dmV", hf_av_new);
|
||||
@@ -965,6 +933,188 @@ void ListenReaderField(uint8_t limit) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PM5
|
||||
|
||||
#include "at32f435_437_crm.h"
|
||||
#include "at32f435_437_tmr.h"
|
||||
|
||||
// TODO DXL: 一部分QC逻辑可以放在PM5设备端实现,这个函数后面记得复用代码,并且不要放在 appmain.c 中(考虑移动到平台专属的模块)
|
||||
// failed_item == 0: BLUE LED in Antenna
|
||||
// failed_item == 1: RGB in mainboard
|
||||
// failed_item == 2: LEDs * 4 or Buzzer or Button in mainboard
|
||||
static bool QCTestPM5(uint8_t *failed_item) {
|
||||
// 天线蓝灯、主板RGB、主板四颗LED、蜂鸣器、按钮
|
||||
StartTicks();
|
||||
I2C_init(true);
|
||||
|
||||
uint8_t addr_ant = 0x51; // TODO DXL define move to header?
|
||||
uint8_t addr_rgb = 0x48;
|
||||
uint8_t data_u8;
|
||||
bool isok = false;
|
||||
|
||||
// 读取天线当前MAP配置,如果读取不到,则认为天线的控制芯片可能有问题
|
||||
isok = I2C_BufferReadRaw(&data_u8, 1, 0x02, addr_ant << 1);
|
||||
if (!isok) {
|
||||
*failed_item = 0;
|
||||
return false;
|
||||
}
|
||||
// 重新写入天线的MAP配置,去开灯
|
||||
data_u8 |= 0x06; // 0000 0110 // 125 134 250 375 500 HFLED LFLED Q
|
||||
isok = I2C_BufferWrite(&data_u8, 1, 0x02, addr_ant << 1);
|
||||
|
||||
// 开启RGB灯自动闪烁
|
||||
uint8_t buf_rgb[3] = {0, 0, 128};
|
||||
uint8_t buf_flash_time[] = {50, 50}; // 1s on, 500ms off.
|
||||
isok = I2C_WriteByte(0, 0x02, addr_rgb << 1); // 写索引寄存器,设置后续操作的RGB索引
|
||||
if (!isok) {
|
||||
*failed_item = 1;
|
||||
return false;
|
||||
}
|
||||
isok = I2C_WriteByte(1, 0x01, addr_rgb << 1); // 写数量寄存器,设置硬件挂1个灯,很重要!!!,不然无法闪灯
|
||||
if (!isok) {
|
||||
*failed_item = 1;
|
||||
return false;
|
||||
}
|
||||
isok = I2C_BufferWrite(buf_rgb, sizeof(buf_rgb), 0x03, addr_rgb << 1); // 写数据寄存器,每三个字节就是对应的RGB888值
|
||||
if (!isok) {
|
||||
*failed_item = 1;
|
||||
return false;
|
||||
}
|
||||
isok = I2C_WriteByte(1, 0x06, addr_rgb << 1); // 写闪灯使能寄存器,使能 0 号灯珠的可控闪烁
|
||||
if (!isok) {
|
||||
*failed_item = 1;
|
||||
return false;
|
||||
}
|
||||
isok = I2C_BufferWrite(buf_flash_time, sizeof(buf_flash_time), 0x07, addr_rgb << 1); // 写闪灯使能寄存器,使能 0 号灯珠的可控闪烁
|
||||
if (!isok) {
|
||||
*failed_item = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 在循环中测试LED、蜂鸣器、按钮
|
||||
|
||||
#define BEEPER_EN_GPIO GPIOB
|
||||
#define BEEPER_EN_GPIO_PIN GPIO_PINS_13
|
||||
#define BEEPER_MOD_GPIO GPIOC
|
||||
#define BEEPER_MOD_GPIO_PIN GPIO_PINS_9
|
||||
#define BEEPER_MOD_GPIO_SRC GPIO_PINS_SOURCE9
|
||||
#define BEEPER_MOD_GPIO_MUX GPIO_MUX_3
|
||||
#define BEEPER_MOD_TMR TMR8
|
||||
#define BEEPER_MOD_TMR_CH TMR_SELECT_CHANNEL_4
|
||||
|
||||
// PB13 使能,PC9 调制,使用 TMR8_CH4 输出调制
|
||||
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_TMR8_PERIPH_CLOCK, TRUE);
|
||||
|
||||
gpio_init_type gpio_init_struct;
|
||||
gpio_default_para_init(&gpio_init_struct);
|
||||
// 蜂鸣器使能脚
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||
gpio_init_struct.gpio_pins = BEEPER_EN_GPIO_PIN;
|
||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||
gpio_init(BEEPER_EN_GPIO, &gpio_init_struct);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE);
|
||||
// 蜂鸣器调制脚
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_init_struct.gpio_pins = BEEPER_MOD_GPIO_PIN;
|
||||
gpio_init(BEEPER_MOD_GPIO, &gpio_init_struct);
|
||||
gpio_pin_mux_config(BEEPER_MOD_GPIO, BEEPER_MOD_GPIO_SRC, BEEPER_MOD_GPIO_MUX);
|
||||
|
||||
tmr_internal_clock_set(BEEPER_MOD_TMR);
|
||||
tmr_reset(BEEPER_MOD_TMR);
|
||||
tmr_base_init(BEEPER_MOD_TMR, 999, 95); // 192M出2k
|
||||
tmr_output_config_type tmr_output_struct;
|
||||
tmr_output_default_para_init(&tmr_output_struct);
|
||||
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
||||
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
|
||||
tmr_output_struct.oc_output_state = TRUE;
|
||||
tmr_output_channel_config(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, &tmr_output_struct);
|
||||
tmr_channel_value_set(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, 500); // 比较值=500 (50%占空比)
|
||||
tmr_counter_enable(BEEPER_MOD_TMR, TRUE);
|
||||
tmr_output_enable(BEEPER_MOD_TMR, TRUE);
|
||||
|
||||
LEDsoff(); // 在开始测试之前线关闭所有LED
|
||||
|
||||
*failed_item = 2;
|
||||
// 在开始测试之前,如果按钮是按下的,则认为失败,有可能按钮不良卡住了
|
||||
if (BUTTON_PRESS()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (BUTTON_PRESS()) {
|
||||
return true;
|
||||
}
|
||||
if (data_available()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LED_A_ON();
|
||||
BEEPER_MOD_TMR->pr = 999;
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE);
|
||||
SpinDelay(20);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE);
|
||||
SpinDelay(200);
|
||||
LED_A_OFF();
|
||||
|
||||
if (BUTTON_PRESS()) {
|
||||
return true;
|
||||
}
|
||||
if (data_available()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LED_B_ON();
|
||||
BEEPER_MOD_TMR->pr = 1100;
|
||||
tmr_channel_value_set(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, 550);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE);
|
||||
SpinDelay(20);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE);
|
||||
SpinDelay(200);
|
||||
LED_B_OFF();
|
||||
|
||||
if (BUTTON_PRESS()) {
|
||||
return true;
|
||||
}
|
||||
if (data_available()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LED_C_ON();
|
||||
BEEPER_MOD_TMR->pr = 1200;
|
||||
tmr_channel_value_set(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, 600);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE);
|
||||
SpinDelay(20);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE);
|
||||
SpinDelay(200);
|
||||
LED_C_OFF();
|
||||
|
||||
if (BUTTON_PRESS()) {
|
||||
return true;
|
||||
}
|
||||
if (data_available()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LED_D_ON();
|
||||
BEEPER_MOD_TMR->pr = 1300;
|
||||
tmr_channel_value_set(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, 650);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE);
|
||||
SpinDelay(20);
|
||||
gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE);
|
||||
SpinDelay(200);
|
||||
LED_D_OFF();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void PacketReceived(PacketCommandNG *packet) {
|
||||
/*
|
||||
if (packet->ng) {
|
||||
@@ -2684,7 +2834,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
if (button_status == BUTTON_SINGLE_CLICK) {
|
||||
reply_ng(CMD_MEASURE_ANTENNA_TUNING_HF, PM3_EOPABORTED, NULL, 0);
|
||||
}
|
||||
uint16_t volt = MeasureAntennaTuningHfData();
|
||||
uint32_t volt = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);
|
||||
reply_ng(CMD_MEASURE_ANTENNA_TUNING_HF, PM3_SUCCESS, (uint8_t *)&volt, sizeof(volt));
|
||||
break;
|
||||
case 3:
|
||||
@@ -2697,10 +2847,12 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifndef PM5
|
||||
case CMD_HF_DECAY: {
|
||||
MeasureAntennaTuningHfDecay((const hf_decay_params_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case CMD_MEASURE_ANTENNA_TUNING_LF: {
|
||||
if (packet->length != 2)
|
||||
reply_ng(CMD_MEASURE_ANTENNA_TUNING_LF, PM3_EINVARG, NULL, 0);
|
||||
@@ -2718,7 +2870,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
reply_ng(CMD_MEASURE_ANTENNA_TUNING_LF, PM3_EOPABORTED, NULL, 0);
|
||||
}
|
||||
|
||||
uint32_t volt = MeasureAntennaTuningLfData();
|
||||
uint32_t volt = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_LF);
|
||||
reply_ng(CMD_MEASURE_ANTENNA_TUNING_LF, PM3_SUCCESS, (uint8_t *)&volt, sizeof(volt));
|
||||
break;
|
||||
case 3:
|
||||
@@ -2848,7 +3000,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
|
||||
base = (uint8_t *) _flash_start;
|
||||
|
||||
size_t flash_size = get_flash_size();
|
||||
size_t flash_size = GetChipFlashSize();
|
||||
|
||||
// Boundary check the offset.
|
||||
if (offset > flash_size) {
|
||||
@@ -3072,7 +3224,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
case CMD_FLASHMEM_SET_SPIBAUDRATE: {
|
||||
if (packet->length != sizeof(uint32_t))
|
||||
break;
|
||||
FlashmemSetSpiBaudrate(packet->data.asDwords[0]);
|
||||
Flash_SetSpiBaudrate(packet->data.asDwords[0]);
|
||||
break;
|
||||
}
|
||||
case CMD_FLASHMEM_WRITE: {
|
||||
@@ -3199,6 +3351,16 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
LED_B_OFF();
|
||||
break;
|
||||
}
|
||||
case CMD_FLASHMEM_INFO: {
|
||||
uint64_t flash_uniqueID = 0;
|
||||
bool isok = FlashInit();
|
||||
if (isok) {
|
||||
isok = Flash_UniqueID((uint8_t *)(&flash_uniqueID));
|
||||
FlashStop();
|
||||
}
|
||||
reply_ng(CMD_FLASHMEM_INFO, (isok) ? PM3_SUCCESS : PM3_EFLASH, (uint8_t *)&flash_uniqueID, sizeof(flash_uniqueID));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef WITH_LF
|
||||
case CMD_LF_SET_DIVISOR: {
|
||||
@@ -3210,17 +3372,17 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
case CMD_SET_ADC_MUX: {
|
||||
switch (packet->data.asBytes[0]) {
|
||||
case 0:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
break;
|
||||
case 2:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
break;
|
||||
#ifndef WITH_FPC_USART
|
||||
case 1:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LORAW);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LORAW);
|
||||
break;
|
||||
case 3:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIRAW);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIRAW);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
@@ -3238,7 +3400,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
break;
|
||||
}
|
||||
case CMD_TIA: {
|
||||
|
||||
#ifdef CHIP_AT91SAM7S
|
||||
while ((AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINRDY) == 0); // Wait for MAINF value to become available...
|
||||
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINF;
|
||||
Dbprintf(" Slow clock old measured value:.........%d Hz", (16 * MAINCK) / mainf);
|
||||
@@ -3249,6 +3411,10 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
Dbprintf(""); // first message gets lost
|
||||
Dbprintf(" Slow clock new measured value:.........%d Hz", (16 * MAINCK) / mainf);
|
||||
reply_ng(CMD_TIA, PM3_SUCCESS, NULL, 0);
|
||||
#else
|
||||
Dbprintf("Chip is not AT91SAM7S, TIA is " _RED_("unsupported"));
|
||||
reply_ng(CMD_TIA, PM3_EDEVNOTSUPP, NULL, 0);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case CMD_STANDALONE: {
|
||||
@@ -3294,8 +3460,8 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
usb_disable();
|
||||
|
||||
// (iceman) why this wait?
|
||||
SpinDelay(1000);
|
||||
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
|
||||
SpinDelay(1000); // Go wait for the USB to completely go offline on the host side.
|
||||
ResetChip();
|
||||
// We're going to reset, and the bootrom will take control.
|
||||
for (;;) {}
|
||||
break;
|
||||
@@ -3305,7 +3471,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
g_common_area.command = COMMON_AREA_COMMAND_ENTER_FLASH_MODE;
|
||||
}
|
||||
usb_disable();
|
||||
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
|
||||
ResetChip();
|
||||
// We're going to flash, and the bootrom will take control.
|
||||
for (;;) {}
|
||||
break;
|
||||
@@ -3318,13 +3484,126 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
reply_old(CMD_DEVICE_INFO, dev_info, 0, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_FPGA_BITSTREAM_CONFIG_START: // Merge 3 cmds to reuse some code.
|
||||
case CMD_FPGA_BITSTREAM_CONFIG_WRITE:
|
||||
case CMD_FPGA_BITSTREAM_CONFIG_FINISH: {
|
||||
// Dbprintf("Received FPGA config command 0x%04x", packet->cmd);
|
||||
int res;
|
||||
// Process
|
||||
if (packet->cmd == CMD_FPGA_BITSTREAM_CONFIG_START) {
|
||||
struct p {
|
||||
uint8_t sram_mode;
|
||||
uint32_t file_length;
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *) packet->data.asBytes;
|
||||
res = FpgaStartConfig(payload->sram_mode, payload->file_length);
|
||||
} else if (packet->cmd == CMD_FPGA_BITSTREAM_CONFIG_WRITE) {
|
||||
res = FpgaConfigWrite(packet->data.asBytes, packet->length);
|
||||
} else {
|
||||
res = FpgaStopConfig();
|
||||
}
|
||||
// Response
|
||||
if (res == PM3_EFAILED) {
|
||||
uint32_t plat_status = FpgaConfigPlatformStatus(); // Return status code of platform when res is PM3_EFAILED
|
||||
reply_ng(packet->cmd, res, (uint8_t*)&plat_status, sizeof(plat_status));
|
||||
} else {
|
||||
reply_ng(packet->cmd, res, NULL, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifdef PM5
|
||||
case CMD_ANT_CONTROL_WRITE: {
|
||||
struct p {
|
||||
uint8_t data;
|
||||
uint8_t reg_type; // 0 is io reg, 1 is map reg.
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *) packet->data.asBytes;
|
||||
|
||||
StartTicks();
|
||||
I2C_init(true);
|
||||
|
||||
uint8_t addr = 0x51; // TODO DXL define move to header?
|
||||
uint8_t cmd = payload->reg_type == 0 ? 0x01 : 0x02;
|
||||
|
||||
bool isok = I2C_BufferWrite(&payload->data, 1, cmd, addr << 1);
|
||||
reply_ng(CMD_ANT_CONTROL_WRITE, isok ? PM3_SUCCESS : PM3_EFAILED, NULL, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_ANT_CONTROL_READ: {
|
||||
struct p {
|
||||
uint8_t reg_type; // 0 is io reg, 1 is map reg.
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *) packet->data.asBytes;
|
||||
|
||||
StartTicks();
|
||||
I2C_init(true);
|
||||
|
||||
uint8_t addr = 0x51; // TODO DXL define move to header?
|
||||
uint8_t cmd = payload->reg_type == 0 ? 0x01 : 0x02;
|
||||
uint8_t data;
|
||||
|
||||
bool isok = I2C_BufferReadRaw(&data, 1, cmd, addr << 1);
|
||||
reply_ng(CMD_ANT_CONTROL_READ, isok ? PM3_SUCCESS : PM3_EFAILED, &data, sizeof(data));
|
||||
break;
|
||||
}
|
||||
case CMD_EEPROM_FACTORY_INFO_READ: {
|
||||
StartTicks();
|
||||
I2C_init(true);
|
||||
|
||||
uint8_t addr = 0x50; // TODO DXL define move to header?
|
||||
uint8_t data[256]; // 24c02: 256byte
|
||||
bool isok = I2C_BufferReadRaw(data, sizeof(data), 0x00, addr << 1);
|
||||
reply_ng(CMD_EEPROM_FACTORY_INFO_READ, isok ? PM3_SUCCESS : PM3_EFAILED, data, sizeof(data));
|
||||
break;
|
||||
}
|
||||
case CMD_EEPROM_FACTORY_INFO_WRITE: {
|
||||
StartTicks();
|
||||
I2C_init(true);
|
||||
|
||||
uint8_t addr = 0x50; // TODO DXL define move to header?
|
||||
uint16_t len = packet->length;
|
||||
while (len) {
|
||||
uint16_t write_len = MIN(len, 16);
|
||||
uint16_t write_pos = packet->length - len;
|
||||
bool isok = I2C_BufferWrite(packet->data.asBytes + write_pos, write_len, write_pos, addr << 1);
|
||||
if (!isok) {
|
||||
reply_ng(CMD_EEPROM_FACTORY_INFO_WRITE, PM3_EFAILED, NULL, 0);
|
||||
return;
|
||||
}
|
||||
len -= write_len;
|
||||
// 24C02 writes to a page write buffer of only 16 bytes.
|
||||
// If the write speed is too fast, it may cause data write failure.
|
||||
// Therefore, a delay or ACK judgment is required between page writes
|
||||
SpinDelay(5); // 24C02 write cycle time is about 5ms
|
||||
}
|
||||
reply_ng(CMD_EEPROM_FACTORY_INFO_WRITE, PM3_SUCCESS, NULL, 0);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case CMD_FPGA_CMD_SET_PWR_PWM_LOW_COUNT: {
|
||||
struct p {
|
||||
uint8_t is_lf;
|
||||
uint16_t count;
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *) packet->data.asBytes;
|
||||
FpgaDownloadAndGo(payload->is_lf ? FPGA_BITSTREAM_LF : FPGA_BITSTREAM_HF);
|
||||
FpgaSendCommand(FPGA_CMD_SET_PWR_PWM_LOW_COUNT, payload->count & 0xFFF);
|
||||
reply_ng(CMD_FPGA_CMD_SET_PWR_PWM_LOW_COUNT, PM3_SUCCESS, NULL, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_MAIN_CHIP_UNIQUEID: {
|
||||
// PM3 placeholder, to be replaced when correct commit gets merged
|
||||
uint8_t size = 0;
|
||||
uint8_t* uid = NULL;
|
||||
uint8_t* uid = GetChipUniqueId(&size);
|
||||
reply_ng(CMD_MAIN_CHIP_UNIQUEID, PM3_SUCCESS, uid, size);
|
||||
break;
|
||||
}
|
||||
#ifdef PM5
|
||||
case CMD_PM5_QC_TEST: {
|
||||
uint8_t failed_item = 0;
|
||||
reply_ng(CMD_PM5_QC_TEST, QCTestPM5(&failed_item) ? PM3_SUCCESS : PM3_EFAILED, &failed_item, 1);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
Dbprintf("%s: 0x%04x", "unknown command:", packet->cmd);
|
||||
break;
|
||||
@@ -3332,7 +3611,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
}
|
||||
}
|
||||
|
||||
void __attribute__((noreturn)) AppMain(void) {
|
||||
void __attribute__((noreturn)) AppMain(void) {
|
||||
|
||||
SpinDelay(100);
|
||||
BigBuf_initialize();
|
||||
@@ -3344,23 +3623,12 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||
|
||||
LEDsoff();
|
||||
|
||||
// The FPGA gets its clock from us from PCK0 output, so set that up.
|
||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_PCK0;
|
||||
AT91C_BASE_PIOA->PIO_PDR = GPIO_PCK0;
|
||||
AT91C_BASE_PMC->PMC_SCER |= AT91C_PMC_PCK0;
|
||||
// PCK0 is PLL clock / 4 = 96MHz / 4 = 24MHz
|
||||
AT91C_BASE_PMC->PMC_PCKR[0] = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_4; // 4 for 24MHz pck0, 2 for 48 MHZ pck0
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_PCK0;
|
||||
|
||||
// Reset SPI
|
||||
AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SWRST;
|
||||
AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SWRST; // errata says it needs twice to be correctly set.
|
||||
|
||||
// Reset SSC
|
||||
AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST;
|
||||
// Setup FPGA clock & Reset COM
|
||||
FpgaSetup24MHzClk();
|
||||
FpgaResetComInterface();
|
||||
|
||||
// Configure MUX
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
// Load the FPGA image, which we have stored in our flash.
|
||||
// (the HF version by default)
|
||||
@@ -3389,12 +3657,10 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WITH_FLASH
|
||||
// If flash is not present, BUSY_TIMEOUT kicks in, let's do it after USB
|
||||
loadT55xxConfig();
|
||||
|
||||
//
|
||||
// Enforce a spiffs check/garbage collection at boot so we are likely to never
|
||||
// fall under the 2 contigous free blocks availables
|
||||
// This is a time-consuming process on large flash.
|
||||
@@ -3457,9 +3723,68 @@ void __attribute__((noreturn)) AppMain(void) {
|
||||
* So this is the trigger to execute a standalone mod. Generic entrypoint by following the standalone/standalone.h headerfile
|
||||
* All standalone mod "main loop" should be the RunMod() function.
|
||||
*/
|
||||
allow_send_wtx = false;
|
||||
RunMod();
|
||||
allow_send_wtx = true;
|
||||
// allow_send_wtx = false;
|
||||
// RunMod();
|
||||
// allow_send_wtx = true;
|
||||
|
||||
#ifdef PM5 // TODO DXL Test long press to device shutdown, temporarily blocking standalone mod
|
||||
|
||||
/*
|
||||
StartTicks();
|
||||
I2C_init(true);
|
||||
uint8_t addr = 0x51;
|
||||
// 125 134 250 375 500 HFLED LFLED Q
|
||||
// 1 0 0 0 0 1 1 1
|
||||
uint8_t data = 0x87;
|
||||
I2C_BufferWrite(&data, 1, 0x02, addr << 1);
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
FpgaSendCommand(FPGA_CMD_SET_PWR_PWM_LOW_COUNT, 4095);
|
||||
|
||||
static bool b = 0;
|
||||
if (b) {
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
b = 0;
|
||||
} else {
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_ADC_READER_FIELD);
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125);
|
||||
b = 1;
|
||||
}
|
||||
*/
|
||||
|
||||
LEDsoff();
|
||||
while (BUTTON_PRESS()) {
|
||||
SpinDelay(50);
|
||||
LED_A_INV();
|
||||
SpinDelay(50);
|
||||
LED_B_INV();
|
||||
SpinDelay(50);
|
||||
LED_C_INV();
|
||||
SpinDelay(50);
|
||||
LED_D_INV();
|
||||
}
|
||||
// Release for more than 100ms before truly shutting down, anti shake
|
||||
uint8_t idx = 0;
|
||||
while (!BUTTON_PRESS()) {
|
||||
SpinDelay(10);
|
||||
idx += 1;
|
||||
if (idx == 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
LEDsoff();
|
||||
if (idx == 10) {
|
||||
SpinDelay(100);
|
||||
LED_A_INV();
|
||||
SpinDelay(100);
|
||||
LED_A_INV();
|
||||
SpinDelay(100);
|
||||
LED_A_INV();
|
||||
Gpio_ARM_Power_ON_Low();
|
||||
while (1); // Wait for system power off.
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,16 +28,6 @@ extern bool g_hf_field_timeout_active;
|
||||
void hf_field_off(void);
|
||||
int tearoff_hook(void);
|
||||
|
||||
#if defined RDV4 || defined ICOPYX
|
||||
// ADC Vref = 3300mV, and an (10000k+240k):240k voltage divider on the LF input can measure voltages up to 140800 mV
|
||||
#define MAX_ADC_HF_VOLTAGE 140800
|
||||
#else
|
||||
// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV
|
||||
#define MAX_ADC_HF_VOLTAGE 36300
|
||||
#endif
|
||||
// ADC Vref = 3300mV, (240k-10M):240k voltage divider, 140800 mV
|
||||
#define MAX_ADC_LF_VOLTAGE 140800
|
||||
|
||||
// Default connection speed test timeout, used in hw status
|
||||
#define CONN_SPEED_TEST_MIN_TIME_DEFAULT 500 // in milliseconds
|
||||
|
||||
@@ -48,9 +38,6 @@ void send_wtx(uint16_t wtx);
|
||||
void ReadMem(int addr);
|
||||
void __attribute__((noreturn)) AppMain(void);
|
||||
|
||||
uint16_t AvgAdc(uint8_t ch);
|
||||
uint16_t SumAdc(uint8_t ch, uint8_t NbSamples);
|
||||
|
||||
//void PrintToSendBuffer(void);
|
||||
void ToSendStuffBit(int b);
|
||||
void ToSendReset(void);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+17
-1
@@ -14,7 +14,8 @@
|
||||
// See LICENSE.txt for the text of the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "cmd.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "usb_cdc_apis.h"
|
||||
#include "usb_read_ng.h"
|
||||
#include "usart.h"
|
||||
#include "crc16.h"
|
||||
#include "string.h"
|
||||
@@ -73,6 +74,9 @@ int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, const v
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// TODO DXL 测试阶段,暂时通过SPI应答
|
||||
extern int cep_spi_write_sync(uint8_t *data, size_t len);
|
||||
|
||||
static int reply_ng_internal(uint16_t cmd, int8_t status, uint8_t reason, const uint8_t *data, size_t len, bool ng) {
|
||||
PacketResponseNGRaw txBufferNG;
|
||||
size_t txBufferNGLen;
|
||||
@@ -119,6 +123,10 @@ static int reply_ng_internal(uint16_t cmd, int8_t status, uint8_t reason, const
|
||||
resultusb = usb_write((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
}
|
||||
if (g_reply_via_fpc) {
|
||||
|
||||
// TODO DXL 测试阶段,暂时通过SPI应答
|
||||
// resultusb = cep_spi_write_sync((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
|
||||
#ifdef WITH_FPC_USART_HOST
|
||||
resultfpc = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
#else
|
||||
@@ -251,6 +259,10 @@ static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *da
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// TODO DXL 临时在此处定义外部实现的CEP端口的SPI通信实现,做视频通信测试用的,后期需要重构设计
|
||||
// extern uint32_t cep_spi_read_ng(uint8_t *data, size_t len);
|
||||
// extern bool cep_spi_data_available(void);
|
||||
|
||||
int receive_ng(PacketCommandNG *rx) {
|
||||
|
||||
// Check if there is a packet available
|
||||
@@ -258,6 +270,10 @@ int receive_ng(PacketCommandNG *rx) {
|
||||
return receive_ng_internal(rx, usb_read_ng, true, false);
|
||||
}
|
||||
|
||||
// if (cep_spi_data_available()) {
|
||||
// return receive_ng_internal(rx, cep_spi_read_ng, false, true); // TODO DXL 临时用fpc这种标志
|
||||
// }
|
||||
|
||||
#ifdef WITH_FPC_USART_HOST
|
||||
// Check if there is a FPC packet available
|
||||
if (usart_rxdata_available() > 0)
|
||||
|
||||
+103
-94
@@ -16,10 +16,10 @@
|
||||
// Low frequency EM4x50 commands
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "lfsampling.h"
|
||||
#include "lfadc.h"
|
||||
#include "lfdemod.h"
|
||||
#include "commonutil.h"
|
||||
@@ -29,15 +29,8 @@
|
||||
#include "appmain.h" // tear
|
||||
#include "bruteforce.h"
|
||||
|
||||
// Sam7s has several timers, we will use the source TIMER_CLOCK1 (aka AT91C_TC_CLKS_TIMER_DIV1_CLOCK)
|
||||
// TIMER_CLOCK1 = MCK/2, MCK is running at 48 MHz, Timer is running at 48/2 = 24 MHz
|
||||
// EM4x50 units (T0) have duration of 8 microseconds (us), which is 1/125000 per second (carrier)
|
||||
// T0 = TIMER_CLOCK1 / 125000 = 192
|
||||
|
||||
#define T0 192
|
||||
|
||||
// conversions (carrier frequency 125 kHz):
|
||||
// 1 us = 1.5 ticks
|
||||
// 1 us = 1.5 ticks for GetTicks()
|
||||
// 1 cycle = 1 period = 8 us = 12 ticks
|
||||
// 1 bit = 64 cycles = 768 ticks = 512 us (for Opt64)
|
||||
#define CYCLES2TICKS 12
|
||||
@@ -59,8 +52,8 @@
|
||||
#define EM4X50_T_ZERO_DETECTION 3
|
||||
|
||||
// timeout values (empirical) for simulation mode (may vary with regard to reader)
|
||||
#define EM4X50_T_SIMULATION_TIMEOUT_READ 600
|
||||
#define EM4X50_T_SIMULATION_TIMEOUT_WAIT 50
|
||||
#define EM4X50_T_SIMULATION_TIMEOUT_READ 318 // only for em4x50_sim_read_bit()
|
||||
#define EM4X50_T_SIMULATION_TIMEOUT_EDGE 24
|
||||
|
||||
// the following value (pulses) seems to be critical; if it's too low
|
||||
//(e.g. < 120) some cards are no longer readable although they're ok
|
||||
@@ -69,7 +62,7 @@
|
||||
// div
|
||||
#define EM4X50_TAG_WORD 45
|
||||
#define EM4X50_TAG_MAX_NO_BYTES 136
|
||||
#define EM4X50_TIMEOUT_PULSE_EVAL 2500
|
||||
#define EM4X50_TIMEOUT_PULSE_EVAL (4 * EM4X50_T_TAG_FULL_PERIOD * CYCLES2TICKS) // 4bit data periods
|
||||
|
||||
uint8_t g_High = 190;
|
||||
uint8_t g_Low = 60;
|
||||
@@ -136,7 +129,6 @@ static bool extract_parities(uint64_t word, uint32_t *data) {
|
||||
}
|
||||
|
||||
void em4x50_setup_read(void) {
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
|
||||
|
||||
@@ -151,15 +143,14 @@ void em4x50_setup_read(void) {
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125);
|
||||
|
||||
// Connect the A/D to the peak-detected low-frequency path.
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
|
||||
// Steal this pin from the SSP (SPI communication channel with fpga) and
|
||||
// use it to control the modulation
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
gpio_fpga_mod_only_setup();
|
||||
|
||||
// Disable modulation at default, which means enable the field
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
// Watchdog hit
|
||||
WDT_HIT();
|
||||
@@ -170,9 +161,7 @@ void em4x50_setup_sim(void) {
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125);
|
||||
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
|
||||
gpio_fpga_mod_feedback_setup();
|
||||
|
||||
StartTicks();
|
||||
|
||||
@@ -200,8 +189,10 @@ static bool get_signalproperties(void) {
|
||||
// about 2 samples per bit period
|
||||
WaitUS(EM4X50_T_TAG_HALF_PERIOD * CYCLES2MUSEC);
|
||||
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
|
||||
// ignore first samples
|
||||
if ((i > SIGNAL_IGNORE_FIRST_SAMPLES) && (AT91C_BASE_SSC->SSC_RHR > noise)) {
|
||||
if ((i > SIGNAL_IGNORE_FIRST_SAMPLES) && (FPGA_SSC_RX_Value() > noise)) {
|
||||
signal_found = true;
|
||||
break;
|
||||
}
|
||||
@@ -220,7 +211,9 @@ static bool get_signalproperties(void) {
|
||||
|
||||
if (BUTTON_PRESS()) return false;
|
||||
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
if (sample > sample_max[i])
|
||||
sample_max[i] = sample;
|
||||
|
||||
@@ -247,7 +240,9 @@ static bool invalid_bit(void) {
|
||||
// get sample at 3/4 of bit period
|
||||
WaitUS(EM4X50_T_TAG_THREE_QUARTER_PERIOD * CYCLES2MUSEC);
|
||||
|
||||
uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
|
||||
uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
|
||||
// wait until end of bit period
|
||||
WaitUS(EM4X50_T_TAG_QUARTER_PERIOD * CYCLES2MUSEC);
|
||||
@@ -261,36 +256,46 @@ static bool invalid_bit(void) {
|
||||
|
||||
static uint32_t get_pulse_length(void) {
|
||||
|
||||
int32_t timeout = EM4X50_TIMEOUT_PULSE_EVAL, tval = 0;
|
||||
uint64_t timeout = GetTicks() + EM4X50_TIMEOUT_PULSE_EVAL;
|
||||
|
||||
// iterates pulse lengths (low -> high -> low)
|
||||
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
FPGA_SSC_RX_READY_WAIT(); // Wait for valid data received.
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
|
||||
while (sample > g_Low && (timeout--))
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
while (sample > g_Low && (GetTicks() < timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (timeout <= 0)
|
||||
if (GetTicks() >= timeout) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tval = GetTicks();
|
||||
timeout = EM4X50_TIMEOUT_PULSE_EVAL;
|
||||
uint32_t start_ticks = GetTicks();
|
||||
|
||||
while (sample < g_High && (timeout--))
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
while (sample < g_High && (GetTicks() < timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (timeout <= 0)
|
||||
if (GetTicks() >= timeout) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
timeout = EM4X50_TIMEOUT_PULSE_EVAL;
|
||||
while (sample > g_Low && (timeout--))
|
||||
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
while (sample > g_Low && (GetTicks() < timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (timeout <= 0)
|
||||
if (GetTicks() >= timeout) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return GetTicks() - tval;
|
||||
|
||||
return GetTicks() - start_ticks;
|
||||
}
|
||||
|
||||
// check if pulse length <pl> corresponds to given length <length>
|
||||
@@ -309,22 +314,22 @@ static void em4x50_reader_send_bit(int bit) {
|
||||
|
||||
// disable modulation (activate the field) for 7 cycles of carrier
|
||||
// period (Opt64)
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetTicks() - tval < 7 * CYCLES2TICKS);
|
||||
|
||||
// enable modulation (drop the field) for remaining first
|
||||
// half of bit period
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetTicks() - tval < EM4X50_T_TAG_HALF_PERIOD * CYCLES2TICKS);
|
||||
|
||||
// disable modulation for second half of bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetTicks() - tval < EM4X50_T_TAG_FULL_PERIOD * CYCLES2TICKS);
|
||||
|
||||
} else {
|
||||
|
||||
// bit = "1" means disable modulation for full bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetTicks() - tval < EM4X50_T_TAG_FULL_PERIOD * CYCLES2TICKS);
|
||||
}
|
||||
}
|
||||
@@ -903,7 +908,7 @@ void em4x50_read(const em4x50_data_t *etd, bool ledcontrol) {
|
||||
}
|
||||
|
||||
if (ledcontrol) LEDsoff();
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
lf_finalize(ledcontrol);
|
||||
reply_ng(CMD_LF_EM4X50_READ, status, (uint8_t *)words, EM4X50_TAG_MAX_NO_BYTES);
|
||||
}
|
||||
@@ -956,7 +961,7 @@ void em4x50_reader(bool ledcontrol) {
|
||||
}
|
||||
|
||||
if (ledcontrol) LEDsoff();
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
lf_finalize(ledcontrol);
|
||||
reply_ng(CMD_LF_EM4X50_READER, now, (uint8_t *)words, 4 * now);
|
||||
}
|
||||
@@ -1145,37 +1150,50 @@ void em4x50_writepwd(const em4x50_data_t *etd, bool ledcontrol) {
|
||||
reply_ng(CMD_LF_EM4X50_WRITEPWD, status, NULL, 0);
|
||||
}
|
||||
|
||||
// wait for ssc clk edge change to high, clk is from cross_lo
|
||||
// mode:
|
||||
// 1: wait to high
|
||||
// 2: wait to low
|
||||
// 3: wait to high & low
|
||||
static void em4x50_sim_wait_edge(const int mode) {
|
||||
uint32_t ticks_start;
|
||||
if (mode & 0x01) {
|
||||
ticks_start = GET_TICKS; // reset start time value
|
||||
do {
|
||||
if (GetTicksDelta(ticks_start) > EM4X50_T_SIMULATION_TIMEOUT_EDGE) {
|
||||
// Dbprintf("timeout wait clk(1)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (!Gpio_SSC_CLK_Read()); // wait to high
|
||||
}
|
||||
if (mode & 0x02) {
|
||||
ticks_start = GET_TICKS; // reset start time value
|
||||
do {
|
||||
if (GetTicksDelta(ticks_start) > EM4X50_T_SIMULATION_TIMEOUT_EDGE) {
|
||||
// Dbprintf("timeout wait clk(2)");
|
||||
return;
|
||||
}
|
||||
} while (Gpio_SSC_CLK_Read()); // wait to low
|
||||
}
|
||||
}
|
||||
|
||||
// send bit in receive mode by counting carrier cycles
|
||||
static void em4x50_sim_send_bit(uint8_t bit) {
|
||||
|
||||
uint16_t timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
|
||||
|
||||
for (int t = 0; t < EM4X50_T_TAG_FULL_PERIOD; t++) {
|
||||
|
||||
// wait until SSC_CLK goes HIGH
|
||||
// used as a simple detection of a reader field?
|
||||
while ((timeout--) && !(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
|
||||
|
||||
if (timeout == 0) {
|
||||
return;
|
||||
}
|
||||
timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
|
||||
em4x50_sim_wait_edge(1);
|
||||
|
||||
if (bit)
|
||||
OPEN_COIL();
|
||||
else
|
||||
SHORT_COIL();
|
||||
|
||||
//wait until SSC_CLK goes LOW
|
||||
while ((timeout--) && (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
|
||||
if (timeout == 0) {
|
||||
return;
|
||||
}
|
||||
timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
|
||||
em4x50_sim_wait_edge(2);
|
||||
|
||||
if (t == EM4X50_T_TAG_HALF_PERIOD)
|
||||
bit ^= 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1227,23 +1245,9 @@ static void em4x50_sim_send_word(uint32_t word) {
|
||||
|
||||
// wait for <maxperiods> pulses of carrier frequency
|
||||
static void wait_cycles(int maxperiods) {
|
||||
|
||||
int period = 0, timeout = EM4X50_T_SIMULATION_TIMEOUT_WAIT;
|
||||
|
||||
int period = 0;
|
||||
while (period < maxperiods) {
|
||||
|
||||
while ((timeout--) && !(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
|
||||
if (timeout <= 0) {
|
||||
return;
|
||||
}
|
||||
timeout = EM4X50_T_SIMULATION_TIMEOUT_WAIT;
|
||||
|
||||
while ((timeout--) && (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
|
||||
if (timeout <= 0) {
|
||||
return;
|
||||
}
|
||||
timeout = EM4X50_T_SIMULATION_TIMEOUT_WAIT;
|
||||
|
||||
em4x50_sim_wait_edge(3);
|
||||
period++;
|
||||
}
|
||||
}
|
||||
@@ -1252,7 +1256,6 @@ static void wait_cycles(int maxperiods) {
|
||||
static int em4x50_sim_read_bit(void) {
|
||||
|
||||
int cycles = 0;
|
||||
int timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
|
||||
|
||||
// wait 16 cycles to make sure there is no field when reading a "0" bit
|
||||
uint32_t waitval = GetTicks();
|
||||
@@ -1260,18 +1263,24 @@ static int em4x50_sim_read_bit(void) {
|
||||
|
||||
while (cycles < EM4X50_T_TAG_THREE_QUARTER_PERIOD) {
|
||||
|
||||
uint32_t timeout_start = GET_TICKS;
|
||||
|
||||
// wait until reader field disappears
|
||||
while ((timeout--) && !(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
|
||||
if (timeout <= 0) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
|
||||
do {
|
||||
if (GetTicksDelta(timeout_start) >= EM4X50_T_SIMULATION_TIMEOUT_READ) {
|
||||
DBG Dbprintf("read bit timeout(1): %d", GetTicksDelta(timeout_start));
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
} while (!Gpio_SSC_CLK_Read());
|
||||
|
||||
timeout_start = GET_TICKS;
|
||||
|
||||
// now check until reader switches on carrier field
|
||||
uint32_t tval = GetTicks();
|
||||
while ((timeout--) && (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
|
||||
while (Gpio_SSC_CLK_Read()) {
|
||||
|
||||
if (timeout <= 0) {
|
||||
if (GetTicksDelta(timeout_start) >= EM4X50_T_SIMULATION_TIMEOUT_READ) {
|
||||
DBG Dbprintf("read bit timeout(2): %d", GetTicksDelta(timeout_start));
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
@@ -1279,11 +1288,12 @@ static int em4x50_sim_read_bit(void) {
|
||||
if (GetTicks() - tval > EM4X50_T_ZERO_DETECTION * CYCLES2TICKS) {
|
||||
|
||||
// gap detected; wait until reader field is switched on again
|
||||
while ((timeout--) && (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
|
||||
|
||||
if (timeout <= 0) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
do {
|
||||
if (GetTicksDelta(timeout_start) >= EM4X50_T_SIMULATION_TIMEOUT_READ) {
|
||||
DBG Dbprintf("read bit timeout(3): %d", GetTicksDelta(timeout_start));
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
} while (Gpio_SSC_CLK_Read());
|
||||
|
||||
// now we have a reference "position", from here it will take
|
||||
// slightly less than 32 cycles until the end of the bit period
|
||||
@@ -1294,7 +1304,6 @@ static int em4x50_sim_read_bit(void) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
|
||||
|
||||
// no gap detected, i.e. reader field is still up;
|
||||
// continue with counting cycles
|
||||
|
||||
+51
-18
@@ -16,8 +16,9 @@
|
||||
// Low frequency EM4x70 commands
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "lfadc.h"
|
||||
#include "commonutil.h"
|
||||
@@ -222,7 +223,6 @@ static void init_tag(void) {
|
||||
}
|
||||
|
||||
static void em4x70_setup_read(void) {
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
|
||||
|
||||
@@ -235,15 +235,14 @@ static void em4x70_setup_read(void) {
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125);
|
||||
|
||||
// Connect the A/D to the peak-detected low-frequency path.
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
|
||||
// Steal this pin from the SSP (SPI communication channel with fpga) and
|
||||
// use it to control the modulation
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
gpio_fpga_mod_only_setup();
|
||||
|
||||
// Disable modulation at default, which means enable the field
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
// Start the timer
|
||||
StartTicks();
|
||||
@@ -263,7 +262,9 @@ static bool get_signalproperties(void) {
|
||||
// about 2 samples per bit period
|
||||
WaitTicks(EM4X70_T_TAG_HALF_PERIOD);
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_RHR > HIGH_SIGNAL_THRESHOLD) {
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
|
||||
if (FPGA_SSC_RX_Value() > HIGH_SIGNAL_THRESHOLD) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -279,19 +280,35 @@ static uint32_t get_falling_pulse_length(void) {
|
||||
|
||||
uint32_t timeout = GetTicks() + EM4X70_T_TAG_TIMEOUT;
|
||||
|
||||
while (IS_HIGH(AT91C_BASE_SSC->SSC_RHR) && !IS_TIMEOUT(timeout));
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
|
||||
uint32_t sample = FPGA_SSC_RX_Value();
|
||||
|
||||
while (IS_HIGH(sample) && !IS_TIMEOUT(timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_TIMEOUT(timeout))
|
||||
return 0;
|
||||
|
||||
uint32_t start_ticks = GetTicks();
|
||||
|
||||
while (IS_LOW(AT91C_BASE_SSC->SSC_RHR) && !IS_TIMEOUT(timeout));
|
||||
while (IS_LOW(sample) && !IS_TIMEOUT(timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_TIMEOUT(timeout))
|
||||
return 0;
|
||||
|
||||
while (IS_HIGH(AT91C_BASE_SSC->SSC_RHR) && !IS_TIMEOUT(timeout));
|
||||
while (IS_HIGH(sample) && !IS_TIMEOUT(timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_TIMEOUT(timeout))
|
||||
return 0;
|
||||
@@ -308,19 +325,35 @@ static uint32_t get_rising_pulse_length(void) {
|
||||
|
||||
uint32_t timeout = GetTicks() + EM4X70_T_TAG_TIMEOUT;
|
||||
|
||||
while (IS_LOW(AT91C_BASE_SSC->SSC_RHR) && !IS_TIMEOUT(timeout));
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
|
||||
uint32_t sample = FPGA_SSC_RX_Value();
|
||||
|
||||
while (IS_LOW(sample) && !IS_TIMEOUT(timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_TIMEOUT(timeout))
|
||||
return 0;
|
||||
|
||||
uint32_t start_ticks = GetTicks();
|
||||
|
||||
while (IS_HIGH(AT91C_BASE_SSC->SSC_RHR) && !IS_TIMEOUT(timeout));
|
||||
while (IS_HIGH(sample) && !IS_TIMEOUT(timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_TIMEOUT(timeout))
|
||||
return 0;
|
||||
|
||||
while (IS_LOW(AT91C_BASE_SSC->SSC_RHR) && !IS_TIMEOUT(timeout));
|
||||
while (IS_LOW(sample) && !IS_TIMEOUT(timeout)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
sample = FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_TIMEOUT(timeout))
|
||||
return 0;
|
||||
@@ -448,22 +481,22 @@ static void em4x70_send_bit(bool bit) {
|
||||
if (bit == 0) {
|
||||
|
||||
// disable modulation (drop the field) n cycles of carrier
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (TICKS_ELAPSED(start_ticks) <= EM4X70_T_TAG_BITMOD);
|
||||
|
||||
// enable modulation (activates the field) for remaining first
|
||||
// half of bit period
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (TICKS_ELAPSED(start_ticks) <= EM4X70_T_TAG_HALF_PERIOD);
|
||||
|
||||
// disable modulation for second half of bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (TICKS_ELAPSED(start_ticks) <= EM4X70_T_TAG_FULL_PERIOD);
|
||||
|
||||
} else {
|
||||
|
||||
// bit = "1" means disable modulation for full bit period
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (TICKS_ELAPSED(start_ticks) <= EM4X70_T_TAG_FULL_PERIOD);
|
||||
}
|
||||
log_sent_bit_end(GetTicks());
|
||||
|
||||
+3
-2
@@ -43,13 +43,14 @@
|
||||
#include "string.h"
|
||||
#include "mifareutil.h"
|
||||
#include "mifaresim.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "protocols.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "i2c_direct.h"
|
||||
|
||||
// Hardcoded response to the reader for file not found, plus the checksum
|
||||
|
||||
+3
-2
@@ -21,14 +21,15 @@
|
||||
#include "epa.h"
|
||||
|
||||
#include "cmd.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "iso14443a.h"
|
||||
#include "iso14443b.h"
|
||||
#include "string.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "commonutil.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
|
||||
#ifdef WITH_ISO14443a
|
||||
// Protocol and Parameter Selection Request for ISO 14443 type A cards
|
||||
|
||||
+24
-23
@@ -19,11 +19,12 @@
|
||||
#include "util.h"
|
||||
#include "protocols.h"
|
||||
#include "crc16.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "string.h"
|
||||
#include "commonutil.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "iso18.h"
|
||||
|
||||
#define AddCrc(data, len) compute_crc(CRC_FELICA, (data), (len), (data)+(len)+1, (data)+(len))
|
||||
@@ -416,8 +417,8 @@ void TransmitFor18092_AsReaderEx(const uint8_t *frame, uint16_t len, const uint3
|
||||
uint16_t c = 0;
|
||||
while (c < 6) {
|
||||
// keep tx buffer in a defined state anyway.
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00;
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(0x00);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
@@ -426,17 +427,17 @@ void TransmitFor18092_AsReaderEx(const uint8_t *frame, uint16_t len, const uint3
|
||||
|
||||
while (c < len) {
|
||||
// Put byte into tx holding register as soon as it is ready
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = frame[c++];
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(frame[c++]);
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) {};
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00; //minimum delay
|
||||
while (!FPGA_SSC_TX_Ready()) {};
|
||||
FPGA_SSC_TX_Value(0x00); //minimum delay
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) {};
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00; //spin
|
||||
while (!FPGA_SSC_TX_Ready()) {};
|
||||
FPGA_SSC_TX_Value(0x00); //spin
|
||||
/**/
|
||||
|
||||
const uint32_t frame_start = felica_lasttime_prox2air_start + (FELICA_PREAMBLE_BYTES * FELICA_BITS_PER_BYTE);
|
||||
@@ -475,7 +476,7 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
||||
FelicaFrameReset(&FelicaFrame);
|
||||
|
||||
// clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
uint8_t b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
(void)b;
|
||||
|
||||
uint32_t timeout = iso18092_get_timeout();
|
||||
@@ -484,9 +485,9 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
|
||||
b = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||
b = (uint8_t)(FPGA_SSC_RX_Value());
|
||||
|
||||
Process18092Byte(&FelicaFrame, b, felica_get_rx_byte_start_time());
|
||||
felica_frame_t *received = NULL;
|
||||
@@ -552,7 +553,7 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
||||
bool iso18092_setup_ex(uint8_t fpga_minor_mode, uint32_t preserve_low_bytes) {
|
||||
|
||||
LEDsoff();
|
||||
#if defined XC3
|
||||
#if defined XC3 || defined PM5
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
#else
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF_FELICA);
|
||||
@@ -576,13 +577,13 @@ bool iso18092_setup_ex(uint8_t fpga_minor_mode, uint32_t preserve_low_bytes) {
|
||||
init_table(CRC_FELICA);
|
||||
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
// Set up the synchronous serial port
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_ISO18092);
|
||||
|
||||
// LSB transfer. Remember to set it back to MSB with
|
||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
||||
// RX LSB transfer. TX MSB transfer, Remember to set it(RX) back to MSB with
|
||||
FpgaUpdateFrameMode(8, false, true);
|
||||
|
||||
// Signal field is on with the appropriate LED
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO18092 | fpga_minor_mode);
|
||||
@@ -605,8 +606,8 @@ void iso18092_setup(uint8_t fpga_minor_mode) {
|
||||
void felica_reset_frame_mode(void) {
|
||||
switch_off();
|
||||
felica_field_active = false;
|
||||
//Resetting Frame mode (First set in fpgaloader.c)
|
||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
||||
// Resetting Frame mode (First set in FpgaSetupSsc() function)
|
||||
FpgaUpdateFrameMode(8, true, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -780,9 +781,9 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
||||
}
|
||||
++checker;
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
|
||||
uint8_t dist = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||
uint8_t dist = (uint8_t)FPGA_SSC_RX_Value();
|
||||
Process18092Byte(&FelicaFrame, dist, felica_get_rx_byte_start_time());
|
||||
|
||||
if ((dist >= 178) && (++trigger_cnt > triggersToSkip)) {
|
||||
@@ -888,9 +889,9 @@ void felica_sim_lite(const uint8_t *uid) {
|
||||
|
||||
if (listenmode) {
|
||||
// waiting for request...
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
|
||||
uint8_t dist = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||
uint8_t dist = (uint8_t)(FPGA_SSC_RX_Value());
|
||||
// frtm = GetCountSspClk();
|
||||
Process18092Byte(&FelicaFrame, dist, felica_get_rx_byte_start_time());
|
||||
|
||||
|
||||
+5
-4
@@ -21,11 +21,12 @@
|
||||
#include "util.h"
|
||||
#include "protocols.h"
|
||||
#include "crc16.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "string.h"
|
||||
#include "commonutil.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "iso18.h"
|
||||
|
||||
#define AddCrc(data, len) compute_crc(CRC_FELICA, (data), (len), (data)+(len)+1, (data)+(len))
|
||||
@@ -879,8 +880,8 @@ static int felica_sim_standard_loop(const felica_sim_model_header_t *hdr, const
|
||||
}
|
||||
++checker;
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
uint8_t dist = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
uint8_t dist = (uint8_t)FPGA_SSC_RX_Value();
|
||||
Process18092Byte(&FelicaFrame, dist, felica_get_rx_byte_start_time());
|
||||
|
||||
if (FelicaFrame.state == STATE_FULL) {
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// See LICENSE.txt for the text of the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Routines to load the FPGA image, and then to configure the FPGA's major
|
||||
// mode once it is configured.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef __FPGALOADER_H
|
||||
#define __FPGALOADER_H
|
||||
|
||||
#include "common.h"
|
||||
#include "fpga.h"
|
||||
|
||||
#define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
|
||||
#define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
|
||||
|
||||
/*
|
||||
Communication between ARM / FPGA is done inside armsrc/fpgaloader.c see: function FpgaSendCommand()
|
||||
Send 16 bit command / data pair to FPGA with the bit format:
|
||||
|
||||
+------ frame layout circa 2020 ------------------+
|
||||
| 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
|
||||
+-------------------------------------------------+
|
||||
| C C C C M M M M P P P P P P P P | C = FPGA_CMD_SET_CONFREG, M = FPGA_MAJOR_MODE_*, P = FPGA_LF_* or FPGA_HF_* parameter
|
||||
| C C C C D D D D D D D D | C = FPGA_CMD_SET_DIVISOR, D = divisor
|
||||
| C C C C T T T T T T T T | C = FPGA_CMD_SET_EDGE_DETECT_THRESHOLD, T = threshold
|
||||
| C C C C E | C = FPGA_CMD_TRACE_ENABLE, E=0 off, E=1 on
|
||||
+-------------------------------------------------+
|
||||
|
||||
+------ frame layout current ---------------------+
|
||||
| 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
|
||||
+-------------------------------------------------+
|
||||
| C C C C M M M P P P P P P | C = FPGA_CMD_SET_CONFREG, M = FPGA_MAJOR_MODE_*, P = FPGA_LF_* or FPGA_HF_* parameter
|
||||
| C C C C D D D D D D D D | C = FPGA_CMD_SET_DIVISOR, D = divisor
|
||||
| C C C C T T T T T T T T | C = FPGA_CMD_SET_EDGE_DETECT_THRESHOLD, T = threshold
|
||||
| C C C C E | C = FPGA_CMD_TRACE_ENABLE, E=0 off, E=1 on
|
||||
+-------------------------------------------------+
|
||||
|
||||
shift_reg receive this 16bit frame
|
||||
|
||||
LF command
|
||||
----------
|
||||
shift_reg[15:12] == 4bit command
|
||||
LF has three commands (FPGA_CMD_SET_CONFREG, FPGA_CMD_SET_DIVISOR, FPGA_CMD_SET_EDGE_DETECT_THRESHOLD)
|
||||
Current commands uses only 2bits. We have room for up to 4bits of commands total (7).
|
||||
|
||||
LF data
|
||||
-------
|
||||
shift_reg[11:0] == 12bit data
|
||||
lf data is divided into MAJOR MODES and configuration values.
|
||||
|
||||
The major modes uses 3bits (0,1,2,3,7 | 000, 001, 010, 011, 111)
|
||||
000 FPGA_MAJOR_MODE_LF_READER = Act as LF reader (modulate)
|
||||
001 FPGA_MAJOR_MODE_LF_EDGE_DETECT = Simulate LF
|
||||
010 FPGA_MAJOR_MODE_LF_PASSTHRU = Passthrough mode, CROSS_LO line connected to SSP_DIN. SSP_DOUT logic level controls if we modulate / listening
|
||||
011 FPGA_MAJOR_MODE_LF_ADC = refactor hitag 2, clear ADC sampling
|
||||
111 FPGA_MAJOR_MODE_OFF = turn off sampling.
|
||||
|
||||
Each one of this major modes can have options. Currently these two major modes uses options.
|
||||
- FPGA_MAJOR_MODE_LF_READER
|
||||
- FPGA_MAJOR_MODE_LF_EDGE_DETECT
|
||||
|
||||
FPGA_MAJOR_MODE_LF_READER
|
||||
-------------------------------------
|
||||
lf_field = 1bit (FPGA_LF_ADC_READER_FIELD)
|
||||
|
||||
You can send FPGA_CMD_SET_DIVISOR to set with FREQUENCY the fpga should sample at
|
||||
divisor = 8bits shift_reg[7:0]
|
||||
|
||||
FPGA_MAJOR_MODE_LF_EDGE_DETECT
|
||||
------------------------------------------
|
||||
lf_ed_toggle_mode = 1bits
|
||||
lf_ed_threshold = 8bits threshold defaults to 127
|
||||
|
||||
You can send FPGA_CMD_SET_EDGE_DETECT_THRESHOLD to set a custom threshold
|
||||
lf_ed_threshold = 8bits threshold value.
|
||||
|
||||
conf_word 12bits
|
||||
conf_word[7:5] = 3bit major mode.
|
||||
conf_word[0] = 1bit lf_field
|
||||
conf_word[1] = 1bit lf_ed_toggle_mode
|
||||
conf_word[7:0] = 8bit divisor
|
||||
conf_word[7:0] = 8bit threshold
|
||||
|
||||
*/
|
||||
// Defining commands, modes and options. This must be aligned to the definitions in fpga/define.v
|
||||
#define FPGA_MAJOR_MODE_MASK 0x01C0
|
||||
#define FPGA_MINOR_MODE_MASK 0x003F
|
||||
|
||||
// Definitions for the FPGA commands.
|
||||
#define FPGA_CMD_SET_CONFREG (1<<12)
|
||||
#define FPGA_CMD_SET_DIVISOR (2<<12)
|
||||
#define FPGA_CMD_SET_EDGE_DETECT_THRESHOLD (3<<12)
|
||||
#define FPGA_CMD_TRACE_ENABLE (2<<12)
|
||||
|
||||
// Major modes
|
||||
#define FPGA_MAJOR_MODE_LF_READER (0<<6)
|
||||
#define FPGA_MAJOR_MODE_LF_EDGE_DETECT (1<<6)
|
||||
#define FPGA_MAJOR_MODE_LF_PASSTHRU (2<<6)
|
||||
#define FPGA_MAJOR_MODE_LF_ADC (3<<6)
|
||||
|
||||
#define FPGA_MAJOR_MODE_HF_READER (0<<6)
|
||||
#define FPGA_MAJOR_MODE_HF_SIMULATOR (1<<6)
|
||||
#define FPGA_MAJOR_MODE_HF_ISO14443A (2<<6)
|
||||
#define FPGA_MAJOR_MODE_HF_SNIFF (3<<6)
|
||||
#define FPGA_MAJOR_MODE_HF_ISO18092 (4<<6)
|
||||
#define FPGA_MAJOR_MODE_HF_GET_TRACE (5<<6)
|
||||
#define FPGA_MAJOR_MODE_OFF (7<<6)
|
||||
|
||||
// Options for LF_READER
|
||||
#define FPGA_LF_ADC_READER_FIELD ( 1 )
|
||||
|
||||
// Options for LF_EDGE_DETECT
|
||||
#define FPGA_LF_EDGE_DETECT_READER_FIELD ( 1 )
|
||||
#define FPGA_LF_EDGE_DETECT_TOGGLE_MODE ( 2 )
|
||||
|
||||
// Options for the generic HF reader
|
||||
#define FPGA_HF_READER_MODE_RECEIVE_IQ ( 0 )
|
||||
#define FPGA_HF_READER_MODE_RECEIVE_AMPLITUDE ( 1 )
|
||||
#define FPGA_HF_READER_MODE_RECEIVE_PHASE ( 2 )
|
||||
#define FPGA_HF_READER_MODE_SEND_FULL_MOD ( 3 )
|
||||
#define FPGA_HF_READER_MODE_SEND_SHALLOW_MOD ( 4 )
|
||||
#define FPGA_HF_READER_MODE_SNIFF_IQ ( 5 )
|
||||
#define FPGA_HF_READER_MODE_SNIFF_AMPLITUDE ( 6 )
|
||||
#define FPGA_HF_READER_MODE_SNIFF_PHASE ( 7 )
|
||||
#define FPGA_HF_READER_MODE_SEND_JAM ( 8 )
|
||||
#define FPGA_HF_READER_MODE_SEND_SHALLOW_MOD_RDV4 ( 9 )
|
||||
|
||||
#define FPGA_HF_READER_SUBCARRIER_848_KHZ (0<<4)
|
||||
#define FPGA_HF_READER_SUBCARRIER_424_KHZ (1<<4)
|
||||
#define FPGA_HF_READER_SUBCARRIER_212_KHZ (2<<4)
|
||||
#define FPGA_HF_READER_2SUBCARRIERS_424_484_KHZ (3<<4)
|
||||
|
||||
// Options for the HF simulated tag, how to modulate
|
||||
#define FPGA_HF_SIMULATOR_NO_MODULATION ( 0 )
|
||||
#define FPGA_HF_SIMULATOR_MODULATE_BPSK ( 1 )
|
||||
#define FPGA_HF_SIMULATOR_MODULATE_212K ( 2 )
|
||||
#define FPGA_HF_SIMULATOR_MODULATE_424K ( 4 )
|
||||
#define FPGA_HF_SIMULATOR_MODULATE_424K_8BIT ( 5 )
|
||||
|
||||
// Options for ISO14443A
|
||||
#define FPGA_HF_ISO14443A_SNIFFER ( 0 )
|
||||
#define FPGA_HF_ISO14443A_TAGSIM_LISTEN ( 1 )
|
||||
#define FPGA_HF_ISO14443A_TAGSIM_MOD ( 2 )
|
||||
#define FPGA_HF_ISO14443A_READER_LISTEN ( 3 )
|
||||
#define FPGA_HF_ISO14443A_READER_MOD ( 4 )
|
||||
|
||||
// Options for ISO18092 / Felica
|
||||
#define FPGA_HF_ISO18092_FLAG_NOMOD ( 1 ) // 0001 disable modulation module
|
||||
#define FPGA_HF_ISO18092_FLAG_424K ( 2 ) // 0010 should enable 414k mode (untested). No autodetect
|
||||
#define FPGA_HF_ISO18092_FLAG_READER ( 4 ) // 0100 enables antenna power, to act as a reader instead of tag
|
||||
|
||||
void FpgaSendCommand(uint16_t cmd, uint16_t v);
|
||||
void FpgaWriteConfWord(uint16_t v);
|
||||
void FpgaEnableTracing(void);
|
||||
void FpgaDisableTracing(void);
|
||||
void FpgaDownloadAndGo(int bitstream_target);
|
||||
void FpgaDownloadAndGo_keep_EM(int bitstream_target);
|
||||
// void FpgaGatherVersion(int bitstream_target, char *dst, int len);
|
||||
void FpgaSetupSsc(uint16_t fpga_mode);
|
||||
void SetupSpi(int mode);
|
||||
bool FpgaSetupSscDma(uint8_t *buf, uint16_t len);
|
||||
void Fpga_print_status(void);
|
||||
int FpgaGetCurrent(void);
|
||||
void FpgaResetBitstream(void);
|
||||
void SetAdcMuxFor(uint32_t whichGpio);
|
||||
|
||||
// extern and generel turn off the antenna method
|
||||
void switch_off(void);
|
||||
|
||||
#endif
|
||||
+11
-9
@@ -23,8 +23,10 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "rssi_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
@@ -35,7 +37,7 @@ int HfReadADC(uint32_t samplesCount, bool ledcontrol) {
|
||||
|
||||
BigBuf_Clear_ext(false);
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
// And put the FPGA in the appropriate mode
|
||||
@@ -55,8 +57,8 @@ int HfReadADC(uint32_t samplesCount, bool ledcontrol) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
volatile uint16_t sample = AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint16_t sample = FPGA_SSC_RX_Value();
|
||||
|
||||
// FPGA side:
|
||||
// corr_i_out <= {2'b00, corr_amplitude[13:8]};
|
||||
@@ -216,7 +218,7 @@ int HfSimulateTkm(const uint8_t *uid, uint8_t modulation, uint32_t timeout) {
|
||||
|
||||
LED_C_ON();
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR | FPGA_HF_SIMULATOR_MODULATE_212K);
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR);
|
||||
|
||||
@@ -238,7 +240,7 @@ int HfSimulateTkm(const uint8_t *uid, uint8_t modulation, uint32_t timeout) {
|
||||
break;
|
||||
|
||||
// in mV
|
||||
int vHf = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
uint32_t vHf = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);
|
||||
if (vHf > MF_MINFIELDV) {
|
||||
if (field_on == false) {
|
||||
LED_A_ON();
|
||||
@@ -256,8 +258,8 @@ int HfSimulateTkm(const uint8_t *uid, uint8_t modulation, uint32_t timeout) {
|
||||
SpinDelay(3);
|
||||
|
||||
for (int i = 0; i < elen;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||
AT91C_BASE_SSC->SSC_THR = data[i++];
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(data[i++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-23
@@ -18,8 +18,9 @@
|
||||
#include "hfsnoop.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "fpga.h"
|
||||
@@ -28,8 +29,8 @@
|
||||
|
||||
static void RAMFUNC optimizedSniff(uint16_t *dest, uint16_t dsize) {
|
||||
while (dsize > 0) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
*dest = (uint16_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
*dest = (uint16_t)(FPGA_SSC_RX_Value());
|
||||
dest++;
|
||||
dsize -= sizeof(dsize);
|
||||
}
|
||||
@@ -40,8 +41,8 @@ static void RAMFUNC skipSniff(uint8_t *dest, uint16_t dsize, uint8_t skipMode, u
|
||||
uint32_t accum = (skipMode == HF_SNOOP_SKIP_MIN) ? 0xffffffff : 0;
|
||||
uint8_t ratioindx = 0;
|
||||
while (dsize > 0) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
volatile uint16_t val = (uint16_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint16_t val = (uint16_t)(FPGA_SSC_RX_Value());
|
||||
switch (skipMode) {
|
||||
case HF_SNOOP_SKIP_MAX:
|
||||
if (accum < (val & 0xff))
|
||||
@@ -95,13 +96,13 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len, uint
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
// Set up the synchronous serial port
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SNIFF);
|
||||
|
||||
// Setting Frame Mode For better performance on high speed data transfer.
|
||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16);
|
||||
FpgaUpdateFrameMode(16, false, false);
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SNIFF);
|
||||
SpinDelay(100);
|
||||
@@ -127,8 +128,8 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len, uint
|
||||
}
|
||||
|
||||
// check if trigger is reached
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
r = (uint16_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
r = (uint16_t)FPGA_SSC_RX_Value();
|
||||
|
||||
r = MAX(r & 0xFF, r >> 8);
|
||||
|
||||
@@ -149,7 +150,7 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len, uint
|
||||
// skip samples loop
|
||||
while (samplesToSkip != 0) {
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
samplesToSkip--;
|
||||
}
|
||||
}
|
||||
@@ -165,8 +166,8 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len, uint
|
||||
}
|
||||
}
|
||||
|
||||
//Resetting Frame mode (First set in fpgaloader.c)
|
||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
||||
// Resetting Frame mode (First set in FpgaSetupSsc() function)
|
||||
FpgaUpdateFrameMode(8, true, true);
|
||||
LED_D_OFF();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
BigBuf_free();
|
||||
@@ -182,25 +183,20 @@ void HfPlotDownload(void) {
|
||||
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_GET_TRACE);
|
||||
|
||||
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) this_buf; // start transfer to this memory address
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = PM3_CMD_DATA_SIZE; // transfer this many samples
|
||||
ts->buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register
|
||||
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // Start DMA transfer
|
||||
FpgaSetupSscRxDmaSingle(this_buf, PM3_CMD_DATA_SIZE);
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_GET_TRACE); // let FPGA transfer its internal Block-RAM
|
||||
|
||||
LED_B_ON();
|
||||
for (size_t i = 0; i < FPGA_TRACE_SIZE; i += PM3_CMD_DATA_SIZE) {
|
||||
size_t len = MIN(FPGA_TRACE_SIZE - i, PM3_CMD_DATA_SIZE);
|
||||
// prepare next DMA transfer:
|
||||
uint8_t *next_buf = ts->buf + ((i + PM3_CMD_DATA_SIZE) % (2 * PM3_CMD_DATA_SIZE));
|
||||
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)next_buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = PM3_CMD_DATA_SIZE;
|
||||
while (!FPGA_SSC_DMA_RX_Done()) {}; // wait for DMA transfer to complete
|
||||
|
||||
size_t len = MIN(FPGA_TRACE_SIZE - i, PM3_CMD_DATA_SIZE);
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX))) {}; // wait for DMA transfer to complete
|
||||
// The main buf has stopped receiving, so it needs to be refreshed.
|
||||
FPGA_SSC_DMA_RX_Refresh_Single(next_buf, PM3_CMD_DATA_SIZE);
|
||||
|
||||
reply_old(CMD_FPGAMEM_DOWNLOADED, i, len, FPGA_TRACE_SIZE, this_buf, len);
|
||||
this_buf = next_buf;
|
||||
|
||||
+49
-134
@@ -20,8 +20,9 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "lfadc.h"
|
||||
@@ -96,7 +97,6 @@ static uint8_t key_no;
|
||||
static uint64_t cipher_state;
|
||||
|
||||
static int16_t blocknr;
|
||||
static size_t flipped_bit = 0;
|
||||
static uint32_t byte_value = 0;
|
||||
|
||||
static void hitag2_reset(void) {
|
||||
@@ -108,12 +108,11 @@ static void hitag2_init(void) {
|
||||
hitag2_reset();
|
||||
}
|
||||
|
||||
// Sam7s has several timers, we will use the source TIMER_CLOCK1 (aka AT91C_TC_CLKS_TIMER_DIV1_CLOCK)
|
||||
// TIMER_CLOCK1 = MCK/2, MCK is running at 48 MHz, Timer is running at 48/2 = 24 MHz
|
||||
// Hitag units (T0) have duration of 8 microseconds (us), which is 1/125000 per second (carrier)
|
||||
// T0 = TIMER_CLOCK1 / 125000 = 192
|
||||
// The input-capture timer (StartInputCapture, see common_arm/ticks) runs at
|
||||
// TIMER_CLOCK3 = MCK/32 = 1.5 MHz. Hitag units (T0) have a duration of 8 us
|
||||
// (1/125000 s, the carrier period), so T0 = 1.5 MHz / 125 kHz = 12 counter ticks.
|
||||
#ifndef HITAG_T0
|
||||
#define HITAG_T0 192
|
||||
#define HITAG_T0 12
|
||||
#endif
|
||||
|
||||
#define HITAG_FRAME_LEN 20
|
||||
@@ -147,50 +146,6 @@ static void hitag2_init(void) {
|
||||
|
||||
#define HT2_MAX_NRSZ ((8 * HITAG_FRAME_LEN + 5) * 2)
|
||||
|
||||
/*
|
||||
// sim
|
||||
static void hitag_send_bit(int bit, bool ledcontrol) {
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
// Reset clock for the next bit
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
|
||||
// Fixed modulation, earlier proxmark version used inverted signal
|
||||
// check datasheet if reader uses BiPhase?
|
||||
if (bit == 0) {
|
||||
// Manchester: Unloaded, then loaded |__--|
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < HITAG_T0 * HITAG_T_TAG_HALF_PERIOD);
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < HITAG_T0 * HITAG_T_TAG_FULL_PERIOD);
|
||||
} else {
|
||||
// Manchester: Loaded, then unloaded |--__|
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < HITAG_T0 * HITAG_T_TAG_HALF_PERIOD);
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < HITAG_T0 * HITAG_T_TAG_FULL_PERIOD);
|
||||
}
|
||||
if (ledcontrol) LED_A_OFF();
|
||||
}
|
||||
|
||||
// sim
|
||||
static void hitag_send_frame(const uint8_t *frame, size_t frame_len) {
|
||||
// SOF - send start of frame
|
||||
hitag_send_bit(1);
|
||||
hitag_send_bit(1);
|
||||
hitag_send_bit(1);
|
||||
hitag_send_bit(1);
|
||||
hitag_send_bit(1);
|
||||
|
||||
// Send the content of the frame
|
||||
for (size_t i = 0; i < frame_len; i++) {
|
||||
hitag_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
|
||||
}
|
||||
|
||||
// Drop the modulation
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
}
|
||||
*/
|
||||
|
||||
// sim
|
||||
static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
|
||||
@@ -1053,7 +1008,7 @@ void hitag_sniff(void) {
|
||||
// and analog mux selection.
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE);
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); // 125Khz
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
RELAY_OFF();
|
||||
|
||||
}
|
||||
@@ -1074,7 +1029,7 @@ void SniffHitag2(bool ledcontrol) {
|
||||
set_tracing(true);
|
||||
|
||||
/*
|
||||
lf_init(false, false, ledcontrol);
|
||||
lf_init(LF_ADC_SNIFF, LF_ADC_WAV_REVERSED, ledcontrol);
|
||||
|
||||
// no logging of the raw signal
|
||||
g_logging = true;
|
||||
@@ -1216,7 +1171,7 @@ void SniffHitag2(bool ledcontrol) {
|
||||
// and analog mux selection.
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE);
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); // 125Khz
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
RELAY_OFF();
|
||||
|
||||
// Configure output pin that is connected to the FPGA (for modulating)
|
||||
@@ -1224,30 +1179,16 @@ void SniffHitag2(bool ledcontrol) {
|
||||
// AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
|
||||
// Disable modulation, we are going to eavesdrop, not modulate ;)
|
||||
// LOW(GPIO_SSC_DOUT);
|
||||
// Gpio_SSC_DOUT_Low();
|
||||
|
||||
// Enable Peripheral Clock for TIMER_CLOCK1, used to capture edges of the reader frames
|
||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC1);
|
||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
||||
|
||||
// Disable timer during configuration
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
|
||||
// Capture mode, default timer source = MCK/2 (TIMER_CLOCK1), TIOA is external trigger,
|
||||
// external trigger rising edge, load RA on rising edge of TIOA.
|
||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK | AT91C_TC_ETRGEDG_BOTH | AT91C_TC_ABETRG | AT91C_TC_LDRA_BOTH;
|
||||
|
||||
// Enable and reset counter
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
|
||||
// Assert a sync signal. This sets all timers to 0 on next active clock edge
|
||||
AT91C_BASE_TCB->TCB_BCR = 1;
|
||||
// Configure the input capture (TC1) via the HAL: it enables the TC1 clock, routes
|
||||
// SSC_FRAME to the timer input, resets on each falling edge and captures RB
|
||||
// (falling->falling) / RA (falling->rising).
|
||||
StartLoEdgeCapture();
|
||||
|
||||
int frame_count = 0, response = 0, lastbit = 1, tag_sof = 4;
|
||||
int overflow = 0;
|
||||
bool rising_edge, reader_frame = false, bSkip = true;
|
||||
bool reader_frame = false, bSkip = true;
|
||||
|
||||
// bool exit_due_to_overflow;
|
||||
// HACK -- add one byte to avoid rewriting manchester decoder for edge case
|
||||
uint8_t rx[HITAG_FRAME_LEN + 1] = {0};
|
||||
size_t rxlen = 0;
|
||||
@@ -1261,57 +1202,45 @@ void SniffHitag2(bool ledcontrol) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
// bool exit_due_to_overflow = false;
|
||||
// Receive frame, watch for at most HITAG_T0 * HITAG_T_EOF periods since the last edge
|
||||
while (GetLoEdgeCaptureCount() < (HITAG_T0 * HITAG_T_EOF)) {
|
||||
|
||||
// Receive frame, watch for at most T0 * EOF periods
|
||||
while (AT91C_BASE_TC1->TC_CV < (HITAG_T0 * HITAG_T_EOF)) {
|
||||
// Read (and clear) the input-capture edge-event flags.
|
||||
lo_edge_t lo_edge = GetLoEdgeCaptureStatus();
|
||||
|
||||
// Check if rising edge in modulation is detected
|
||||
if (AT91C_BASE_TC1->TC_SR & AT91C_TC_LDRAS) {
|
||||
// Rising edge: RA holds the falling->rising sub-period (the reader's tlow).
|
||||
if (lo_edge == LO_EDGE_RISING) {
|
||||
int ra = GetLoEdgeCaptureRising() / HITAG_T0;
|
||||
|
||||
// Retrieve the new timing values
|
||||
int ra = (AT91C_BASE_TC1->TC_RA / HITAG_T0) + overflow;
|
||||
overflow = 0;
|
||||
|
||||
// Find out if we are dealing with a rising or falling edge
|
||||
rising_edge = (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME) > 0;
|
||||
|
||||
// Shorter periods will only happen with reader frames
|
||||
if (reader_frame == false && rising_edge && ra < HITAG_T_TAG_CAPTURE_ONE_HALF) {
|
||||
// Shorter periods only happen with reader frames (reader tlow is 4..10 T0,
|
||||
// while the shortest tag Manchester half-period is 16 T0).
|
||||
if (reader_frame == false && ra < HITAG_T_TAG_CAPTURE_ONE_HALF) {
|
||||
// Switch from tag to reader capture
|
||||
if (ledcontrol) LED_C_OFF();
|
||||
reader_frame = true;
|
||||
rxlen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Only handle if reader frame and rising edge, or tag frame and falling edge
|
||||
if (reader_frame != rising_edge) {
|
||||
overflow += ra;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add the buffered timing values of earlier captured edges which were skipped
|
||||
ra += overflow;
|
||||
overflow = 0;
|
||||
// Falling edge: RB holds the falling->falling full period (the bit timing).
|
||||
if (lo_edge == LO_EDGE_FALLING) {
|
||||
int rb = GetLoEdgeCaptureFalling() / HITAG_T0;
|
||||
|
||||
if (reader_frame) {
|
||||
|
||||
if (ledcontrol) LED_B_ON();
|
||||
// Capture reader frame
|
||||
if (ra >= HITAG_T_STOP) {
|
||||
// if (rxlen != 0) {
|
||||
//DbpString("wierd0?");
|
||||
// }
|
||||
if (rb >= HITAG_T_STOP) {
|
||||
// Capture the T0 periods that have passed since last communication or field drop (reset)
|
||||
response = (ra - HITAG_T_LOW);
|
||||
if (rxlen != 0) { Dbprintf("ra - HITAG_T_LOW... %i", response); }
|
||||
response = (rb - HITAG_T_LOW);
|
||||
if (rxlen != 0) { Dbprintf("rb - HITAG_T_LOW... %i", response); }
|
||||
|
||||
} else if (ra >= HITAG_T_1_MIN) {
|
||||
} else if (rb >= HITAG_T_1_MIN) {
|
||||
// '1' bit
|
||||
rx[rxlen / 8] |= 1 << (7 - (rxlen % 8));
|
||||
rxlen++;
|
||||
|
||||
} else if (ra >= HITAG_T_0_MIN) {
|
||||
} else if (rb >= HITAG_T_0_MIN) {
|
||||
// '0' bit
|
||||
rx[rxlen / 8] |= 0 << (7 - (rxlen % 8));
|
||||
rxlen++;
|
||||
@@ -1320,22 +1249,19 @@ void SniffHitag2(bool ledcontrol) {
|
||||
} else {
|
||||
if (ledcontrol) LED_C_ON();
|
||||
// Capture tag frame (manchester decoding using only falling edges)
|
||||
if (ra >= HITAG_T_EOF) {
|
||||
// if (rxlen != 0) {
|
||||
//DbpString("wierd1?");
|
||||
// }
|
||||
if (rb >= HITAG_T_EOF) {
|
||||
// Capture the T0 periods that have passed since last communication or field drop (reset)
|
||||
// We always receive a 'one' first, which has the falling edge after a half period |-_|
|
||||
response = ra - HITAG_T_TAG_HALF_PERIOD;
|
||||
response = rb - HITAG_T_TAG_HALF_PERIOD;
|
||||
|
||||
} else if (ra >= HITAG_T_TAG_CAPTURE_FOUR_HALF) {
|
||||
} else if (rb >= HITAG_T_TAG_CAPTURE_FOUR_HALF) {
|
||||
// Manchester coding example |-_|_-|-_| (101)
|
||||
rx[rxlen / 8] |= 0 << (7 - (rxlen % 8));
|
||||
rxlen++;
|
||||
rx[rxlen / 8] |= 1 << (7 - (rxlen % 8));
|
||||
rxlen++;
|
||||
|
||||
} else if (ra >= HITAG_T_TAG_CAPTURE_THREE_HALF) {
|
||||
} else if (rb >= HITAG_T_TAG_CAPTURE_THREE_HALF) {
|
||||
// Manchester coding example |_-|...|_-|-_| (0...01)
|
||||
rx[rxlen / 8] |= 0 << (7 - (rxlen % 8));
|
||||
rxlen++;
|
||||
@@ -1347,7 +1273,7 @@ void SniffHitag2(bool ledcontrol) {
|
||||
lastbit = !lastbit;
|
||||
bSkip = !bSkip;
|
||||
|
||||
} else if (ra >= HITAG_T_TAG_CAPTURE_TWO_HALF) {
|
||||
} else if (rb >= HITAG_T_TAG_CAPTURE_TWO_HALF) {
|
||||
// Manchester coding example |_-|_-| (00) or |-_|-_| (11)
|
||||
if (tag_sof) {
|
||||
// Ignore bits that are transmitted during SOF
|
||||
@@ -1387,32 +1313,24 @@ void SniffHitag2(bool ledcontrol) {
|
||||
lastbit = 1;
|
||||
bSkip = true;
|
||||
tag_sof = 4;
|
||||
overflow = 0;
|
||||
|
||||
if (ledcontrol) {
|
||||
LED_B_OFF();
|
||||
LED_C_OFF();
|
||||
}
|
||||
|
||||
} else {
|
||||
// Save the timer overflow, will be 0 when frame was received
|
||||
overflow += (AT91C_BASE_TC1->TC_CV / HITAG_T0);
|
||||
}
|
||||
|
||||
// Reset the frame length
|
||||
rxlen = 0;
|
||||
|
||||
// Reset the timer to restart while-loop that receives frames
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
|
||||
|
||||
// Assert a sync signal. This sets all timers to 0 on next active clock edge
|
||||
AT91C_BASE_TCB->TCB_BCR = 1;
|
||||
// Reset the capture counter to restart the while-loop that receives frames.
|
||||
ResetLoEdgeCapture();
|
||||
}
|
||||
|
||||
if (ledcontrol) LEDsoff();
|
||||
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||
StopLoEdgeCapture();
|
||||
|
||||
DBG Dbprintf("frames.......... %d", frame_count);
|
||||
Dbprintf("Auth attempts... %d", (auth_table_len / 8));
|
||||
@@ -1430,7 +1348,7 @@ void SimulateHitag2(bool ledcontrol) {
|
||||
set_tracing(true);
|
||||
|
||||
// empties bigbuff etc
|
||||
lf_init(false, true, ledcontrol);
|
||||
lf_init(LF_ADC_TAG_SIM, LF_ADC_WAV_REVERSED, ledcontrol);
|
||||
|
||||
int response = 0;
|
||||
uint8_t rx[HITAG_FRAME_LEN] = {0};
|
||||
@@ -1619,7 +1537,6 @@ void SimulateHitag2(bool ledcontrol) {
|
||||
// Send and store the tag answer (if there is any)
|
||||
if (txlen) {
|
||||
// Transmit the tag frame
|
||||
//hitag_send_frame(tx, txlen);
|
||||
lf_manchester_send_bytes(tx, txlen, ledcontrol);
|
||||
|
||||
// Store the frame in the trace
|
||||
@@ -1777,7 +1694,6 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
||||
t_wait_1 = 204;
|
||||
t_wait_2 = 128;
|
||||
tag_size = 256;
|
||||
flipped_bit = 0;
|
||||
DBG DbpString("Configured for " _YELLOW_("Hitag 1") " reader");
|
||||
} else if (payload->cmd <= HT2_LAST_CMD) {
|
||||
// hitag 2 settings
|
||||
@@ -1788,7 +1704,7 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
||||
}
|
||||
|
||||
// init as reader
|
||||
lf_init(true, false, ledcontrol);
|
||||
lf_init(LF_ADC_READER, LF_ADC_WAV_REVERSED, ledcontrol);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
|
||||
uint8_t tag_modulation;
|
||||
@@ -2127,7 +2043,7 @@ void WriterHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
||||
hitag2_init();
|
||||
|
||||
// init as reader
|
||||
lf_init(true, false, ledcontrol);
|
||||
lf_init(LF_ADC_READER, LF_ADC_WAV_REVERSED, ledcontrol);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
|
||||
// Tag specific configuration settings (sof, timings, etc.)
|
||||
@@ -2147,7 +2063,6 @@ void WriterHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
||||
t_wait_1 = 204;
|
||||
t_wait_2 = 128;
|
||||
tag_size = 256;
|
||||
flipped_bit = 0;
|
||||
DBG DbpString("Configured for " _YELLOW_("Hitag 1") " writer");
|
||||
} else if (payload->cmd <= HT2_LAST_CMD) {
|
||||
// hitag 2 settings
|
||||
@@ -2591,6 +2506,7 @@ bool ht2_packbits(uint8_t *nrz_samples, size_t nrzs, uint8_t *rx, size_t *rxlen)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int ht2_read_uid(uint8_t *uid, bool ledcontrol, bool send_answer, bool keep_field_up) {
|
||||
|
||||
g_logging = false;
|
||||
@@ -2600,12 +2516,11 @@ int ht2_read_uid(uint8_t *uid, bool ledcontrol, bool send_answer, bool keep_fiel
|
||||
clear_trace();
|
||||
}
|
||||
|
||||
|
||||
// hitag 2 state machine?
|
||||
hitag2_init();
|
||||
|
||||
// init as reader
|
||||
lf_init(true, false, true);
|
||||
lf_init(LF_ADC_READER, LF_ADC_WAV_REVERSED, true);
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
|
||||
@@ -2642,7 +2557,7 @@ int ht2_read_uid(uint8_t *uid, bool ledcontrol, bool send_answer, bool keep_fiel
|
||||
|
||||
// receive raw samples
|
||||
if (ht2_receive(&response_start, &response_duration, nrz_samples, &nrzs) == false) {
|
||||
continue;;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Store the transmit frame ( TX ), we do this now at this point, to avoid delay in processing
|
||||
|
||||
+12
-11
@@ -24,8 +24,9 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
@@ -56,7 +57,7 @@ static int block_data_left = 0;
|
||||
static bool enable_page_tearoff = false;
|
||||
|
||||
static uint8_t protocol_mode = HITAGS_UID_REQ_ADV1;
|
||||
static MOD m = AC2K; // used modulation
|
||||
static hitag_mod_t m = AC2K; // used modulation
|
||||
static uint32_t reader_selected_uid;
|
||||
static int rotate_uid = 0;
|
||||
static int sof_bits; // number of start-of-frame bits
|
||||
@@ -423,7 +424,7 @@ void hts_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
LogTraceBits(rx, rxlen, start_time, TIMESTAMP, true);
|
||||
|
||||
// Disable timer 1 with external trigger to avoid triggers during our own modulation
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
StopLoEdgeCapture();
|
||||
|
||||
// Process the incoming frame (rx) and prepare the outgoing frame (tx)
|
||||
hts_handle_reader_command(rx, rxlen, tx, &txlen);
|
||||
@@ -433,7 +434,7 @@ void hts_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
// with respect to the falling edge, we need to wait actually (T_Wait1 - T_Low)
|
||||
// periods. The gap time T_Low varies (4..10). All timer values are in
|
||||
// terms of T0 units
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * (HITAG_T_WAIT_RESP - HITAG_T_LOW)) {};
|
||||
while (GetPrecisionCounter() < T0 * (HITAG_T_WAIT_RESP - HITAG_T_LOW)) {};
|
||||
|
||||
// Send and store the tag answer (if there is any)
|
||||
if (txlen > 0) {
|
||||
@@ -444,7 +445,7 @@ void hts_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
}
|
||||
|
||||
// Enable and reset external trigger in timer for capturing future frames
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
EnableLoEdgeCapture();
|
||||
|
||||
// Reset the received frame and response timing info
|
||||
memset(rx, 0x00, sizeof(rx));
|
||||
@@ -454,9 +455,9 @@ void hts_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
// Reset the frame length
|
||||
rxlen = 0;
|
||||
// Save the timer overflow, will be 0 when frame was received
|
||||
overflow += (AT91C_BASE_TC1->TC_CV / T0);
|
||||
overflow += (GetLoEdgeCaptureCount() / T0);
|
||||
// Reset the timer to restart while-loop that receives frames
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
|
||||
ResetLoEdgeCapture();
|
||||
|
||||
}
|
||||
|
||||
@@ -472,7 +473,7 @@ static int hts_send_receive(const uint8_t *tx, size_t txlen, uint8_t *rx, size_t
|
||||
|
||||
// Send and store the reader command
|
||||
// Disable timer 1 with external trigger to avoid triggers during our own modulation
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
StopLoEdgeCapture();
|
||||
|
||||
DBG Dbprintf("tx %d bits:", txlen);
|
||||
DBG Dbhexdump((txlen + 7) / 8, tx, false);
|
||||
@@ -482,7 +483,7 @@ static int hts_send_receive(const uint8_t *tx, size_t txlen, uint8_t *rx, size_t
|
||||
// falling edge occurred halfway the period. with respect to this falling edge,
|
||||
// we need to wait (T_Wait2 + half_tag_period) when the last was a 'one'.
|
||||
// All timer values are in terms of T0 units
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * t_wait) {};
|
||||
while (GetPrecisionCounter() < T0 * t_wait) {};
|
||||
|
||||
start_time = TIMESTAMP;
|
||||
|
||||
@@ -496,7 +497,7 @@ static int hts_send_receive(const uint8_t *tx, size_t txlen, uint8_t *rx, size_t
|
||||
LogTraceBits(tx, txlen, start_time, TIMESTAMP, true);
|
||||
|
||||
// Enable and reset external trigger in timer for capturing future frames
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
EnableLoEdgeCapture();
|
||||
|
||||
hts_set_frame_modulation(protocol_mode, ac_seq);
|
||||
|
||||
|
||||
+162
-143
@@ -21,8 +21,9 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
@@ -33,56 +34,6 @@
|
||||
#include "protocols.h"
|
||||
#include "appmain.h" // tearoff_hook()
|
||||
|
||||
uint16_t timestamp_high = 0; // Timer Counter 2 overflow count, combined with TC2 counter for ~47min timing
|
||||
|
||||
static void hitag_stop_clock(void) {
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKDIS;
|
||||
}
|
||||
|
||||
static void hitag_init_clock(void) {
|
||||
// Enable Peripheral Clock for
|
||||
// Timer Counter 0, used to measure exact timing before answering
|
||||
// Timer Counter 1, used to capture edges of the tag frames
|
||||
// Timer Counter 2, used to log trace time
|
||||
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1) | (1 << AT91C_ID_TC2);
|
||||
|
||||
AT91C_BASE_PIOA->PIO_BSR = GPIO_SSC_FRAME;
|
||||
|
||||
// Disable timer during configuration
|
||||
hitag_stop_clock();
|
||||
|
||||
// TC0: Capture mode, default timer source = MCK/32 (TIMER_CLOCK3), no triggers
|
||||
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV3_CLOCK;
|
||||
|
||||
// TC1: Capture mode, default timer source = MCK/32 (TIMER_CLOCK3), TIOA is external trigger,
|
||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV3_CLOCK // use MCK/32 (TIMER_CLOCK3)
|
||||
| AT91C_TC_ABETRG // TIOA is used as an external trigger
|
||||
| AT91C_TC_ETRGEDG_FALLING // external trigger on falling edge
|
||||
| AT91C_TC_LDRA_RISING // load RA on on rising edge of TIOA
|
||||
| AT91C_TC_LDRB_FALLING; // load RB on on falling edge of TIOA
|
||||
|
||||
// TC2: Capture mode, default timer source = MCK/32 (TIMER_CLOCK3), no triggers
|
||||
AT91C_BASE_TC2->TC_CMR = AT91C_TC_CLKS_TIMER_DIV3_CLOCK;
|
||||
|
||||
// Enable and reset counters
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
|
||||
// Assert a sync signal. This sets all timers to 0 on next active clock edge
|
||||
AT91C_BASE_TCB->TCB_BCR = 1;
|
||||
|
||||
// synchronized startup procedure
|
||||
// In theory, with MCK/32, we shouldn't be waiting longer than 32 instruction statements, right?
|
||||
while (AT91C_BASE_TC0->TC_CV != 0) {
|
||||
}; // wait until TC0 returned to zero
|
||||
|
||||
// reset timestamp
|
||||
timestamp_high = 0;
|
||||
}
|
||||
|
||||
// Initialize FPGA and timer for Hitag operations
|
||||
void hitag_setup_fpga(uint16_t conf, uint8_t threshold, bool ledcontrol) {
|
||||
StopTicks();
|
||||
@@ -95,25 +46,30 @@ void hitag_setup_fpga(uint16_t conf, uint8_t threshold, bool ledcontrol) {
|
||||
|
||||
if (ledcontrol) LED_D_ON();
|
||||
|
||||
hitag_init_clock();
|
||||
// Configure the timers via the HAL: a precision counter (T0 timing), an
|
||||
// input capture (tag frame edges) and a timestamp counter (trace timing).
|
||||
StartPrecisionCounter();
|
||||
StartLoEdgeCapture();
|
||||
StartTimestamp();
|
||||
|
||||
// Set fpga in edge detect with/without reader field, we can modulate as reader/tag now
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | conf);
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125); //125kHz
|
||||
if (threshold != 127) FpgaSendCommand(FPGA_CMD_SET_EDGE_DETECT_THRESHOLD, threshold);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
|
||||
// Configure output and enable pin that is connected to the FPGA (for modulating)
|
||||
AT91C_BASE_PIOA->PIO_OER |= GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_PER |= GPIO_SSC_DOUT;
|
||||
gpio_fpga_mod_only_setup();
|
||||
|
||||
// Disable modulation at default, which means enable the field
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
}
|
||||
|
||||
// Clean up and finalize Hitag operations
|
||||
void hitag_cleanup(bool ledcontrol) {
|
||||
hitag_stop_clock();
|
||||
StopPrecisionCounter();
|
||||
StopLoEdgeCapture();
|
||||
StopTimestamp();
|
||||
set_tracing(false);
|
||||
lf_finalize(ledcontrol);
|
||||
}
|
||||
@@ -121,26 +77,25 @@ void hitag_cleanup(bool ledcontrol) {
|
||||
// Reader functions
|
||||
static void hitag_reader_send_bit(int bit, bool ledcontrol) {
|
||||
// Reset clock for the next bit
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
while (AT91C_BASE_TC0->TC_CV != 0) {};
|
||||
ResetPrecisionCounter();
|
||||
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
// Binary puls length modulation (BPLM) is used to encode the data stream
|
||||
// This means that a transmission of a one takes longer than that of a zero
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
|
||||
// Wait for 4-10 times the carrier period
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_LOW) {};
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_LOW) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
if (bit == 0) {
|
||||
// Zero bit: |_-|
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_0) {};
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_0) {};
|
||||
} else {
|
||||
// One bit: |_--|
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_1) {};
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_1) {};
|
||||
}
|
||||
|
||||
if (ledcontrol) LED_A_OFF();
|
||||
@@ -152,18 +107,17 @@ void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len, bool ledcon
|
||||
hitag_reader_send_bit(0, ledcontrol);
|
||||
|
||||
// Reset clock for the code violation
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
while (AT91C_BASE_TC0->TC_CV != 0) {};
|
||||
ResetPrecisionCounter();
|
||||
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
// SOF is HIGH for HITAG_T_LOW
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_LOW) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_LOW) {};
|
||||
|
||||
// Then LOW for HITAG_T_CODE_VIOLATION
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_CODE_VIOLATION) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_CODE_VIOLATION) {};
|
||||
|
||||
if (ledcontrol) LED_A_OFF();
|
||||
}
|
||||
@@ -174,19 +128,18 @@ void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len, bool ledcon
|
||||
}
|
||||
|
||||
// Send EOF
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
while (AT91C_BASE_TC0->TC_CV != 0) {};
|
||||
ResetPrecisionCounter();
|
||||
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
|
||||
// Wait for 4-10 times the carrier period
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_LOW) {};
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_LOW) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
}
|
||||
|
||||
void hitag_reader_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uint32_t *resptime, bool ledcontrol,
|
||||
MOD modulation, int sof_bits) {
|
||||
hitag_mod_t modulation, int sof_bits) {
|
||||
// Reset values for receiving frames
|
||||
memset(rx, 0x00, sizeofrx);
|
||||
*rxlen = 0;
|
||||
@@ -195,7 +148,7 @@ void hitag_reader_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uin
|
||||
bool bSkip = true;
|
||||
uint32_t errorCount = 0;
|
||||
bool bStarted = false;
|
||||
uint16_t next_edge_event = AT91C_TC_LDRBS;
|
||||
lo_edge_t next_edge = LO_EDGE_FALLING;
|
||||
int double_speed = (modulation == AC4K || modulation == MC8K) ? 2 : 1;
|
||||
|
||||
uint32_t rb_i = 0;
|
||||
@@ -205,22 +158,26 @@ void hitag_reader_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uin
|
||||
bool sof_received = false;
|
||||
|
||||
// Receive tag frame, watch for at most T0*HITAG_T_PROG_MAX periods
|
||||
while (AT91C_BASE_TC0->TC_CV < (T0 * HITAG_T_PROG_MAX)) {
|
||||
while (GetPrecisionCounter() < (T0 * HITAG_T_PROG_MAX)) {
|
||||
// Check if edge in tag modulation is detected
|
||||
if (AT91C_BASE_TC1->TC_SR & next_edge_event) {
|
||||
next_edge_event = next_edge_event ^ (AT91C_TC_LDRAS | AT91C_TC_LDRBS);
|
||||
if (GetLoEdgeCaptureStatus() == next_edge) {
|
||||
next_edge = next_edge == LO_EDGE_RISING ? LO_EDGE_FALLING : LO_EDGE_RISING;
|
||||
|
||||
// only use AT91C_TC_LDRBS falling edge for now
|
||||
if (next_edge_event == AT91C_TC_LDRBS) {
|
||||
// only use INPUT_CAPTURE_EVT_RB falling edge for now
|
||||
if (next_edge == LO_EDGE_FALLING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Retrieve the new timing values
|
||||
uint32_t rb = AT91C_BASE_TC1->TC_RB / T0;
|
||||
edges[rb_i++] = rb;
|
||||
uint32_t rb = GetLoEdgeCaptureFalling() / T0;
|
||||
|
||||
// For debug, save the edges for decoding manual
|
||||
if (rb_i < sizeof(edges)) {
|
||||
edges[rb_i++] = rb;
|
||||
}
|
||||
|
||||
// Reset timer every frame, we have to capture the last edge for timing
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
ResetPrecisionCounter();
|
||||
|
||||
if (ledcontrol) LED_B_INV();
|
||||
|
||||
@@ -342,7 +299,7 @@ void hitag_reader_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uin
|
||||
// max periods between 2 falling edge
|
||||
// RTF AC64 |--__|--__| (00) 64 * T0
|
||||
// RTF MC32 |_-|-_|_-| (010) 48 * T0
|
||||
if (AT91C_BASE_TC1->TC_CV > (T0 * 80)) {
|
||||
if (GetLoEdgeCaptureCount() > (T0 * 80)) {
|
||||
if (bStarted) {
|
||||
break;
|
||||
}
|
||||
@@ -350,15 +307,75 @@ void hitag_reader_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uin
|
||||
}
|
||||
|
||||
DBG {
|
||||
Dbprintf("RX %i:%02X.. resptime:%i edges:", *rxlen, rx[0], *resptime);
|
||||
Dbprintf("bStarted:%d bSkip:%d lastbit:%d sof_received:%d", bStarted, bSkip, lastbit, sof_received);
|
||||
Dbprintf("RX %i:%02X.. resptime:%i", *rxlen, rx[0], *resptime);
|
||||
Dbprintf("Edges count: %d, hex: ", rb_i);
|
||||
Dbhexdump(rb_i, edges, false);
|
||||
}
|
||||
}
|
||||
|
||||
int hitag_reader_transfer(const uint8_t *tx, size_t txlen, uint8_t *rx, size_t sizeofrx, size_t *rxlen, int t_wait,
|
||||
bool ledcontrol, hitag_mod_t modulation, uint8_t sof_bits, uint8_t send_sof) {
|
||||
uint32_t start_time = 0;
|
||||
|
||||
DBG Dbprintf("tx %d bits:", txlen);
|
||||
DBG Dbhexdump((txlen + 7) / 8, tx, false);
|
||||
|
||||
// Disable input capture to avoid triggers during our own modulation.
|
||||
StopLoEdgeCapture();
|
||||
|
||||
// Wait for HITAG_T_WAIT_SC carrier periods after the last tag bit before transmitting,
|
||||
// Since the clock counts since the last falling edge, a 'one' means that the
|
||||
// falling edge occurred halfway the period. with respect to this falling edge,
|
||||
// we need to wait (T_Wait2 + half_tag_period) when the last was a 'one'.
|
||||
// All timer values are in terms of T0 units
|
||||
while (GetPrecisionCounter() < T0 * t_wait) {};
|
||||
|
||||
start_time = TIMESTAMP;
|
||||
|
||||
// Transmit the reader frame
|
||||
hitag_reader_send_frame(tx, txlen, ledcontrol, send_sof);
|
||||
|
||||
// tearoff
|
||||
if (g_tearoff_enabled && tearoff_hook() == PM3_ETEAROFF) {
|
||||
return PM3_ETEAROFF;
|
||||
}
|
||||
|
||||
LogTraceBits(tx, txlen, start_time, TIMESTAMP, true);
|
||||
|
||||
// Enable and reset input capture for capturing the tag response.
|
||||
EnableLoEdgeCapture();
|
||||
|
||||
hitag_reader_receive_frame(rx, sizeofrx, rxlen, &start_time, ledcontrol, modulation, sof_bits);
|
||||
|
||||
DBG Dbprintf("rx %d bits:", *rxlen);
|
||||
DBG Dbhexdump((int)(*rxlen + 7) / 8, rx, false);
|
||||
|
||||
// Check if frame was captured and store it
|
||||
if (*rxlen > 0) {
|
||||
DBG {
|
||||
uint8_t response_bit[sizeofrx * 8];
|
||||
|
||||
for (size_t i = 0; i < *rxlen; i++) {
|
||||
response_bit[i] = (rx[i / 8] >> (7 - (i % 8))) & 1;
|
||||
}
|
||||
|
||||
Dbprintf("ht?: rxlen...... %zu", *rxlen);
|
||||
Dbprintf("ht?: sizeofrx... %zu", sizeofrx);
|
||||
DbpString("ht?: response_bit:");
|
||||
Dbhexdump((int) *rxlen, response_bit, false);
|
||||
}
|
||||
|
||||
LogTraceBits(rx, *rxlen, start_time, TIMESTAMP, false);
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// Tag functions - depends on modulation type
|
||||
static void hitag_tag_send_bit(int bit, MOD modulation, bool ledcontrol) {
|
||||
static void hitag_tag_send_bit(int bit, hitag_mod_t modulation, bool ledcontrol) {
|
||||
// Reset clock for the next bit
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
ResetPrecisionCounter();
|
||||
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
@@ -366,84 +383,84 @@ static void hitag_tag_send_bit(int bit, MOD modulation, bool ledcontrol) {
|
||||
case AC2K: {
|
||||
if (bit == 0) {
|
||||
// AC Coding --__
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 32) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 32) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 64) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 64) {};
|
||||
} else {
|
||||
// AC coding -_-_
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 16) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 16) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 32) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 32) {};
|
||||
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 48) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 48) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 64) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 64) {};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AC4K: {
|
||||
if (bit == 0) {
|
||||
// AC Coding --__
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_TAG_HALF_PERIOD) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_TAG_HALF_PERIOD) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * HITAG_T_TAG_FULL_PERIOD) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * HITAG_T_TAG_FULL_PERIOD) {};
|
||||
} else {
|
||||
// AC coding -_-_
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 8) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 8) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 16) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 16) {};
|
||||
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 24) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 24) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 32) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 32) {};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MC4K: {
|
||||
if (bit == 0) {
|
||||
// Manchester: Unloaded, then loaded |__--|
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 16) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 16) {};
|
||||
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 32) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 32) {};
|
||||
} else {
|
||||
// Manchester: Loaded, then unloaded |--__|
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 16) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 16) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 32) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 32) {};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MC8K: {
|
||||
if (bit == 0) {
|
||||
// Manchester: Unloaded, then loaded |__--|
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 8) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 8) {};
|
||||
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 16) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 16) {};
|
||||
} else {
|
||||
// Manchester: Loaded, then unloaded |--__|
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 8) {};
|
||||
Gpio_SSC_DOUT_High();
|
||||
while (GetPrecisionCounter() < T0 * 8) {};
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 16) {};
|
||||
Gpio_SSC_DOUT_Low();
|
||||
while (GetPrecisionCounter() < T0 * 16) {};
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -453,22 +470,24 @@ static void hitag_tag_send_bit(int bit, MOD modulation, bool ledcontrol) {
|
||||
}
|
||||
|
||||
void hitag_tag_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uint32_t *start_time, bool ledcontrol, int *overflow) {
|
||||
uint16_t next_edge_event = AT91C_TC_LDRBS;
|
||||
lo_edge_t next_edge = LO_EDGE_FALLING;
|
||||
uint8_t edges[160] = {0};
|
||||
uint32_t rb_i = 0;
|
||||
|
||||
// Receive frame, watch for at most T0*EOF periods
|
||||
while (AT91C_BASE_TC1->TC_CV < T0 * HITAG_T_EOF) {
|
||||
while (GetLoEdgeCaptureCount() < T0 * HITAG_T_EOF) {
|
||||
|
||||
// Check if edge in modulation is detected
|
||||
if (AT91C_BASE_TC1->TC_SR & next_edge_event) {
|
||||
next_edge_event = next_edge_event ^ (AT91C_TC_LDRAS | AT91C_TC_LDRBS);
|
||||
if (GetLoEdgeCaptureStatus() == next_edge) {
|
||||
next_edge = next_edge == LO_EDGE_RISING ? LO_EDGE_FALLING : LO_EDGE_RISING;
|
||||
|
||||
// only use AT91C_TC_LDRBS falling edge for now
|
||||
if (next_edge_event == AT91C_TC_LDRBS) continue;
|
||||
// only use INPUT_CAPTURE_EVT_RB falling edge for now
|
||||
if (next_edge == LO_EDGE_FALLING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Retrieve the new timing values
|
||||
uint32_t rb = AT91C_BASE_TC1->TC_RB / T0 + *overflow;
|
||||
uint32_t rb = GetLoEdgeCaptureFalling() / T0 + *overflow;
|
||||
*overflow = 0;
|
||||
|
||||
edges[rb_i++] = rb;
|
||||
@@ -510,20 +529,20 @@ void hitag_tag_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uint32
|
||||
}
|
||||
}
|
||||
|
||||
void hitag_tag_send_frame(const uint8_t *frame, size_t frame_len, int sof_bits, MOD modulation, bool ledcontrol) {
|
||||
void hitag_tag_send_frame(const uint8_t *frame, size_t frame_len, int sof_bits, hitag_mod_t modulation, bool ledcontrol) {
|
||||
// The beginning of the frame is hidden in some high level; pause until our bits will have an effect
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
ResetPrecisionCounter();
|
||||
Gpio_SSC_DOUT_High();
|
||||
|
||||
switch (modulation) {
|
||||
case AC4K:
|
||||
case MC8K: {
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 40) {}; // FADV
|
||||
while (GetPrecisionCounter() < T0 * 40) {}; // FADV
|
||||
break;
|
||||
}
|
||||
case AC2K:
|
||||
case MC4K: {
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * 20) {}; // STD + ADV
|
||||
while (GetPrecisionCounter() < T0 * 20) {}; // STD + ADV
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -543,5 +562,5 @@ void hitag_tag_send_frame(const uint8_t *frame, size_t frame_len, int sof_bits,
|
||||
hitag_tag_send_bit(TEST_BIT_MSB(frame, i), modulation, ledcontrol);
|
||||
}
|
||||
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
}
|
||||
@@ -26,7 +26,9 @@
|
||||
|
||||
#define HITAG_T_WAIT_RESP 200 /* T_wresp should be 204..212 */
|
||||
#define HITAG_T_WAIT_SC 200 /* T_wsc should be 90..5000 */
|
||||
// Read/Write Device waiting time before sending the first command
|
||||
#define HITAG_T_WAIT_FIRST 300 /* T_wfc should be 280..565 (T_ttf) */
|
||||
// HITAG S Transponder programming time
|
||||
#define HITAG_T_PROG_MAX 750 /* T_prog should be 716..726 */
|
||||
|
||||
#define HITAG_T_TAG_ONE_HALF_PERIOD 10
|
||||
@@ -42,16 +44,18 @@
|
||||
#define HITAG_T_TAG_CAPTURE_THREE_HALF 41
|
||||
#define HITAG_T_TAG_CAPTURE_FOUR_HALF 57
|
||||
|
||||
extern uint16_t timestamp_high;
|
||||
#define TIMESTAMP ( (AT91C_BASE_TC2->TC_SR & AT91C_TC_COVFS) ? timestamp_high += 1 : 0, ((timestamp_high << 16) + AT91C_BASE_TC2->TC_CV) / T0)
|
||||
// Trace timestamp in T0 units, provided by the timers HAL (GetTimestamp).
|
||||
#define TIMESTAMP GetTimestamp()
|
||||
|
||||
// Common hitag functions
|
||||
void hitag_setup_fpga(uint16_t conf, uint8_t threshold, bool ledcontrol);
|
||||
void hitag_cleanup(bool ledcontrol);
|
||||
void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len, bool ledcontrol, bool send_sof);
|
||||
void hitag_reader_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uint32_t *resptime, bool ledcontrol, MOD modulation,
|
||||
void hitag_reader_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uint32_t *resptime, bool ledcontrol, hitag_mod_t modulation,
|
||||
int sof_bits);
|
||||
int hitag_reader_transfer(const uint8_t *tx, size_t txlen, uint8_t *rx, size_t sizeofrx, size_t *rxlen, int t_wait,
|
||||
bool ledcontrol, hitag_mod_t modulation, uint8_t sof_bits, uint8_t send_sof);
|
||||
void hitag_tag_receive_frame(uint8_t *rx, size_t sizeofrx, size_t *rxlen, uint32_t *start_time, bool ledcontrol, int *overflow);
|
||||
void hitag_tag_send_frame(const uint8_t *frame, size_t frame_len, int sof_bits, MOD modulation, bool ledcontrol);
|
||||
void hitag_tag_send_frame(const uint8_t *frame, size_t frame_len, int sof_bits, hitag_mod_t modulation, bool ledcontrol);
|
||||
|
||||
#endif
|
||||
+16
-13
@@ -14,6 +14,10 @@
|
||||
// See LICENSE.txt for the text of the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Low frequency HITAG µ (micro) functions
|
||||
// HitagU. There are two frequency models, of which the 125kHz model has been discontinued.
|
||||
// 125k clock: https://www.nxp.com/products/no-longer-manufactured/hitag-%CE%BC-iso18000-2-transponder-ic:HTMS8301FTK
|
||||
// 134k clock: https://www.nxp.com/products/rfid-nfc/hitag-lf/hitag-%C2%B5-advanced-advanced-plus:HTMS1X01_HTMS8X01
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hitagu.h"
|
||||
#include "hitag_common.h"
|
||||
@@ -24,19 +28,19 @@
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "dbprint.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "hitag2/hitag2_crypto.h"
|
||||
#include "lfadc.h"
|
||||
#include "protocols.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "string.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "util.h"
|
||||
|
||||
// Hitag µ specific definitions
|
||||
#define HTU_SOF_BITS 4 // Start of frame bits is always 3 for Hitag µ (110) plus 1 bit error flag
|
||||
|
||||
MOD M = MC4K; // Modulation type
|
||||
hitag_mod_t M = MC4K; // Modulation type
|
||||
|
||||
// Structure to hold the state of the Hitag µ tag
|
||||
static struct hitagU_tag tag = {
|
||||
@@ -414,7 +418,7 @@ void htu_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
LogTraceBits(rx, rxlen, start_time, TIMESTAMP, true);
|
||||
|
||||
// Disable timer 1 with external trigger to avoid triggers during our own modulation
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
StopLoEdgeCapture();
|
||||
|
||||
// Prepare tag response (tx)
|
||||
memset(tx, 0x00, sizeof(tx));
|
||||
@@ -428,7 +432,7 @@ void htu_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
// with respect to the falling edge, we need to wait actually (T_Wait1 - T_Low)
|
||||
// periods. The gap time T_Low varies (4..10). All timer values are in
|
||||
// terms of T0 units
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * (HITAG_T_WAIT_RESP - HITAG_T_LOW)) {
|
||||
while (GetPrecisionCounter() < T0 * (HITAG_T_WAIT_RESP - HITAG_T_LOW)) {
|
||||
};
|
||||
|
||||
// Send and store the tag answer (if there is any)
|
||||
@@ -440,7 +444,7 @@ void htu_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
}
|
||||
|
||||
// Enable and reset external trigger in timer for capturing future frames
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
EnableLoEdgeCapture();
|
||||
|
||||
// Reset the received frame and response timing info
|
||||
memset(rx, 0x00, sizeof(rx));
|
||||
@@ -449,9 +453,9 @@ void htu_simulate(bool tag_mem_supplied, int8_t threshold, const uint8_t *data,
|
||||
// Reset the frame length
|
||||
rxlen = 0;
|
||||
// Save the timer overflow, will be 0 when frame was received
|
||||
overflow += (AT91C_BASE_TC1->TC_CV / T0);
|
||||
overflow += (GetLoEdgeCaptureCount() / T0);
|
||||
// Reset the timer to restart while-loop that receives frames
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
|
||||
ResetLoEdgeCapture();
|
||||
}
|
||||
|
||||
hitag_cleanup(ledcontrol);
|
||||
@@ -470,14 +474,13 @@ static int htu_reader_send_receive(uint8_t *tx, size_t txlen, uint8_t *rx, size_
|
||||
memset(rx, 0x00, sizeofrx);
|
||||
|
||||
// Disable timer 1 with external trigger to avoid triggers during our own modulation
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
StopLoEdgeCapture();
|
||||
|
||||
DBG Dbprintf("tx %d bits:", txlen);
|
||||
DBG Dbhexdump((txlen + 7) / 8, tx, false);
|
||||
|
||||
// Wait until we can send the command
|
||||
while (AT91C_BASE_TC0->TC_CV < T0 * t_wait) {
|
||||
};
|
||||
while (GetPrecisionCounter() < T0 * t_wait) {};
|
||||
|
||||
// Set up tracing
|
||||
uint32_t start_time = TIMESTAMP;
|
||||
@@ -492,7 +495,7 @@ static int htu_reader_send_receive(uint8_t *tx, size_t txlen, uint8_t *rx, size_
|
||||
LogTraceBits(tx, txlen, start_time, TIMESTAMP, true);
|
||||
|
||||
// Enable and reset external trigger in timer for capturing future frames
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
EnableLoEdgeCapture();
|
||||
|
||||
// Capture response - SOF is automatically stripped by hitag_reader_receive_frame
|
||||
hitag_reader_receive_frame(rx, sizeofrx, rxlen, &start_time, ledcontrol, modulation, sof_bits);
|
||||
|
||||
+106
-41
@@ -20,38 +20,37 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
|
||||
#define GPIO_RST AT91C_PIO_PA1
|
||||
#define GPIO_SCL AT91C_PIO_PA5
|
||||
#define GPIO_SDA AT91C_PIO_PA7
|
||||
#define SCL_H Gpio_I2C_SCL_High()
|
||||
#define SCL_L Gpio_I2C_SCL_Low()
|
||||
#define SDA_H Gpio_I2C_SDA_High()
|
||||
#define SDA_L Gpio_I2C_SDA_Low()
|
||||
#define RST_H Gpio_I2C_RST_High()
|
||||
#define RST_L Gpio_I2C_RST_Low()
|
||||
|
||||
#define SCL_H HIGH(GPIO_SCL)
|
||||
#define SCL_L LOW(GPIO_SCL)
|
||||
#define SDA_H HIGH(GPIO_SDA)
|
||||
#define SDA_L LOW(GPIO_SDA)
|
||||
|
||||
#define SCL_read ((AT91C_BASE_PIOA->PIO_PDSR & GPIO_SCL) == GPIO_SCL)
|
||||
#define SDA_read ((AT91C_BASE_PIOA->PIO_PDSR & GPIO_SDA) == GPIO_SDA)
|
||||
#define SCL_read Gpio_I2C_SCL_Read()
|
||||
#define SDA_read Gpio_I2C_SDA_Read()
|
||||
|
||||
#define I2C_ERROR "I2C_WaitAck Error"
|
||||
|
||||
// Direct use the loop to delay. 6 instructions loop, Masterclock 48MHz,
|
||||
// delay=1 is about 200kbps
|
||||
// timer.
|
||||
// I2CSpinDelayClk(4) = 12.31us
|
||||
// I2CSpinDelayClk(1) = 3.07us
|
||||
static volatile uint32_t c;
|
||||
static void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
|
||||
for (c = delay * 2; c; c--) {};
|
||||
}
|
||||
// I2CSpinDelayClk(4) about 12us
|
||||
// I2CSpinDelayClk(1) about 3us
|
||||
// static void I2CSpinDelayClk(const uint16_t delay) {
|
||||
// for (uint16_t i = 0; i < delay; i++) {
|
||||
// SpinDelayUsPrecision(2);
|
||||
// }
|
||||
// }
|
||||
|
||||
#define I2C_DELAY_1CLK I2CSpinDelayClk(1)
|
||||
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
|
||||
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
|
||||
// TODO DXL 修改了速度到比较慢的情况,测完需要改回来,原先是2和4
|
||||
|
||||
#define I2C_DELAY_1CLK SpinDelayUsPrecision(20)
|
||||
#define I2C_DELAY_2CLK SpinDelayUsPrecision(22)
|
||||
// #define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
|
||||
|
||||
// try i2c bus recovery at 100kHz = 5us high, 5us low
|
||||
void I2C_recovery(void) {
|
||||
@@ -89,19 +88,7 @@ void I2C_recovery(void) {
|
||||
}
|
||||
|
||||
void I2C_init(bool has_ticks) {
|
||||
// Configure reset pin, close up pull up, push-pull output, default high
|
||||
AT91C_BASE_PIOA->PIO_PPUDR = GPIO_RST;
|
||||
AT91C_BASE_PIOA->PIO_MDDR = GPIO_RST;
|
||||
|
||||
// Configure I2C pin, open up, open leakage
|
||||
AT91C_BASE_PIOA->PIO_PPUER |= (GPIO_SCL | GPIO_SDA);
|
||||
AT91C_BASE_PIOA->PIO_MDER |= (GPIO_SCL | GPIO_SDA);
|
||||
|
||||
// default three lines all pull up
|
||||
AT91C_BASE_PIOA->PIO_SODR |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
|
||||
|
||||
AT91C_BASE_PIOA->PIO_OER |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
|
||||
AT91C_BASE_PIOA->PIO_PER |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
|
||||
gpio_sw_i2c_rst_setup();
|
||||
|
||||
if (has_ticks) {
|
||||
WaitMS(2);
|
||||
@@ -115,19 +102,19 @@ void I2C_init(bool has_ticks) {
|
||||
// set the reset state
|
||||
void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA) {
|
||||
if (LineRST)
|
||||
HIGH(GPIO_RST);
|
||||
RST_H;
|
||||
else
|
||||
LOW(GPIO_RST);
|
||||
RST_L;
|
||||
|
||||
if (LineSCK)
|
||||
HIGH(GPIO_SCL);
|
||||
SCL_H;
|
||||
else
|
||||
LOW(GPIO_SCL);
|
||||
SCL_L;
|
||||
|
||||
if (LineSDA)
|
||||
HIGH(GPIO_SDA);
|
||||
SDA_H;
|
||||
else
|
||||
LOW(GPIO_SDA);
|
||||
SDA_L;
|
||||
}
|
||||
|
||||
// Reset the SIM_Adapter, then enter the main program
|
||||
@@ -594,6 +581,84 @@ int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t
|
||||
return readcount - 2;
|
||||
}
|
||||
|
||||
// read one array of data (Data array, Readout length, command to be written , SlaveDevice address ).
|
||||
// len = uint16 because we need to read up to 256bytes
|
||||
// No data process logic, only raw rx.
|
||||
int16_t I2C_BufferReadRaw(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address) {
|
||||
|
||||
// sanity check
|
||||
if (data == NULL || len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t *pd = data;
|
||||
|
||||
// extra wait 500us (514us measured)
|
||||
// 200us (xx measured)
|
||||
WaitUS(600);
|
||||
|
||||
bool _break = true;
|
||||
|
||||
do {
|
||||
if (I2C_Start() == false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 0xB0 / 0xC0 == i2c write
|
||||
I2C_SendByte(device_address & 0xFE);
|
||||
if (I2C_WaitAck() == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
I2C_SendByte(device_cmd);
|
||||
if (I2C_WaitAck() == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 0xB1 / 0xC1 == i2c read
|
||||
I2C_Start();
|
||||
I2C_SendByte(device_address | 1);
|
||||
if (I2C_WaitAck() == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
_break = false;
|
||||
} while (false);
|
||||
|
||||
if (_break) {
|
||||
I2C_Stop();
|
||||
if (g_dbglevel > DBG_DEBUG) DbpString(I2C_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int16_t count = 0;
|
||||
|
||||
while (len) {
|
||||
int16_t tmp = I2C_ReadByte();
|
||||
if (tmp < 0) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
data[count] = (uint8_t)tmp & 0xFF;
|
||||
len--;
|
||||
count++;
|
||||
|
||||
// acknowledgements. After last byte send NACK.
|
||||
if (len == 0) {
|
||||
I2C_NoAck();
|
||||
} else {
|
||||
I2C_Ack();
|
||||
}
|
||||
}
|
||||
|
||||
I2C_Stop();
|
||||
|
||||
// Dbprintf("rec len... %u count... %u", recv_len, count);
|
||||
// Dbhexdump(count, data, false);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address) {
|
||||
//START, 0xB0, 0x00, 0x00, START, 0xB1, xx, yy, zz, ......, STOP
|
||||
bool _break = true;
|
||||
|
||||
+2
-1
@@ -43,7 +43,7 @@
|
||||
|
||||
void I2C_recovery(void);
|
||||
void I2C_init(bool has_ticks);
|
||||
void I2C_Reset(void);
|
||||
void I2C_Reset(void); // TODO DXL: Not implemented but defined?
|
||||
void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA);
|
||||
|
||||
void I2C_Reset_EnterMainProgram(void);
|
||||
@@ -53,6 +53,7 @@ bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address);
|
||||
|
||||
bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address);
|
||||
bool I2C_BufferWrite(const uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address);
|
||||
int16_t I2C_BufferReadRaw(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address);
|
||||
int16_t I2C_BufferRead(uint8_t *data, uint16_t len, uint8_t device_cmd, uint8_t device_address);
|
||||
|
||||
// for firmware
|
||||
|
||||
+3
-2
@@ -23,7 +23,8 @@
|
||||
#include "BigBuf.h"
|
||||
#include "string.h"
|
||||
#include "mifareutil.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "protocols.h"
|
||||
@@ -32,7 +33,7 @@
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "i2c.h"
|
||||
#include "i2c_direct.h"
|
||||
|
||||
|
||||
+3
-2
@@ -29,12 +29,13 @@
|
||||
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "string.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "protocols.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "iso15693.h"
|
||||
#include "iclass_cmd.h" // iclass_card_select_t struct
|
||||
#include "i2c.h" // i2c defines (SIM module access)
|
||||
|
||||
+74
-54
@@ -24,8 +24,10 @@
|
||||
#include "cmd.h"
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "rssi_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "parity.h"
|
||||
@@ -37,7 +39,7 @@
|
||||
#include "desfire_crypto.h" // UL-C authentication helpers
|
||||
#include "mifare.h" // for iso14a_polling_frame_t structure
|
||||
#include "cmac_calc.h"
|
||||
#include "usb_cdc.h"
|
||||
#include "usb_cdc_apis.h"
|
||||
|
||||
// Forward declaration: HID Config Card jam support (implemented in secc.c).
|
||||
// Called from SniffIso14443a when param bit 0x04 is set.
|
||||
@@ -45,8 +47,6 @@ bool hid_config_card_jam(const uint8_t *cmd, int len, uint8_t *dma_buf);
|
||||
|
||||
static uint32_t iso14a_timeout;
|
||||
|
||||
static uint8_t colpos = 0;
|
||||
|
||||
// the block number for the ISO14443-4 PCB
|
||||
static uint8_t iso14_pcb_blocknum = 0;
|
||||
|
||||
@@ -845,8 +845,8 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
uint8_t *data = dma->buf;
|
||||
|
||||
// Setup and start DMA.
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -875,7 +875,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
}
|
||||
|
||||
register int readBufDataP = data - dma->buf;
|
||||
register int dmaBufDataP = DMA_BUFFER_SIZE - AT91C_BASE_PDC_SSC->PDC_RCR;
|
||||
register int dmaBufDataP = DMA_BUFFER_SIZE - FPGA_SSC_DMA_RX_Remaining_Count();
|
||||
if (readBufDataP <= dmaBufDataP) {
|
||||
dataLen = dmaBufDataP - readBufDataP;
|
||||
} else {
|
||||
@@ -886,6 +886,11 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
maxDataLen = dataLen;
|
||||
}
|
||||
|
||||
// TODO DXL This cross platform issue needs to be addressed
|
||||
// When the current buffer address is zeroed, it usually means the next buffer hasn't been assigned a value in time,
|
||||
// indicating that the MCU's processing speed is slow.
|
||||
// The logic here is to reset the state machine to receive data again.
|
||||
|
||||
// DMA fully stalled: both buffers exhausted. Re-arm primary + secondary,
|
||||
// resync the read pointer, and drop the in-flight frame.
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
@@ -918,6 +923,13 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO DXL This problem needs to be addressed.
|
||||
* if (FPGA_SSC_DMA_RX_Done()) {
|
||||
* FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
|
||||
* }
|
||||
*/
|
||||
|
||||
// secondary buffer exhausted, primary still running — refill secondary
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
@@ -929,6 +941,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
// Need two samples to feed Miller and Manchester-Decoder
|
||||
if (rx_samples & 0x01) {
|
||||
|
||||
// Reader -> Tag
|
||||
// no need to try decoding reader data if the tag is sending
|
||||
if (TagIsActive == false) {
|
||||
|
||||
@@ -967,6 +980,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
ReaderIsActive = (Uart.state != STATE_14A_UNSYNCD);
|
||||
}
|
||||
|
||||
// Tag -> Reader
|
||||
// no need to try decoding tag data if the reader is sending - and we cannot afford the time
|
||||
if (ReaderIsActive == false) {
|
||||
|
||||
@@ -1151,7 +1165,7 @@ bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t received_maxlen,
|
||||
Uart14aInit(received, received_maxlen, par);
|
||||
|
||||
// clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
uint8_t b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
(void)b;
|
||||
|
||||
uint8_t flip = 0;
|
||||
@@ -1180,8 +1194,8 @@ bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t received_maxlen,
|
||||
checker = 4000;
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
if (MillerDecoding(b, 0)) {
|
||||
*len = Uart.len;
|
||||
return true;
|
||||
@@ -2597,7 +2611,6 @@ static void PrepareDelayedTransfer(uint16_t delay) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Transmit the command (to the tag) that was placed in ToSend[].
|
||||
// Parameter timing:
|
||||
@@ -2613,7 +2626,10 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing
|
||||
return;
|
||||
}
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD);
|
||||
// DXL: If the mode is set to FPGA_MAJOR_MODE_OFF before transmission, the timing wait will freeze.
|
||||
// If you need to handle this situation, you can uncomment the code below(SPEED is affected).
|
||||
// And do not use the FPGA_HF_ISO14443A_READER_MOD!!!
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN);
|
||||
|
||||
if (timing) {
|
||||
|
||||
@@ -2632,14 +2648,28 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing
|
||||
ThisTransferTime = ((MAX(NextTransferTime, GetCountSspClk()) & 0xfffffff8) + 8);
|
||||
|
||||
while (GetCountSspClk() < ThisTransferTime) {};
|
||||
|
||||
LastTimeProxToAirStart = ThisTransferTime;
|
||||
|
||||
}
|
||||
|
||||
// DXL: Switch to this mode before actually starting to send. Otherwise, it may cause delays between frames to fail.
|
||||
// 14b also has this problem, which requires waiting for the frame delay to complete
|
||||
// before switching to modulation transmission mode to send data.
|
||||
// If we don't do this, there is a possibility of randomly encountering communication exception bugs
|
||||
// on high-performance processors such as AT32, which is very fatal!
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD);
|
||||
|
||||
// If the transmission is not cleared, there is a high probability of communication abnormalities.
|
||||
// I suspect that the wrong DOUT level may have modulated data that should not have been modulated.
|
||||
// If further research is needed, an oscilloscope needs to be used to observe the specific DOUT modulation status.
|
||||
// ---
|
||||
// Clear TXRDY:
|
||||
FPGA_SSC_TX_Value(SEC_Y);
|
||||
|
||||
uint16_t c = 0;
|
||||
while (c < len) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = cmd[c];
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(cmd[c]);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
@@ -2750,23 +2780,13 @@ int EmGetCmd(uint8_t *received, uint16_t received_max_len, uint16_t *len, uint8_
|
||||
LED_D_OFF();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
||||
|
||||
// Set ADC to read field strength
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
|
||||
AT91C_BASE_ADC->ADC_MR =
|
||||
ADC_MODE_PRESCALE(63) |
|
||||
ADC_MODE_STARTUP_TIME(1) |
|
||||
ADC_MODE_SAMPLE_HOLD_TIME(15);
|
||||
|
||||
AT91C_BASE_ADC->ADC_CHER = ADC_CHANNEL(ADC_CHAN_HF);
|
||||
|
||||
// start ADC
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
||||
AdcSetupRssiChannel(ADC_RSSI_CH_HF);
|
||||
|
||||
// Now run a 'software UART' on the stream of incoming samples.
|
||||
Uart14aInit(received, received_max_len, par);
|
||||
|
||||
// Clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
uint8_t b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
(void)b;
|
||||
|
||||
uint8_t flip = 0;
|
||||
@@ -2802,17 +2822,17 @@ int EmGetCmd(uint8_t *received, uint16_t received_max_len, uint16_t *len, uint8_
|
||||
|
||||
|
||||
// test if the field exists
|
||||
if (AT91C_BASE_ADC->ADC_SR & ADC_END_OF_CONVERSION(ADC_CHAN_HF)) {
|
||||
if (AdcRssiDataReady(ADC_RSSI_CH_HF)) {
|
||||
|
||||
analogCnt++;
|
||||
|
||||
analogAVG += (AT91C_BASE_ADC->ADC_CDR[ADC_CHAN_HF] & 0x3FF);
|
||||
analogAVG += AdcRssiDataRead(ADC_RSSI_CH_HF);
|
||||
|
||||
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START;
|
||||
AdcRssiConversionStart();
|
||||
|
||||
if (analogCnt >= 32) {
|
||||
|
||||
if ((MAX_ADC_HF_VOLTAGE * (analogAVG / analogCnt) >> 10) < MF_MINFIELDV) {
|
||||
if (AdcRssiDataToMilliVolt(analogAVG / analogCnt, ADC_RSSI_CH_HF) < MF_MINFIELDV) {
|
||||
|
||||
if (timer == 0) {
|
||||
timer = GetTickCount();
|
||||
@@ -2831,8 +2851,8 @@ int EmGetCmd(uint8_t *received, uint16_t received_max_len, uint16_t *len, uint8_
|
||||
}
|
||||
|
||||
// receive and test the miller decoding
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
if (MillerDecoding(b, 0)) {
|
||||
*len = Uart.len;
|
||||
return 0;
|
||||
@@ -2862,14 +2882,14 @@ int EmSendCmd14443aRaw(const uint8_t *resp, uint16_t respLen) {
|
||||
i = (correction_needed) ? 0 : 1;
|
||||
|
||||
// clear receiving shift register and holding register
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY));
|
||||
b = AT91C_BASE_SSC->SSC_RHR;
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
b = FPGA_SSC_RX_Value();
|
||||
(void) b;
|
||||
|
||||
// wait for the FPGA to signal fdt_indicator == 1 (the FPGA is ready to queue new data in its delay line)
|
||||
for (uint8_t j = 0; j < 5; j++) { // allow timeout - better late than never
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY));
|
||||
if (AT91C_BASE_SSC->SSC_RHR) {
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
if (FPGA_SSC_RX_Value()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2877,22 +2897,24 @@ int EmSendCmd14443aRaw(const uint8_t *resp, uint16_t respLen) {
|
||||
while ((ThisTransferTime = GetCountSspClk()) & 0x00000007);
|
||||
|
||||
// Clear TXRDY:
|
||||
AT91C_BASE_SSC->SSC_THR = SEC_F;
|
||||
FPGA_SSC_TX_Value(SEC_F);
|
||||
|
||||
// send cycle
|
||||
for (; i < respLen;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = resp[i++];
|
||||
FpgaSendQueueDelay = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(resp[i++]);
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
FpgaSendQueueDelay = (uint8_t)FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that the FPGA Delay Queue is empty before we switch to TAGSIM_LISTEN again:
|
||||
uint8_t fpga_queued_bits = FpgaSendQueueDelay >> 3;
|
||||
for (i = 0; i <= (fpga_queued_bits >> 3) + 1;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = SEC_F;
|
||||
FpgaSendQueueDelay = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(SEC_F);
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
FpgaSendQueueDelay = (uint8_t)FPGA_SSC_RX_Value();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -3014,7 +3036,7 @@ bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint16_t rec_
|
||||
Demod14aInit(receivedResponse, rec_maxlen, NULL);
|
||||
|
||||
// clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
uint8_t b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
(void)b;
|
||||
|
||||
uint32_t timeout = iso14a_get_timeout();
|
||||
@@ -3023,8 +3045,8 @@ bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint16_t rec_
|
||||
for (;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
if (ManchesterDecoding_Thinfilm(b)) {
|
||||
*received_len = Demod.len;
|
||||
LogTrace(receivedResponse, Demod.len, Demod.startTime * 16 - DELAY_AIR2ARM_AS_READER, Demod.endTime * 16 - DELAY_AIR2ARM_AS_READER, NULL, false);
|
||||
@@ -3064,7 +3086,7 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint16_t rec_max
|
||||
Demod14aInit(receivedResponse, rec_maxlen, receivedResponsePar);
|
||||
|
||||
// clear RXRDY:
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
uint8_t b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
(void)b;
|
||||
|
||||
volatile uint32_t c = 0;
|
||||
@@ -3073,8 +3095,8 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint16_t rec_max
|
||||
for (;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
if (ManchesterDecoding(b, offset, 0)) {
|
||||
NextTransferTime = MAX(NextTransferTime, Demod.endTime - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / 16 + FRAME_DELAY_TIME_PICC_TO_PCD);
|
||||
return true;
|
||||
@@ -3186,11 +3208,9 @@ void iso14443a_antifuzz(uint32_t flags) {
|
||||
resp[2] = 0xFF;
|
||||
resp[3] = 0xFF;
|
||||
resp[4] = resp[0] ^ resp[1] ^ resp[2] ^ resp[3];
|
||||
colpos = 0;
|
||||
|
||||
if (IS_FLAG_UID_IN_DATA(flags, 7)) {
|
||||
resp[0] = MIFARE_SELECT_CT;
|
||||
colpos = 8;
|
||||
}
|
||||
|
||||
// trigger a faulty/collision response
|
||||
@@ -3635,7 +3655,7 @@ void iso14443a_setup(uint8_t fpga_minor_mode) {
|
||||
// Set up the synchronous serial port
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_ISO14443A);
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
LED_D_OFF();
|
||||
// Signal field is on with the appropriate LED
|
||||
|
||||
+64
-73
@@ -29,10 +29,12 @@
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "cmd.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "commonutil.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "rssi_apis.h"
|
||||
#include "iso14b.h" // defines for ETU conversions
|
||||
#include "iclass.h" // picopass buffer defines
|
||||
|
||||
@@ -714,8 +716,8 @@ static bool GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) {
|
||||
while (BUTTON_PRESS() == false) {
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
uint8_t b = (uint8_t)FPGA_SSC_RX_Value();
|
||||
for (uint8_t mask = 0x80; mask != 0x00; mask >>= 1) {
|
||||
if (Handle14443bSampleFromReader(b & mask)) {
|
||||
*len = Uart.byteCnt;
|
||||
@@ -742,8 +744,8 @@ static void TransmitFor14443b_AsTag(const uint8_t *response, uint16_t len) {
|
||||
for (uint16_t i = 0; i < len;) {
|
||||
|
||||
// Put byte into tx holding register as soon as it is ready
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||
AT91C_BASE_SSC->SSC_THR = response[i++];
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(response[i++]);
|
||||
|
||||
// Start-up SSC once first byte is in SSC_THR
|
||||
if (i == 1) {
|
||||
@@ -774,7 +776,7 @@ void SimulateIso14443bTag(const uint8_t *pupi) {
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
// Set up the synchronous serial port
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR);
|
||||
@@ -837,7 +839,7 @@ void SimulateIso14443bTag(const uint8_t *pupi) {
|
||||
}
|
||||
|
||||
// find reader field
|
||||
vHf = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
vHf = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);
|
||||
if (vHf > MF_MINFIELDV) {
|
||||
if (cardSTATE == SIM_POWER_OFF) {
|
||||
cardSTATE = SIM_IDLE;
|
||||
@@ -1002,7 +1004,7 @@ void Simulate_iso14443b_srx_tag(uint8_t *uid) {
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
// Set up the synchronous serial port
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR);
|
||||
@@ -1045,7 +1047,7 @@ void Simulate_iso14443b_srx_tag(uint8_t *uid) {
|
||||
// find reader field
|
||||
if (cardSTATE == SIM_NOFIELD) {
|
||||
|
||||
vHf = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
vHf = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);
|
||||
if (vHf > MF_MINFIELDV) {
|
||||
cardSTATE = SIM_IDLE;
|
||||
LED_A_ON();
|
||||
@@ -1378,8 +1380,8 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
@@ -1395,7 +1397,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||
|
||||
for (;;) {
|
||||
|
||||
volatile uint16_t behindBy = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
volatile uint16_t behindBy = ((uint16_t *)FPGA_SSC_DMA_RX_Current_Address() - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behindBy == 0) {
|
||||
WDT_HIT();
|
||||
if (BUTTON_PRESS()) {
|
||||
@@ -1429,18 +1431,9 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||
upTo = dma->buf;
|
||||
|
||||
// DMA Counter Register had reached 0, already rotated.
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||
if (FPGA_SSC_DMA_RX_Done()) {
|
||||
|
||||
// primary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
// secondary buffer sets as primary, secondary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
|
||||
|
||||
WDT_HIT();
|
||||
if (BUTTON_PRESS()) {
|
||||
@@ -1451,7 +1444,6 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||
}
|
||||
|
||||
if (Handle14443bSamplesFromTag(ci, cq)) {
|
||||
|
||||
// Response timing is measured from DMA start, but trace rows use
|
||||
// absolute SSP time like reader frames.
|
||||
uint32_t eof_delta = GetCountSspClkDelta(dma_start_time);
|
||||
@@ -1472,7 +1464,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
FpgaDisableSscDma();
|
||||
FPGA_SSC_DMA_RX_Disable();
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -1492,6 +1484,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||
if (retlen) {
|
||||
*retlen = Demod.len;
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1503,28 +1496,33 @@ static void TransmitFor14443b_AsReader(uint32_t *start_time) {
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
#ifdef RDV4
|
||||
// TODO DXL 可能此函数会被 Get14443bAnswerFromTag 的改动所影响,需要进行测试。
|
||||
|
||||
// TR2 minimum 14 ETUs
|
||||
if (*start_time < ISO14B_TR0) {
|
||||
// *start_time = DELAY_ARM_TO_TAG;
|
||||
*start_time = ISO14B_TR0;
|
||||
}
|
||||
// *start_time = (*start_time - DELAY_ARM_TO_TAG) & 0xfffffff0;
|
||||
*start_time = (*start_time & 0xfffffff0);
|
||||
if (GetCountSspClk() > *start_time) { // we may miss the intended time
|
||||
*start_time = (GetCountSspClk() + 32) & 0xfffffff0; // next possible time
|
||||
}
|
||||
// waiting for T2(minimum delay between two frames)
|
||||
while (GetCountSspClk() < *start_time) {}
|
||||
|
||||
// DXL: It is best to perform a clearance once.
|
||||
FPGA_SSC_TX_Clear();
|
||||
|
||||
// DXL:
|
||||
// We only switch to the transmission modulation mode before starting the transmission, and before that,
|
||||
// we may still be delaying and waiting for T2 (14 ETUs) between two frames
|
||||
#if defined RDV4 || defined PM5
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SEND_SHALLOW_MOD_RDV4);
|
||||
#else
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SEND_SHALLOW_MOD);
|
||||
#endif
|
||||
|
||||
// TR2 minimum 14 ETUs
|
||||
if (*start_time < ISO14B_TR0) {
|
||||
// *start_time = DELAY_ARM_TO_TAG;
|
||||
*start_time = ISO14B_TR0;
|
||||
}
|
||||
|
||||
// *start_time = (*start_time - DELAY_ARM_TO_TAG) & 0xfffffff0;
|
||||
*start_time = (*start_time & 0xfffffff0);
|
||||
|
||||
if (GetCountSspClk() > *start_time) { // we may miss the intended time
|
||||
*start_time = (GetCountSspClk() + 32) & 0xfffffff0; // next possible time
|
||||
}
|
||||
|
||||
// wait
|
||||
while (GetCountSspClk() < *start_time);
|
||||
|
||||
LED_B_ON();
|
||||
for (int c = 0; c < ts->max; c++) {
|
||||
volatile uint8_t data = ts->buf[c];
|
||||
@@ -1532,11 +1530,11 @@ static void TransmitFor14443b_AsReader(uint32_t *start_time) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
volatile uint16_t send_word = (data & 0x80) ? 0x0000 : 0xFFFF;
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
while (!FPGA_SSC_TX_Ready()) ;
|
||||
FPGA_SSC_TX_Value(send_word);
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
while (!FPGA_SSC_TX_Ready()) ;
|
||||
FPGA_SSC_TX_Value(send_word);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
@@ -1550,23 +1548,25 @@ static void TransmitFor14443b_AsReader(uint32_t *start_time) {
|
||||
for (uint8_t i = 0; i < last_bits; i++) {
|
||||
volatile uint16_t send_word = (data & 0x80) ? 0x0000 : 0xFFFF;
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
while (!FPGA_SSC_TX_Ready()) ;
|
||||
FPGA_SSC_TX_Value(send_word);
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
while (!FPGA_SSC_TX_Ready()) ;
|
||||
FPGA_SSC_TX_Value(send_word);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
|
||||
// DXL: Very important!!! If not cleared, ST25 will always fail communication on at32 platform.
|
||||
FPGA_SSC_TX_Clear();
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
|
||||
LED_B_OFF();
|
||||
|
||||
// *start_time += DELAY_ARM_TO_TAG;
|
||||
|
||||
// wait for last transfer to complete
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXEMPTY)) {};
|
||||
while (!FPGA_SSC_TX_Done()) {};
|
||||
}
|
||||
|
||||
static uint32_t ToSendBitCount(const tosend_t *ts) {
|
||||
@@ -2457,13 +2457,13 @@ void iso14443b_setup(void) {
|
||||
Uart14bInit(BigBuf_calloc(MAX_FRAME_SIZE));
|
||||
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
// Set up the synchronous serial port
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
|
||||
// Signal field is on with the appropriate LED
|
||||
#ifdef RDV4
|
||||
#if defined RDV4 || defined PM5
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SEND_SHALLOW_MOD_RDV4);
|
||||
#else
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SEND_SHALLOW_MOD);
|
||||
@@ -2594,7 +2594,7 @@ void SniffIso14443b(void) {
|
||||
// FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_SUBCARRIER_848_KHZ | FPGA_HF_READER_MODE_SNIFF_AMPLITUDE);
|
||||
|
||||
// connect Demodulated Signal to ADC:
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
|
||||
StartCountSspClk();
|
||||
@@ -2603,8 +2603,8 @@ void SniffIso14443b(void) {
|
||||
dmabuf16_t *dma = get_dma16();
|
||||
|
||||
// Setup and start DMA.
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) DbpString("FpgaSetupSscDma failed. Exiting");
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) DbpString("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
switch_off();
|
||||
return;
|
||||
}
|
||||
@@ -2615,7 +2615,7 @@ void SniffIso14443b(void) {
|
||||
bool tag_is_active = false;
|
||||
bool reader_is_active = false;
|
||||
bool expect_tag_answer = false;
|
||||
int dma_start_time = 0;
|
||||
uint32_t dma_start_time = 0;
|
||||
|
||||
// Count of samples received so far, so that we can include timing
|
||||
int samples = 0;
|
||||
@@ -2624,7 +2624,7 @@ void SniffIso14443b(void) {
|
||||
|
||||
for (;;) {
|
||||
|
||||
volatile int behind_by = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
volatile int behind_by = ((uint16_t *)FPGA_SSC_DMA_RX_Current_Address() - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behind_by < 1) continue;
|
||||
|
||||
samples++;
|
||||
@@ -2644,18 +2644,9 @@ void SniffIso14443b(void) {
|
||||
upTo = dma->buf;
|
||||
|
||||
// DMA Counter Register had reached 0, already rotated.
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||
if (FPGA_SSC_DMA_RX_Done()) {
|
||||
|
||||
// primary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
// secondary buffer sets as primary, secondary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
|
||||
|
||||
WDT_HIT();
|
||||
if (BUTTON_PRESS()) {
|
||||
@@ -2782,7 +2773,7 @@ static void tearoff_field_on(void) {
|
||||
Demod14bInit(BigBuf_calloc(MAX_FRAME_SIZE), MAX_FRAME_SIZE);
|
||||
Uart14bInit(BigBuf_calloc(MAX_FRAME_SIZE));
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER); // programs PDC with fresh BigBuf address
|
||||
#ifdef RDV4
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_MODE_SEND_SHALLOW_MOD_RDV4);
|
||||
|
||||
+44
-66
@@ -69,9 +69,11 @@
|
||||
#include "cmd.h"
|
||||
#include "appmain.h"
|
||||
#include "dbprint.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "commonutil.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "rssi_apis.h"
|
||||
#include "BigBuf.h"
|
||||
#include "crc16.h"
|
||||
|
||||
@@ -300,7 +302,7 @@ void CodeIso15693AsTag(const uint8_t *cmd, size_t len) {
|
||||
// Transmit the command (to the tag) that was placed in cmd[].
|
||||
void TransmitTo15693Tag(const uint8_t *cmd, int len, uint32_t *start_time, bool shallow_mod) {
|
||||
|
||||
#ifdef RDV4
|
||||
#if defined RDV4 || defined PM5
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | (shallow_mod ? FPGA_HF_READER_MODE_SEND_SHALLOW_MOD_RDV4 : FPGA_HF_READER_MODE_SEND_FULL_MOD));
|
||||
#else
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | (shallow_mod ? FPGA_HF_READER_MODE_SEND_SHALLOW_MOD : FPGA_HF_READER_MODE_SEND_FULL_MOD));
|
||||
@@ -328,11 +330,11 @@ void TransmitTo15693Tag(const uint8_t *cmd, int len, uint32_t *start_time, bool
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
uint16_t send_word = (data & 0x80) ? 0xffff : 0x0000;
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
while (!FPGA_SSC_TX_Ready()) ;
|
||||
FPGA_SSC_TX_Value(send_word);
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) ;
|
||||
AT91C_BASE_SSC->SSC_THR = send_word;
|
||||
while (!FPGA_SSC_TX_Ready()) ;
|
||||
FPGA_SSC_TX_Value(send_word);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
@@ -379,9 +381,9 @@ void TransmitTo15693Reader(const uint8_t *cmd, size_t len, uint32_t *start_time,
|
||||
uint8_t cmd_bits = ((cmd[c] >> i) & 0x01) ? 0xff : 0x00;
|
||||
|
||||
for (int j = 0; j < (slow ? 4 : 1);) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
bits_to_send = bits_to_shift << (8 - shift_delay) | cmd_bits >> shift_delay;
|
||||
AT91C_BASE_SSC->SSC_THR = bits_to_send;
|
||||
FPGA_SSC_TX_Value(bits_to_send);
|
||||
bits_to_shift = cmd_bits;
|
||||
j++;
|
||||
}
|
||||
@@ -394,8 +396,8 @@ void TransmitTo15693Reader(const uint8_t *cmd, size_t len, uint32_t *start_time,
|
||||
bits_to_send = bits_to_shift << (8 - shift_delay);
|
||||
if (bits_to_send) {
|
||||
for (; ;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||
AT91C_BASE_SSC->SSC_THR = bits_to_send;
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(bits_to_send);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1018,7 +1020,7 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||
}
|
||||
|
||||
// wait for last transfer to complete
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXEMPTY));
|
||||
while (!FPGA_SSC_TX_Done());
|
||||
|
||||
// And put the FPGA in the appropriate mode
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_2SUBCARRIERS_424_484_KHZ | FPGA_HF_READER_MODE_RECEIVE_AMPLITUDE);
|
||||
@@ -1030,10 +1032,8 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||
dmabuf16_t *dma = get_dma16();
|
||||
|
||||
// Setup and start DMA.
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) {
|
||||
Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
}
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
return PM3_EINIT;
|
||||
}
|
||||
|
||||
@@ -1042,7 +1042,7 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||
|
||||
for (;;) {
|
||||
|
||||
volatile uint16_t behindBy = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
volatile uint16_t behindBy = ((uint16_t *)FPGA_SSC_DMA_RX_Current_Address() - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behindBy == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -1059,18 +1059,9 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||
upTo = dma->buf; // start reading the circular buffer from the beginning
|
||||
|
||||
// DMA Counter Register had reached 0, already rotated.
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||
if (FPGA_SSC_DMA_RX_Done()) {
|
||||
|
||||
// primary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
// secondary buffer sets as primary, secondary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
|
||||
|
||||
WDT_HIT();
|
||||
if (BUTTON_PRESS()) {
|
||||
@@ -1137,7 +1128,7 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
|
||||
}
|
||||
}
|
||||
|
||||
FpgaDisableSscDma();
|
||||
FPGA_SSC_DMA_RX_Disable();
|
||||
FpgaDisableTracing();
|
||||
|
||||
uint32_t sof_time = *eof_time - (32 * 16); // time for SOF transfer
|
||||
@@ -1530,22 +1521,20 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
||||
DecodeReaderInit(dr, received, max_len, 0, NULL);
|
||||
|
||||
// wait for last transfer to complete
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXEMPTY));
|
||||
while (!FPGA_SSC_TX_Done());
|
||||
|
||||
LED_D_OFF();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR | FPGA_HF_SIMULATOR_NO_MODULATION);
|
||||
|
||||
// clear receive register and wait for next transfer
|
||||
uint32_t temp = AT91C_BASE_SSC->SSC_RHR;
|
||||
uint32_t temp = FPGA_SSC_RX_Value();
|
||||
(void) temp;
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)) ;
|
||||
FPGA_SSC_RX_READY_WAIT();
|
||||
|
||||
// Setup and start DMA.
|
||||
dmabuf8_t *dma = get_dma8();
|
||||
if (FpgaSetupSscDma(dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) {
|
||||
Dbprintf("FpgaSetupSscDma failed. Exiting");
|
||||
}
|
||||
if (FpgaSetupSscRxDmaRepeat(dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
return -4;
|
||||
}
|
||||
const uint8_t *upTo = dma->buf;
|
||||
@@ -1553,7 +1542,7 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
||||
uint32_t dma_start_time = GetCountSspClk() & 0xfffffff8;
|
||||
|
||||
for (;;) {
|
||||
volatile uint16_t behindBy = ((uint8_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
volatile uint16_t behindBy = ((uint8_t *)FPGA_SSC_DMA_RX_Current_Address() - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behindBy == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -1571,9 +1560,9 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) { // DMA Counter Register had reached 0, already rotated.
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf; // refresh the DMA Next Buffer and
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE; // DMA Next Counter registers
|
||||
|
||||
if (FPGA_SSC_DMA_RX_Done()) { // DMA Counter Register had reached 0, already rotated.
|
||||
FPGA_SSC_DMA_RX_Refresh_Single(dma->buf, DMA_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
@@ -1605,7 +1594,7 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
||||
WDT_HIT();
|
||||
}
|
||||
|
||||
FpgaDisableSscDma();
|
||||
FPGA_SSC_DMA_RX_Disable();
|
||||
|
||||
if (dr->byteCount >= 0) {
|
||||
uint32_t sof_time = *eof_time
|
||||
@@ -1651,7 +1640,7 @@ void AcquireRawAdcSamplesIso15693(void) {
|
||||
|
||||
// initialize SSC and select proper AD input
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
StartCountSspClk();
|
||||
|
||||
@@ -1665,19 +1654,19 @@ void AcquireRawAdcSamplesIso15693(void) {
|
||||
TransmitTo15693Tag(ts->buf, ts->max, &start_time, false);
|
||||
|
||||
// wait for last transfer to complete
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXEMPTY)) ;
|
||||
while (!FPGA_SSC_TX_Done()) ;
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_SUBCARRIER_424_KHZ | FPGA_HF_READER_MODE_RECEIVE_AMPLITUDE);
|
||||
|
||||
for (int c = 0; c < 4000;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
uint16_t r = AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
uint16_t r = FPGA_SSC_RX_Value();
|
||||
dest[c++] = r >> 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FpgaDisableSscDma();
|
||||
FPGA_SSC_DMA_RX_Disable();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LEDsoff();
|
||||
}
|
||||
@@ -1712,7 +1701,7 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string, bool icla
|
||||
|
||||
LED_D_OFF();
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
|
||||
StartCountSspClk();
|
||||
@@ -1721,10 +1710,8 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string, bool icla
|
||||
dmabuf16_t *dma = get_dma16();
|
||||
|
||||
// Setup and start DMA.
|
||||
if (FpgaSetupSscDma((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) {
|
||||
DbpString("FpgaSetupSscDma failed. Exiting");
|
||||
}
|
||||
if (FpgaSetupSscRxDmaRepeat((uint8_t *) dma->buf, DMA_BUFFER_SIZE) == false) {
|
||||
if (g_dbglevel > DBG_ERROR) DbpString("FpgaSetupSscRxDmaRepeat failed. Exiting");
|
||||
switch_off();
|
||||
return;
|
||||
}
|
||||
@@ -1743,7 +1730,7 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string, bool icla
|
||||
|
||||
for (;;) {
|
||||
|
||||
volatile int behind_by = ((uint16_t *)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
volatile int behind_by = ((uint16_t *)FPGA_SSC_DMA_RX_Current_Address() - upTo) & (DMA_BUFFER_SIZE - 1);
|
||||
if (behind_by < 1) {
|
||||
continue;
|
||||
}
|
||||
@@ -1765,18 +1752,9 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string, bool icla
|
||||
upTo = dma->buf;
|
||||
|
||||
// DMA Counter Register had reached 0, already rotated.
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX)) {
|
||||
if (FPGA_SSC_DMA_RX_Done()) {
|
||||
|
||||
// primary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
// secondary buffer sets as primary, secondary buffer was stopped
|
||||
if (AT91C_BASE_PDC_SSC->PDC_RNCR == 0) {
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) dma->buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
|
||||
}
|
||||
FPGA_SSC_DMA_RX_Refresh_Repeat(dma->buf, DMA_BUFFER_SIZE);
|
||||
|
||||
WDT_HIT();
|
||||
if (BUTTON_PRESS()) {
|
||||
@@ -1925,7 +1903,7 @@ void Iso15693InitReader(void) {
|
||||
|
||||
// initialize SSC and select proper AD input
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
set_tracing(true);
|
||||
|
||||
@@ -2173,7 +2151,7 @@ void Iso15693InitTag(void) {
|
||||
|
||||
// initialize SSC and select proper AD input
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
clear_trace();
|
||||
set_tracing(true);
|
||||
@@ -2285,7 +2263,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
|
||||
// find reader field
|
||||
if (tag->state == TAG_STATE_NO_FIELD) {
|
||||
|
||||
vHf = (MAX_ADC_HF_VOLTAGE * SumAdc(ADC_CHAN_HF, 32)) >> 15;
|
||||
vHf = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_HF);
|
||||
if (vHf > MF_MINFIELDV) {
|
||||
tag->state = TAG_STATE_READY;
|
||||
LED_A_ON();
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
at your option, any later version. See the LICENSE.txt file for the text of
|
||||
the license.
|
||||
-----------------------------------------------------------------------------
|
||||
Linker script for the ARM binary
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
INCLUDE ../common_arm/ldscript.common
|
||||
|
||||
PHDRS
|
||||
{
|
||||
text PT_LOAD FLAGS(5);
|
||||
data PT_LOAD;
|
||||
bss PT_LOAD;
|
||||
}
|
||||
|
||||
ENTRY(Vector)
|
||||
SECTIONS
|
||||
{
|
||||
.start : {
|
||||
*(.startos)
|
||||
} >osimage :text
|
||||
|
||||
.text : {
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.eh_frame)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
} >osimage :text
|
||||
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
*(fpga_all_bit.data)
|
||||
. = ALIGN(8);
|
||||
} >osimage :text
|
||||
|
||||
.data : {
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(.ramfunc)
|
||||
. = ALIGN(4);
|
||||
} >ram AT>osimage :data
|
||||
|
||||
__data_src_start__ = LOADADDR(.data);
|
||||
__data_start__ = ADDR(.data);
|
||||
__data_end__ = __data_start__ + SIZEOF(.data);
|
||||
__os_size__ = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata);
|
||||
|
||||
.bss : {
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
} >ram AT>ram :bss
|
||||
|
||||
.commonarea (NOLOAD) : {
|
||||
*(.commonarea)
|
||||
} >commonarea :NONE
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
at your option, any later version. See the LICENSE.txt file for the text of
|
||||
the license.
|
||||
-----------------------------------------------------------------------------
|
||||
Linker script for the ARM binary
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
INCLUDE ../common_arm/ldscript.defs.at32
|
||||
INCLUDE ../common_arm/ldscript.common
|
||||
|
||||
INCLUDE ./ldscript.osimage.phdrs
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH, AT32 is startup from 'startup_at32f435_437.s' */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >osimage :text
|
||||
}
|
||||
|
||||
INCLUDE ./ldscript.osimage.sections
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
at your option, any later version. See the LICENSE.txt file for the text of
|
||||
the license.
|
||||
-----------------------------------------------------------------------------
|
||||
Linker script for the ARM binary
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
INCLUDE ../common_arm/ldscript.defs.at91
|
||||
INCLUDE ../common_arm/ldscript.common
|
||||
|
||||
INCLUDE ./ldscript.osimage.phdrs
|
||||
|
||||
ENTRY(Vector)
|
||||
|
||||
INCLUDE ./ldscript.osimage.sections
|
||||
@@ -0,0 +1,6 @@
|
||||
PHDRS
|
||||
{
|
||||
text PT_LOAD FLAGS(5);
|
||||
data PT_LOAD;
|
||||
bss PT_LOAD;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* See LICENSE.txt for the text of the license.
|
||||
*-----------------------------------------------------------------------------
|
||||
*-----------------------------------------------------------------------------
|
||||
* Common linker script, for os image for sections.
|
||||
*-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.start : {
|
||||
*(.startos)
|
||||
} >osimage :text
|
||||
|
||||
.text : {
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.eh_frame)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
} >osimage :text
|
||||
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
*(fpga_all_bit.data)
|
||||
. = ALIGN(8);
|
||||
} >osimage :text
|
||||
|
||||
.data : {
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(.ramfunc)
|
||||
. = ALIGN(4);
|
||||
} >ram AT>osimage :data
|
||||
|
||||
__data_src_start__ = LOADADDR(.data);
|
||||
__data_start__ = ADDR(.data);
|
||||
__data_end__ = __data_start__ + SIZEOF(.data);
|
||||
__os_size__ = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata);
|
||||
|
||||
.bss : {
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
} >ram AT>ram :bss
|
||||
|
||||
.commonarea (NOLOAD) : {
|
||||
*(.commonarea)
|
||||
} >commonarea :NONE
|
||||
}
|
||||
+12
-12
@@ -24,8 +24,9 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "string.h"
|
||||
@@ -75,8 +76,8 @@ static uint16_t rx_frame_from_fpga(void) {
|
||||
WDT_HIT();
|
||||
|
||||
// wait for frame be become available in rx holding register
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
return AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
return FPGA_SSC_RX_Value();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -143,12 +144,12 @@ static bool rx_bit(void) {
|
||||
|
||||
static void tx_bit(bool bit) {
|
||||
// insert pause
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
last_frame_end += RWD_TIME_PAUSE;
|
||||
while (GET_TICKS < last_frame_end) { };
|
||||
|
||||
// return to carrier on, wait for bit periode to end
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
last_frame_end += (bit ? RWD_TIME_1 : RWD_TIME_0) - RWD_TIME_PAUSE;
|
||||
while (GET_TICKS < last_frame_end) { };
|
||||
}
|
||||
@@ -181,10 +182,10 @@ static void tx_frame(uint32_t frame, uint8_t len) {
|
||||
};
|
||||
|
||||
// add pause to mark end of the frame
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
last_frame_end += RWD_TIME_PAUSE;
|
||||
while (GET_TICKS < last_frame_end) { };
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
// log
|
||||
uint8_t cmdbytes[] = {len, BYTEx(frame, 0), BYTEx(frame, 1), BYTEx(frame, 2)};
|
||||
@@ -288,16 +289,15 @@ static void init_reader(void) {
|
||||
// configure FPGA
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER | FPGA_HF_READER_SUBCARRIER_212_KHZ | FPGA_HF_READER_MODE_RECEIVE_IQ);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
LED_A_ON();
|
||||
|
||||
// configure SSC with defaults
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
|
||||
// re-claim GPIO_SSC_DOUT as GPIO and enable output
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
gpio_fpga_mod_only_setup();
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
// reserve a cardmem, meaning we can use the tracelog function in bigbuff easier.
|
||||
legic_mem = BigBuf_get_EM_addr();
|
||||
|
||||
+11
-11
@@ -24,8 +24,9 @@
|
||||
#include "cmd.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -75,7 +76,7 @@ static uint32_t last_frame_end; /* ts of last bit of previews rx or tx frame */
|
||||
// Returns true if a pulse/pause is received within timeout
|
||||
// Note: inlining this function would fail with -Os
|
||||
static bool wait_for(bool value, const uint32_t timeout) {
|
||||
while ((bool)(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_DIN) != value) {
|
||||
while (Gpio_SSC_DIN_Read() != value) {
|
||||
WDT_HIT();
|
||||
if (GetCountSspClk() > timeout) {
|
||||
return false;
|
||||
@@ -142,10 +143,10 @@ static void tx_bit(bool bit) {
|
||||
|
||||
if (bit) {
|
||||
// modulate subcarrier
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
} else {
|
||||
// do not modulate subcarrier
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
}
|
||||
|
||||
// wait for tx timeslot to end
|
||||
@@ -181,7 +182,7 @@ static void tx_frame(uint32_t frame, uint8_t len) {
|
||||
};
|
||||
|
||||
// disable subcarrier
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
// log
|
||||
uint8_t cmdbytes[] = {len, BYTEx(frame, 0), BYTEx(frame, 1)};
|
||||
@@ -202,7 +203,7 @@ static void tx_ack(void) {
|
||||
legic_prng_forward(1);
|
||||
|
||||
// disable subcarrier
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
// log
|
||||
uint8_t cmdbytes[] = {1, 1};
|
||||
@@ -313,15 +314,14 @@ static void init_tag(void) {
|
||||
// configure FPGA
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR | FPGA_HF_SIMULATOR_MODULATE_212K);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_HIPKD);
|
||||
|
||||
// configure SSC with defaults
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR);
|
||||
|
||||
// first pull output to low to prevent glitches then re-claim GPIO_SSC_DOUT
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
Gpio_SSC_DOUT_Low();
|
||||
gpio_fpga_mod_only_setup();
|
||||
|
||||
// reserve a cardmem, meaning we can use the tracelog function in bigbuff easier.
|
||||
legic_mem = BigBuf_get_EM_addr();
|
||||
|
||||
+111
-76
@@ -18,8 +18,9 @@
|
||||
|
||||
#include "lfadc.h"
|
||||
#include "lfsampling.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "appmain.h"
|
||||
|
||||
@@ -40,14 +41,15 @@
|
||||
// Exported global variables
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool g_logging = true;
|
||||
bool g_logging = false; // TODO DXL 在某些情况下,读不到卡的时候,此处可能会造成内存溢出,需要解决
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Global variables
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool rising_edge = false;
|
||||
static bool reader_mode = false;
|
||||
static lf_adc_init_mode_t g_init_mode = LF_ADC_READER;
|
||||
static lf_adc_edge_mode_t g_edge_mode = LF_ADC_WAV_REVERSED;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Auxiliary functions
|
||||
@@ -62,32 +64,35 @@ bool lf_test_periods(size_t expected, size_t count) {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Low frequency (LF) adc passthrough functionality
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
static uint8_t previous_adc_val = 0; //0xFF;
|
||||
static uint8_t previous_adc_val = 0; // 0xFF;
|
||||
static uint8_t adc_avg = 0;
|
||||
static uint8_t adc_max;
|
||||
static uint8_t adc_min;
|
||||
|
||||
uint8_t get_adc_avg(void) {
|
||||
uint8_t lf_get_adc_avg(void) {
|
||||
return adc_avg;
|
||||
}
|
||||
|
||||
void lf_sample_mean(void) {
|
||||
uint8_t periods = 0;
|
||||
uint32_t adc_sum = 0;
|
||||
adc_max = 0;
|
||||
adc_min = 255;
|
||||
while (periods < 32) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
adc_sum += AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
const uint8_t adc_val = FPGA_SSC_RX_Value();
|
||||
if (adc_val < adc_min) adc_min = adc_val;
|
||||
if (adc_val > adc_max) adc_max = adc_val;
|
||||
adc_sum += adc_val;
|
||||
periods++;
|
||||
}
|
||||
}
|
||||
// division by 32
|
||||
adc_avg = adc_sum >> 5;
|
||||
adc_avg = adc_sum >> 5; // division by 32
|
||||
previous_adc_val = adc_avg;
|
||||
|
||||
if (g_dbglevel >= DBG_EXTENDED) {
|
||||
Dbprintf("LF ADC average %u", adc_avg);
|
||||
}
|
||||
DBG Dbprintf("LF ADC average %u, max %u, min %u, diff %u", adc_avg, adc_max, adc_min, adc_max - adc_min);
|
||||
}
|
||||
|
||||
static size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
|
||||
|
||||
#define LIMIT_DEV 20
|
||||
|
||||
// timeout limit to 100 000 w/o
|
||||
@@ -101,61 +106,68 @@ static size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
|
||||
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
DBG Dbprintf("Error, timeout for wait adc value rx");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00;
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
FPGA_SSC_TX_Value(0x00);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
if (FPGA_SSC_RX_Ready() == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
periods++;
|
||||
periods++; // T0 increment, 1(TO) = 8us, same with 125khz clock.
|
||||
timeout = 100000; // reset timeout
|
||||
volatile uint8_t adc_val = FPGA_SSC_RX_Value(); // Get current adc value.
|
||||
|
||||
// reset timeout
|
||||
timeout = 100000;
|
||||
if (g_logging) {
|
||||
logSampleSimple(adc_val);
|
||||
}
|
||||
|
||||
volatile uint8_t adc_val = AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
if (g_logging) {
|
||||
logSampleSimple(adc_val);
|
||||
}
|
||||
|
||||
// Only test field changes if state of adc values matter
|
||||
if (wait == false) {
|
||||
// Test if we are locating a field modulation (100% ASK = complete field drop)
|
||||
if (detect_gap) {
|
||||
// Only return when the field completely disappeared
|
||||
if (adc_val == 0) {
|
||||
return periods;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Trigger on a modulation swap by observing an edge change
|
||||
// Only test field changes if state of adc values matter
|
||||
if (wait == false) {
|
||||
// Test if we are locating a field modulation (100% ASK = complete field drop)
|
||||
if (detect_gap) {
|
||||
// Only return when the field completely disappeared
|
||||
if (adc_val == 0) {
|
||||
return periods;
|
||||
}
|
||||
} else {
|
||||
if (g_edge_mode == LF_ADC_WAV_REVERSED) {
|
||||
if (rising_edge) {
|
||||
|
||||
if ((previous_adc_val > avg_peak) && (adc_val <= previous_adc_val)) {
|
||||
rising_edge = false;
|
||||
return periods;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ((previous_adc_val < avg_through) && (adc_val >= previous_adc_val)) {
|
||||
rising_edge = true;
|
||||
return periods;
|
||||
}
|
||||
|
||||
}
|
||||
} else if (g_edge_mode == LF_ADC_NOT_REVERSED) {
|
||||
if (rising_edge) {
|
||||
if (adc_val <= adc_avg && adc_val <= avg_through) {
|
||||
rising_edge = false;
|
||||
return periods;
|
||||
}
|
||||
} else {
|
||||
if (adc_val >= avg_peak) {
|
||||
rising_edge = true;
|
||||
return periods;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previous_adc_val = adc_val;
|
||||
previous_adc_val = adc_val;
|
||||
|
||||
if (periods >= max) {
|
||||
return 0;
|
||||
}
|
||||
if (periods >= max) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,18 +187,17 @@ size_t lf_detect_gap(size_t max) {
|
||||
}
|
||||
|
||||
void lf_reset_counter(void) {
|
||||
|
||||
// TODO: find out the correct reset settings for tag and reader mode
|
||||
// if (reader_mode) {
|
||||
// if (g_init_mode == LF_ADC_READER) {
|
||||
// Reset values for reader mode
|
||||
rising_edge = false;
|
||||
previous_adc_val = 0xFF;
|
||||
|
||||
// } else {
|
||||
// } else {
|
||||
// Reset values for tag/transponder mode
|
||||
// rising_edge = false;
|
||||
// previous_adc_val = 0xFF;
|
||||
// }
|
||||
// rising_edge = false;
|
||||
// previous_adc_val = 0xFF;
|
||||
// }
|
||||
}
|
||||
|
||||
bool lf_get_tag_modulation(void) {
|
||||
@@ -198,15 +209,15 @@ bool lf_get_reader_modulation(void) {
|
||||
}
|
||||
|
||||
void lf_wait_periods(size_t periods) {
|
||||
// wait detect gap
|
||||
// wait for detect gap
|
||||
lf_count_edge_periods_ex(periods, true, false);
|
||||
}
|
||||
|
||||
void lf_init(bool reader, bool simulate, bool ledcontrol) {
|
||||
|
||||
void lf_init(lf_adc_init_mode_t init_mode, lf_adc_edge_mode_t edge_mode, bool ledcontrol) {
|
||||
StopTicks();
|
||||
|
||||
reader_mode = reader;
|
||||
g_init_mode = init_mode;
|
||||
g_edge_mode = edge_mode;
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
|
||||
@@ -216,21 +227,22 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
|
||||
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, sc->divisor);
|
||||
|
||||
if (reader) {
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
|
||||
} else {
|
||||
|
||||
if (simulate) {
|
||||
// Different fpga config for different mode.
|
||||
switch (g_init_mode) {
|
||||
case LF_ADC_READER:
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
|
||||
break;
|
||||
case LF_ADC_TAG_SIM:
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC);
|
||||
} else {
|
||||
// Sniff
|
||||
break;
|
||||
case LF_ADC_SNIFF:
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC);
|
||||
// FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Connect the A/D to the peak-detected low-frequency path.
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
|
||||
// Now set up the SSC to get the ADC samples that are now streaming at us.
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_LF_READER);
|
||||
@@ -242,12 +254,16 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
|
||||
// maximum: 545T0 = 545 * 8us = 4360us = 4.36ms - Hitag2 command waiting time before it starts transmitting in public mode (if configured so)
|
||||
// 565T0 = 565 * 8us = 4520us = 4.52ms - HitagS waiting time before entering TTF mode (if configured so)
|
||||
// Thus (2.50 ms + 4.36 ms) / 2 ~= 3 ms (rounded down to integer), should be a good timing for both tag models
|
||||
SpinDelay(3);
|
||||
SpinDelay(2); // TODO DXL 之前是 3ms,改成2ms测试hitagU
|
||||
// TODO DXL 经测试,3ms时hitag2工作的很好,但是hitagu会进入TTF模式导致无法寻卡
|
||||
// hitagu用2ms延时比较靠谱
|
||||
// lf_wait_periods(200); // TODO DXL zx8268 用这个时长才能正常寻卡,3ms的话,8268直接开始广播了,没办法通信上了
|
||||
|
||||
// Steal this pin from the SSP (SPI communication channel with fpga) and use it to control the modulation
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
gpio_fpga_mod_only_setup();
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
/* TODO DXL 暂时注释,看看哪里没用到这些定时器的,如果都没用到,则可以删掉
|
||||
|
||||
// Enable peripheral Clock for TIMER_CLOCK 0
|
||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0);
|
||||
@@ -259,9 +275,13 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV4_CLOCK;
|
||||
|
||||
*/
|
||||
|
||||
// Clear all leds
|
||||
if (ledcontrol) LEDsoff();
|
||||
|
||||
/* TODO DXL 暂时注释,看看哪里没用到这些定时器的,如果都没用到,则可以删掉
|
||||
|
||||
// Reset and enable timers
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
|
||||
@@ -269,6 +289,8 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
|
||||
// Assert a sync signal. This sets all timers to 0 on next active clock edge
|
||||
AT91C_BASE_TCB->TCB_BCR = 1;
|
||||
|
||||
*/
|
||||
|
||||
// Prepare data trace
|
||||
uint32_t bufsize = 10000;
|
||||
|
||||
@@ -281,6 +303,8 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
|
||||
}
|
||||
|
||||
void lf_finalize(bool ledcontrol) {
|
||||
/* TODO DXL 暂时注释,看看哪里没用到这些定时器的,如果都没用到,则可以删掉
|
||||
|
||||
// Disable timers
|
||||
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
|
||||
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
|
||||
@@ -289,6 +313,8 @@ void lf_finalize(bool ledcontrol) {
|
||||
AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_ASR = GPIO_SSC_DIN | GPIO_SSC_DOUT;
|
||||
|
||||
*/
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
|
||||
if (ledcontrol) LEDsoff();
|
||||
@@ -316,9 +342,9 @@ size_t lf_detect_field_drop(size_t max) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
periods++;
|
||||
volatile uint8_t adc_val = AT91C_BASE_SSC->SSC_RHR;
|
||||
volatile uint8_t adc_val = FPGA_SSC_RX_Value();
|
||||
|
||||
if (g_logging) logSampleSimple(adc_val);
|
||||
|
||||
@@ -334,11 +360,19 @@ size_t lf_detect_field_drop(size_t max) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lf_reset_field(size_t periods) {
|
||||
// FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
Gpio_SSC_DOUT_High();
|
||||
lf_wait_periods(periods);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
// FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
|
||||
}
|
||||
|
||||
void lf_modulation(bool modulation) {
|
||||
if (modulation) {
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
} else {
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,8 +386,8 @@ static void lf_manchester_send_bit(uint8_t bit) {
|
||||
|
||||
// simulation
|
||||
bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len, bool ledcontrol) {
|
||||
|
||||
if (ledcontrol) LED_B_ON();
|
||||
if (ledcontrol)
|
||||
LED_B_ON();
|
||||
|
||||
lf_manchester_send_bit(1);
|
||||
lf_manchester_send_bit(1);
|
||||
@@ -366,6 +400,7 @@ bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len, bool ledco
|
||||
lf_manchester_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
|
||||
}
|
||||
|
||||
if (ledcontrol) LED_B_OFF();
|
||||
if (ledcontrol)
|
||||
LED_B_OFF();
|
||||
return true;
|
||||
}
|
||||
+26
-3
@@ -27,7 +27,30 @@
|
||||
|
||||
extern bool g_logging;
|
||||
|
||||
uint8_t get_adc_avg(void);
|
||||
/*
|
||||
* Trigger on a modulation swap by observing an edge change
|
||||
* PEAK_THROUGH_LEFT:
|
||||
* 1. When the peak of the falling edge appears to rise, it is considered to be the rising edge.
|
||||
* 2. When the peak of the rising edge drops, it is considered a falling edge.
|
||||
* Note: The edge status is from waveform of the analog signal is reversed.
|
||||
* PEAK_THROUGH_CENTER:
|
||||
* 1. The timing for edge judgment is based on the level range without modulation.
|
||||
* 2. The edge switching will not be determined within the range of the peak of the falling edge and the peak of the rising edge.
|
||||
* Note: not reversed.
|
||||
*/
|
||||
typedef enum {
|
||||
LF_ADC_WAV_REVERSED = 0U,
|
||||
LF_ADC_NOT_REVERSED = 1U,
|
||||
} lf_adc_edge_mode_t;
|
||||
|
||||
// What working mode should the module be initialized to?
|
||||
typedef enum {
|
||||
LF_ADC_READER = 0U,
|
||||
LF_ADC_TAG_SIM = 1U,
|
||||
LF_ADC_SNIFF = 2U,
|
||||
} lf_adc_init_mode_t;
|
||||
|
||||
uint8_t lf_get_adc_avg(void);
|
||||
void lf_sample_mean(void);
|
||||
bool lf_test_periods(size_t expected, size_t count);
|
||||
size_t lf_count_edge_periods(size_t max);
|
||||
@@ -38,10 +61,10 @@ bool lf_get_tag_modulation(void);
|
||||
bool lf_get_reader_modulation(void);
|
||||
|
||||
void lf_wait_periods(size_t periods);
|
||||
//void lf_init(bool reader);
|
||||
void lf_init(bool reader, bool simulate, bool ledcontrol);
|
||||
void lf_init(lf_adc_init_mode_t init_mode, lf_adc_edge_mode_t edge_mode, bool ledcontrol);
|
||||
void lf_finalize(bool ledcontrol);
|
||||
size_t lf_detect_field_drop(size_t max);
|
||||
void lf_reset_field(size_t periods);
|
||||
|
||||
bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len, bool ledcontrol);
|
||||
void lf_modulation(bool modulation);
|
||||
|
||||
+46
-27
@@ -24,8 +24,9 @@
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
@@ -36,7 +37,7 @@
|
||||
#include "lfsampling.h"
|
||||
#include "protocols.h"
|
||||
#include "pmflash.h"
|
||||
#include "flashmem.h" // persistence on flash
|
||||
#include "flashmem.h"
|
||||
#include "spiffs.h" // spiffs
|
||||
#include "appmain.h" // print stack
|
||||
|
||||
@@ -517,6 +518,12 @@ void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint16_t period_0, uint
|
||||
101010101010101[0]000...
|
||||
|
||||
[5555fe852c5555555555555555fe0000]
|
||||
|
||||
|
||||
The current read-write implementation is based on the discontinued model RI-TRP-WR2B-30.
|
||||
The old model is single page, while the new model is multi page, with different operation instructions and communication formats.
|
||||
https://e2e.ti.com/support/wireless-connectivity/other-wireless-group/other-wireless/f/other-wireless-technologies-forum/863988/ri-trp-wr2b-30-replacement-part?tisearch=e2e-sitesearch&keymatch=RI-TRP-WR2B#
|
||||
|
||||
*/
|
||||
void ReadTItag(bool ledcontrol) {
|
||||
StartTicks();
|
||||
@@ -554,6 +561,19 @@ void ReadTItag(bool ledcontrol) {
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
|
||||
// 周期的判断,就是实际上固定的频率采集到的数据,计算实际上所需的过零点的数量,在整个频率内所占用的采集点的数量
|
||||
// 比如123khz的数据调制,从0跨越到1需要更多的时间,那实际上所耗费的在固定频率下所采集的数据的数量更多。
|
||||
// 模拟固定频率采集的 CROSS_LO 数据(123):000001111100000
|
||||
// 模拟固定频率采集的 CROSS_LO 数据(134):000011110000111
|
||||
// 以上例子可以描述出大概的数据变化在采集到的数据中的特征
|
||||
// 采样点数量所需的计算实际易于理解的公式
|
||||
// 123.2khz 一个周期需要 8.116us
|
||||
// 123.2khz 16个周期需要 129.856us
|
||||
// 2mhz 采样一个周期需要 0.0000005s = 500ns
|
||||
// 129.856us / 500ns(0.5us) 就是所需的采样点数量。
|
||||
// 所以看16个fsk的过零点所需要的采样点数量,就基本上能猜测出来当前调制的频率是多少。
|
||||
// HDX调制16个周期的134khz或者123khz,所以这个判断的方法可以这么工作起来。
|
||||
|
||||
for (i = 0; i < n - 1; i++) {
|
||||
// count cycles by looking for lo to hi zero crossings
|
||||
if ((dest[i] < 0) && (dest[i + 1] > 0)) {
|
||||
@@ -655,17 +675,17 @@ static void WriteTIbyte(uint8_t b) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (b & (1 << i)) {
|
||||
// stop modulating antenna 1ms
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
WaitUS(1000);
|
||||
// modulate antenna 1ms
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
WaitUS(1000);
|
||||
} else {
|
||||
// stop modulating antenna 0.3ms
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
WaitUS(300);
|
||||
// modulate antenna 1.7ms
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
WaitUS(1700);
|
||||
}
|
||||
}
|
||||
@@ -683,14 +703,12 @@ void AcquireTiType(bool ledcontrol) {
|
||||
//clear buffer now so it does not interfere with timing later
|
||||
BigBuf_Clear_ext(false);
|
||||
|
||||
// TODO DXL Waiting for cross-platform implementation.
|
||||
|
||||
// Set up the synchronous serial port
|
||||
AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DIN;
|
||||
AT91C_BASE_PIOA->PIO_ASR = GPIO_SSC_DIN;
|
||||
|
||||
// steal this pin from the SSP and use it to control the modulation
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
|
||||
AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST;
|
||||
AT91C_BASE_SSC->SSC_CR = AT91C_SSC_RXEN | AT91C_SSC_TXEN;
|
||||
|
||||
@@ -704,24 +722,29 @@ void AcquireTiType(bool ledcontrol) {
|
||||
AT91C_BASE_SSC->SSC_TCMR = 0;
|
||||
// Transmit Frame Mode Register
|
||||
AT91C_BASE_SSC->SSC_TFMR = 0;
|
||||
|
||||
// iceman, FpgaSetupSsc(FPGA_MAJOR_MODE_LF_READER) ?? the code above? can it be replaced?
|
||||
|
||||
// steal this pin from the SSP and use it to control the modulation
|
||||
gpio_fpga_mod_only_setup();
|
||||
|
||||
if (ledcontrol) LED_D_ON();
|
||||
|
||||
// modulate antenna
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
// start modulate antenna
|
||||
Gpio_SSC_DOUT_High();
|
||||
|
||||
// Charge TI tag for 50ms.
|
||||
WaitMS(50);
|
||||
|
||||
// stop modulating antenna and listen
|
||||
LOW(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_Low();
|
||||
|
||||
if (ledcontrol) LED_D_OFF();
|
||||
|
||||
i = 0;
|
||||
for (;;) {
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
buf[i] = AT91C_BASE_SSC->SSC_RHR; // store 32 bit values in buffer
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
buf[i] = FPGA_SSC_RX_Value(); // store 32 bit values in buffer
|
||||
i++;
|
||||
if (i >= TIBUFLEN) break;
|
||||
}
|
||||
@@ -779,8 +802,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc, bool ledcontrol) {
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
// steal this pin from the SSP and use it to control the modulation
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
gpio_fpga_mod_only_setup();
|
||||
|
||||
// writing algorithm:
|
||||
// a high bit consists of a field off for 1ms and field on for 1ms
|
||||
@@ -793,7 +815,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc, bool ledcontrol) {
|
||||
// finish with 50ms programming time
|
||||
|
||||
// modulate antenna
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
WaitMS(50); // charge time
|
||||
|
||||
WriteTIbyte(0xbb); // keyword
|
||||
@@ -810,7 +832,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc, bool ledcontrol) {
|
||||
WriteTIbyte((crc >> 8) & 0xff); // crc hi
|
||||
WriteTIbyte(0x00); // write frame lo
|
||||
WriteTIbyte(0x03); // write frame hi
|
||||
HIGH(GPIO_SSC_DOUT);
|
||||
Gpio_SSC_DOUT_High();
|
||||
WaitMS(50); // programming time
|
||||
|
||||
if (ledcontrol) LED_A_OFF();
|
||||
@@ -826,7 +848,6 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc, bool ledcontrol) {
|
||||
// note: a call to FpgaDownloadAndGo(FPGA_BITSTREAM_LF) must be done before, but
|
||||
// this may destroy the bigbuf so be sure this is called before calling SimulateTagLowFrequencyEx
|
||||
void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycles) {
|
||||
|
||||
// start us timer
|
||||
StartTicks();
|
||||
|
||||
@@ -847,9 +868,7 @@ void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycl
|
||||
else
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, sc->divisor);
|
||||
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
|
||||
gpio_fpga_mod_feedback_setup();
|
||||
|
||||
uint16_t check = 0;
|
||||
|
||||
@@ -868,7 +887,7 @@ void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycl
|
||||
|
||||
// wait until SSC_CLK goes HIGH
|
||||
// used as a simple detection of a reader field?
|
||||
while (!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
|
||||
while (!(Gpio_SSC_CLK_Read())) {
|
||||
WDT_HIT();
|
||||
if (check == 1000) {
|
||||
if (data_available() || BUTTON_PRESS())
|
||||
@@ -888,7 +907,7 @@ void SimulateTagLowFrequencyEx(int period, int gap, bool ledcontrol, int numcycl
|
||||
check = 0;
|
||||
|
||||
//wait until SSC_CLK goes LOW
|
||||
while (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK) {
|
||||
while (Gpio_SSC_CLK_Read()) {
|
||||
WDT_HIT();
|
||||
if (check == 2000) {
|
||||
if (BUTTON_PRESS() || data_available())
|
||||
@@ -1665,7 +1684,7 @@ void turn_read_lf_on(uint32_t delay) {
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | FPGA_LF_ADC_READER_FIELD);
|
||||
|
||||
// measure antenna strength.
|
||||
//int adcval = ((MAX_ADC_LF_VOLTAGE * (SumAdc(ADC_CHAN_LF, 32) >> 1)) >> 14);
|
||||
//int adcval = AdcRssiAvgToMilliVolt(ADC_RSSI_CH_LF);
|
||||
WaitUS(delay);
|
||||
}
|
||||
|
||||
|
||||
+23
-20
@@ -20,14 +20,15 @@
|
||||
|
||||
#include "proxmark3_arm.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "ticks.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "dbprint.h"
|
||||
#include "util.h"
|
||||
#include "lfdemod.h"
|
||||
#include "string.h" // memset
|
||||
#include "appmain.h" // print stack
|
||||
#include "usb_cdc.h" // real-time sampling
|
||||
#include "usb_cdc_apis.h"
|
||||
#include "lfops.h"
|
||||
|
||||
/*
|
||||
@@ -273,7 +274,7 @@ void LFSetupFPGAForADC(int divisor, bool reader_field) {
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | (reader_field ? FPGA_LF_ADC_READER_FIELD : 0));
|
||||
|
||||
// Connect the A/D to the peak-detected low-frequency path.
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
|
||||
// Now set up the SSC to get the ADC samples that are now streaming at us.
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_LF_READER);
|
||||
@@ -335,12 +336,12 @@ uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, in
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (ledcontrol && (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY)) {
|
||||
if (ledcontrol && FPGA_SSC_TX_Ready()) {
|
||||
LED_D_ON();
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
|
||||
// (RDV4) Test point 8 (TP8) can be used to trigger oscilloscope
|
||||
if (ledcontrol) LED_D_OFF();
|
||||
@@ -399,6 +400,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, in
|
||||
uint32_t DoAcquisition_default(int trigger_threshold, bool verbose, bool ledcontrol) {
|
||||
return DoAcquisition(1, 8, 0, trigger_threshold, verbose, 0, 0, 0, ledcontrol);
|
||||
}
|
||||
|
||||
uint32_t DoAcquisition_config(bool verbose, uint32_t sample_size, bool ledcontrol) {
|
||||
return DoAcquisition(config.decimation
|
||||
, config.bits_per_sample
|
||||
@@ -468,9 +470,11 @@ int ReadLF_realtime(bool reader_field, bool cotag) {
|
||||
uint8_t curr_byte = 0;
|
||||
int return_value = PM3_SUCCESS;
|
||||
|
||||
uint32_t sample_buffer_len = AT91C_USB_EP_IN_SIZE;
|
||||
uint32_t usb_buffer_len = 0, sample_buffer_len;
|
||||
usb_get_ep_size(NULL, &usb_buffer_len, NULL);
|
||||
sample_buffer_len = usb_buffer_len; // If sample_buffer_len is not specified, a buffer of random length may be requested.
|
||||
initSampleBuffer(&sample_buffer_len);
|
||||
if (sample_buffer_len != AT91C_USB_EP_IN_SIZE) {
|
||||
if (sample_buffer_len != usb_buffer_len) {
|
||||
return PM3_EFAILED;
|
||||
}
|
||||
|
||||
@@ -503,12 +507,12 @@ int ReadLF_realtime(bool reader_field, bool cotag) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if ((AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY)) {
|
||||
if (FPGA_SSC_TX_Ready()) {
|
||||
LED_D_ON();
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
|
||||
// (RDV4) Test point 8 (TP8) can be used to trigger oscilloscope
|
||||
LED_D_OFF();
|
||||
@@ -621,12 +625,12 @@ void doT55x7Acquisition(size_t sample_size, bool ledcontrol) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (ledcontrol && (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY)) {
|
||||
if (ledcontrol && FPGA_SSC_TX_Ready()) {
|
||||
LED_D_ON();
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
if (ledcontrol) LED_D_OFF();
|
||||
|
||||
// skip until the first high sample above threshold
|
||||
@@ -700,9 +704,8 @@ void doCotagAcquisition(void) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
|
||||
// find first peak
|
||||
if (firsthigh == false) {
|
||||
@@ -770,8 +773,8 @@ uint16_t doCotagAcquisitionManchester(uint8_t *dest, uint16_t destlen) {
|
||||
}
|
||||
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
|
||||
// find first peak
|
||||
if (firsthigh == false) {
|
||||
|
||||
+7
-6
@@ -20,13 +20,14 @@
|
||||
|
||||
#include "BigBuf.h"
|
||||
#include "crc.h" // CRC-8 / Hitag1 / ZX8211
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "dbprint.h"
|
||||
#include "lfops.h" // turn_read_lf_on / off
|
||||
#include "lfadc.h"
|
||||
#include "lfsampling.h" // getSamplingConfig
|
||||
#include "pm3_cmd.h" // struct
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "fpga_apis.h"
|
||||
|
||||
/*
|
||||
ZX8211
|
||||
@@ -106,7 +107,7 @@ static void zx8211_setup_read(void) {
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125);
|
||||
|
||||
// Connect the A/D to the peak-detected low-frequency path.
|
||||
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
|
||||
SetAdcMuxFor(ADC_MUXSEL_LOPKD);
|
||||
|
||||
// Start the timer
|
||||
StartTicks();
|
||||
@@ -145,12 +146,12 @@ static void zx_get(bool ledcontrol) {
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
if (ledcontrol && (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY)) {
|
||||
if (ledcontrol && FPGA_SSC_TX_Ready()) {
|
||||
LED_D_ON();
|
||||
}
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
volatile uint8_t sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
if (FPGA_SSC_RX_Ready()) {
|
||||
volatile uint8_t sample = (uint8_t)FPGA_SSC_RX_Value();
|
||||
(void)sample;
|
||||
|
||||
// (RDV4) Test point 8 (TP8) can be used to trigger oscilloscope
|
||||
|
||||
+5
-4
@@ -26,15 +26,16 @@
|
||||
#include "BigBuf.h"
|
||||
#include "cmd.h"
|
||||
#include "flashmem.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "iso14443a.h"
|
||||
#include "mifaredesfire.h"
|
||||
#include "util.h"
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "usb_cdc.h" // usb_poll_validate_length
|
||||
#include "ticks_apis.h"
|
||||
#include "usb_cdc_apis.h"
|
||||
#include "spiffs.h" // spiffs
|
||||
#include "appmain.h" // print_stack_usage
|
||||
#include "cmac_calc.h"
|
||||
@@ -3431,7 +3432,7 @@ void MifareHasStaticNonce(void) {
|
||||
nt = bytes_to_num(rec, 4);
|
||||
|
||||
// some cards with static nonce need to be reset before next query
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // TODO DXL Can we use mf_reset_card(); ?
|
||||
LEDsoff();
|
||||
CHK_TIMEOUT();
|
||||
|
||||
|
||||
@@ -23,13 +23,14 @@
|
||||
#include "desfire_crypto.h"
|
||||
#include "cmd.h"
|
||||
#include "dbprint.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_loader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "iso14443a.h"
|
||||
#include "crc16.h"
|
||||
#include "commonutil.h"
|
||||
#include "util.h"
|
||||
#include "mifare.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "protocols.h"
|
||||
|
||||
#define MAX_APPLICATION_COUNT 28
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@
|
||||
#include "BigBuf.h"
|
||||
#include "string.h"
|
||||
#include "mifareutil.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "fpga_apis.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "cmd.h"
|
||||
#include "protocols.h"
|
||||
@@ -44,7 +44,7 @@
|
||||
#include "commonutil.h"
|
||||
#include "crc16.h"
|
||||
#include "dbprint.h"
|
||||
#include "ticks.h"
|
||||
#include "ticks_apis.h"
|
||||
#include "parity.h"
|
||||
|
||||
static bool IsKeyBReadable(uint8_t blockNo) {
|
||||
|
||||
Loaded 100 of 200 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user