├── .gitignore
├── .gitmodules
├── Debug-ScreenShot-OnBadge.png
├── Debug-ScreenShot.png
├── LICENSE
├── README.md
├── hardware
├── DC25_Darknet_Badge_BOM.pdf
├── board
│ ├── darknet_parts_library.lbr
│ ├── dc25-darknet-dialer-eaglev8.1.brd
│ ├── dc25-darknet-dialer-eaglev8.1.sch
│ ├── dc25-darknet-dialer-eaglev8.2.brd
│ ├── dc25-darknet-dialer-eaglev8.2.sch
│ ├── dc25-darknet-dialer-eaglev8.3.brd
│ ├── dc25-darknet-dialer-eaglev8.3.sch
│ ├── dc25-darknet-dialer-eaglev8.brd
│ ├── dc25-darknet-dialer-eaglev8.sch
│ ├── dc25-darknet-dialer.brd
│ └── dc25-darknet-dialer.sch
├── docs
│ ├── MCP73831
│ │ └── MCP73831.pdf
│ ├── ST7735
│ │ ├── ILI9163C.pdf
│ │ ├── ST7735-example2.c
│ │ ├── ST7735.c
│ │ ├── ST7735.h
│ │ ├── ST7735.pdf
│ │ ├── ST7735R-Sitronix.pdf
│ │ ├── ST7735S_v1.1.pdf
│ │ ├── ST7735_v2.1.pdf
│ │ └── notes.txt
│ ├── rfm69hcw
│ │ └── RFM69HCW-V1.1.pdf
│ ├── stm32f302rb
│ │ ├── 21dm00105918.pdf
│ │ ├── STM32L4TSC.pdf
│ │ ├── en.DM00094064.pdf
│ │ ├── en.STM32L4_Peripheral_Touchsense.pdf
│ │ ├── en.brstm32f3.pdf
│ │ ├── en.flstm32nucleo.pdf
│ │ └── stm32f302cb-956187.pdf
│ └── vsmb2943slx01
│ │ └── vsmb2943slx01-231148.pdf
└── todo.txt
├── software
├── BadgeGen
│ ├── .cproject
│ ├── .gitignore
│ ├── .project
│ ├── commands.txt
│ ├── openocd-help.txt
│ └── src
│ │ ├── BadgeGen2.cpp
│ │ ├── micro-ecc
│ │ ├── .gitignore
│ │ ├── LICENSE.txt
│ │ ├── README.md
│ │ ├── asm_arm.inc
│ │ ├── asm_arm_mult_square.inc
│ │ ├── asm_arm_mult_square_umaal.inc
│ │ ├── asm_avr.inc
│ │ ├── asm_avr_mult_square.inc
│ │ ├── curve-specific.inc
│ │ ├── emk_project.py
│ │ ├── emk_rules.py
│ │ ├── platform-specific.inc
│ │ ├── scripts
│ │ │ ├── mult_arm.py
│ │ │ ├── mult_avr.py
│ │ │ ├── mult_avr_extra.py
│ │ │ ├── square_arm.py
│ │ │ └── square_avr.py
│ │ ├── test
│ │ │ ├── ecc_test
│ │ │ │ └── ecc_test.ino
│ │ │ ├── emk_rules.py
│ │ │ ├── test_compress.c
│ │ │ ├── test_compute.c
│ │ │ ├── test_ecdh.c
│ │ │ ├── test_ecdsa.c
│ │ │ └── test_ecdsa_deterministic.c.example
│ │ ├── types.h
│ │ ├── uECC.c
│ │ ├── uECC.h
│ │ └── uECC_vli.h
│ │ ├── sha256.cpp
│ │ └── sha256.h
├── DarkNet-EclipseStyle.xml
├── DarknetGateway
│ ├── Makefile
│ ├── README.md
│ └── src
│ │ ├── Hardware.cpp
│ │ ├── Hardware.h
│ │ ├── RFM69.cpp
│ │ ├── RFM69.h
│ │ ├── RFM69registers.h
│ │ ├── RPIHardware.cpp
│ │ ├── RPIHardware.h
│ │ ├── error_type.cpp
│ │ ├── error_type.h
│ │ └── main.cpp
├── cube-src
│ └── firmware
│ │ ├── .cproject
│ │ ├── .mxproject
│ │ ├── .project
│ │ ├── Drivers
│ │ ├── CMSIS
│ │ │ ├── Device
│ │ │ │ └── ST
│ │ │ │ │ └── STM32F3xx
│ │ │ │ │ └── Include
│ │ │ │ │ ├── stm32f302xc.h
│ │ │ │ │ ├── stm32f3xx.h
│ │ │ │ │ └── system_stm32f3xx.h
│ │ │ └── Include
│ │ │ │ ├── arm_common_tables.h
│ │ │ │ ├── arm_const_structs.h
│ │ │ │ ├── arm_math.h
│ │ │ │ ├── cmsis_armcc.h
│ │ │ │ ├── cmsis_armcc_V6.h
│ │ │ │ ├── cmsis_gcc.h
│ │ │ │ ├── core_cm0.h
│ │ │ │ ├── core_cm0plus.h
│ │ │ │ ├── core_cm3.h
│ │ │ │ ├── core_cm4.h
│ │ │ │ ├── core_cm7.h
│ │ │ │ ├── core_cmFunc.h
│ │ │ │ ├── core_cmInstr.h
│ │ │ │ ├── core_cmSimd.h
│ │ │ │ ├── core_sc000.h
│ │ │ │ └── core_sc300.h
│ │ └── STM32F3xx_HAL_Driver
│ │ │ ├── Inc
│ │ │ ├── Legacy
│ │ │ │ └── stm32_hal_legacy.h
│ │ │ ├── stm32f3xx_hal.h
│ │ │ ├── stm32f3xx_hal_cortex.h
│ │ │ ├── stm32f3xx_hal_def.h
│ │ │ ├── stm32f3xx_hal_dma.h
│ │ │ ├── stm32f3xx_hal_dma_ex.h
│ │ │ ├── stm32f3xx_hal_flash.h
│ │ │ ├── stm32f3xx_hal_flash_ex.h
│ │ │ ├── stm32f3xx_hal_gpio.h
│ │ │ ├── stm32f3xx_hal_gpio_ex.h
│ │ │ ├── stm32f3xx_hal_i2c.h
│ │ │ ├── stm32f3xx_hal_i2c_ex.h
│ │ │ ├── stm32f3xx_hal_pcd.h
│ │ │ ├── stm32f3xx_hal_pcd_ex.h
│ │ │ ├── stm32f3xx_hal_pwr.h
│ │ │ ├── stm32f3xx_hal_pwr_ex.h
│ │ │ ├── stm32f3xx_hal_rcc.h
│ │ │ ├── stm32f3xx_hal_rcc_ex.h
│ │ │ ├── stm32f3xx_hal_spi.h
│ │ │ ├── stm32f3xx_hal_spi_ex.h
│ │ │ ├── stm32f3xx_hal_tim.h
│ │ │ ├── stm32f3xx_hal_tim_ex.h
│ │ │ └── stm32f3xx_hal_tsc.h
│ │ │ └── Src
│ │ │ ├── stm32f3xx_hal.c
│ │ │ ├── stm32f3xx_hal_cortex.c
│ │ │ ├── stm32f3xx_hal_dma.c
│ │ │ ├── stm32f3xx_hal_flash.c
│ │ │ ├── stm32f3xx_hal_flash_ex.c
│ │ │ ├── stm32f3xx_hal_gpio.c
│ │ │ ├── stm32f3xx_hal_i2c.c
│ │ │ ├── stm32f3xx_hal_i2c_ex.c
│ │ │ ├── stm32f3xx_hal_pcd.c
│ │ │ ├── stm32f3xx_hal_pcd_ex.c
│ │ │ ├── stm32f3xx_hal_pwr.c
│ │ │ ├── stm32f3xx_hal_pwr_ex.c
│ │ │ ├── stm32f3xx_hal_rcc.c
│ │ │ ├── stm32f3xx_hal_rcc_ex.c
│ │ │ ├── stm32f3xx_hal_spi.c
│ │ │ ├── stm32f3xx_hal_spi_ex.c
│ │ │ ├── stm32f3xx_hal_tim.c
│ │ │ ├── stm32f3xx_hal_tim_ex.c
│ │ │ └── stm32f3xx_hal_tsc.c
│ │ ├── Inc
│ │ ├── dma.h
│ │ ├── gpio.h
│ │ ├── main.h
│ │ ├── spi.h
│ │ ├── stm32f3xx_hal_conf.h
│ │ ├── stm32f3xx_it.h
│ │ ├── tim.h
│ │ ├── tsc.h
│ │ ├── usb_device.h
│ │ ├── usbd_cdc_if.h
│ │ ├── usbd_conf.h
│ │ └── usbd_desc.h
│ │ ├── Middlewares
│ │ └── ST
│ │ │ └── STM32_USB_Device_Library
│ │ │ ├── Class
│ │ │ └── CDC
│ │ │ │ ├── Inc
│ │ │ │ └── usbd_cdc.h
│ │ │ │ └── Src
│ │ │ │ └── usbd_cdc.c
│ │ │ └── Core
│ │ │ ├── Inc
│ │ │ ├── usbd_core.h
│ │ │ ├── usbd_ctlreq.h
│ │ │ ├── usbd_def.h
│ │ │ └── usbd_ioreq.h
│ │ │ └── Src
│ │ │ ├── usbd_core.c
│ │ │ ├── usbd_ctlreq.c
│ │ │ └── usbd_ioreq.c
│ │ ├── STM32F302RBTx_FLASH.ld
│ │ ├── Src
│ │ ├── dma.c
│ │ ├── gpio.c
│ │ ├── main.c
│ │ ├── spi.c
│ │ ├── stm32f3xx_hal_msp.c
│ │ ├── stm32f3xx_it.c
│ │ ├── system_stm32f3xx.c
│ │ ├── tim.c
│ │ ├── tsc.c
│ │ ├── usb_device.c
│ │ ├── usbd_cdc_if.c
│ │ ├── usbd_conf.c
│ │ └── usbd_desc.c
│ │ ├── firmware.ioc
│ │ ├── firmware.xml
│ │ └── startup
│ │ └── startup_stm32f302xc.s
├── firmware-test
│ ├── .cproject
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ └── language.settings.xml
│ ├── Middlewares
│ │ └── ST
│ │ │ └── STM32_USB_Device_Library
│ │ │ ├── Class
│ │ │ └── CDC
│ │ │ │ ├── Inc
│ │ │ │ └── usbd_cdc.h
│ │ │ │ └── Src
│ │ │ │ └── usbd_cdc.c
│ │ │ └── Core
│ │ │ ├── Inc
│ │ │ ├── usbd_core.h
│ │ │ ├── usbd_ctlreq.h
│ │ │ ├── usbd_def.h
│ │ │ └── usbd_ioreq.h
│ │ │ └── Src
│ │ │ ├── usbd_core.c
│ │ │ ├── usbd_ctlreq.c
│ │ │ └── usbd_ioreq.c
│ ├── include
│ │ ├── dma.h
│ │ ├── gpio.h
│ │ ├── mxconstants.h
│ │ ├── spi.h
│ │ ├── stm32f3xx_hal_conf.h
│ │ ├── stm32f3xx_it.h
│ │ ├── tim.h
│ │ ├── tsc.h
│ │ ├── usb_device.h
│ │ ├── usbd_cdc_if.h
│ │ ├── usbd_conf.h
│ │ └── usbd_desc.h
│ ├── ldscripts
│ │ ├── libs.ld
│ │ ├── mem.ld
│ │ └── sections.ld
│ ├── src
│ │ ├── badge
│ │ │ ├── dcdarknet_app.cpp
│ │ │ ├── dcdarknet_app.h
│ │ │ ├── display_device.cpp
│ │ │ ├── display_device.h
│ │ │ ├── error_type.cpp
│ │ │ ├── error_type.h
│ │ │ ├── font.cpp
│ │ │ ├── logger.cpp
│ │ │ └── logger.h
│ │ ├── dma.c
│ │ ├── gpio.c
│ │ ├── main.cpp
│ │ ├── spi.c
│ │ ├── stm32f3xx_hal_msp.c
│ │ ├── stm32f3xx_it.c
│ │ ├── tim.c
│ │ ├── tsc.c
│ │ ├── usb_device.c
│ │ ├── usbd_cdc_if.c
│ │ ├── usbd_conf.c
│ │ └── usbd_desc.c
│ └── system
│ │ ├── include
│ │ ├── arm
│ │ │ └── semihosting.h
│ │ ├── cmsis
│ │ │ ├── README_DEVICE_30x.txt
│ │ │ ├── arm_common_tables.h
│ │ │ ├── arm_const_structs.h
│ │ │ ├── arm_math.h
│ │ │ ├── cmsis_armcc.h
│ │ │ ├── cmsis_armcc_V6.h
│ │ │ ├── cmsis_device.h
│ │ │ ├── cmsis_gcc.h
│ │ │ ├── core_cm0.h
│ │ │ ├── core_cm0plus.h
│ │ │ ├── core_cm3.h
│ │ │ ├── core_cm4.h
│ │ │ ├── core_cm7.h
│ │ │ ├── core_cmFunc.h
│ │ │ ├── core_cmInstr.h
│ │ │ ├── core_cmSimd.h
│ │ │ ├── core_sc000.h
│ │ │ ├── core_sc300.h
│ │ │ └── device
│ │ │ │ ├── stm32f301x8.h
│ │ │ │ ├── stm32f302x8.h
│ │ │ │ ├── stm32f302xc.h
│ │ │ │ ├── stm32f302xe.h
│ │ │ │ ├── stm32f303x8.h
│ │ │ │ ├── stm32f303xc.h
│ │ │ │ ├── stm32f303xe.h
│ │ │ │ ├── stm32f318xx.h
│ │ │ │ ├── stm32f328xx.h
│ │ │ │ ├── stm32f334x8.h
│ │ │ │ ├── stm32f358xx.h
│ │ │ │ ├── stm32f373xc.h
│ │ │ │ ├── stm32f378xx.h
│ │ │ │ ├── stm32f398xx.h
│ │ │ │ ├── stm32f3xx.h
│ │ │ │ └── system_stm32f3xx.h
│ │ ├── cortexm
│ │ │ └── ExceptionHandlers.h
│ │ ├── diag
│ │ │ └── Trace.h
│ │ └── stm32f3xx
│ │ │ ├── Legacy
│ │ │ └── stm32_hal_legacy.h
│ │ │ ├── stm32f3xx_hal.h
│ │ │ ├── stm32f3xx_hal_cortex.h
│ │ │ ├── stm32f3xx_hal_def.h
│ │ │ ├── stm32f3xx_hal_dma.h
│ │ │ ├── stm32f3xx_hal_dma_ex.h
│ │ │ ├── stm32f3xx_hal_flash.h
│ │ │ ├── stm32f3xx_hal_flash_ex.h
│ │ │ ├── stm32f3xx_hal_gpio.h
│ │ │ ├── stm32f3xx_hal_gpio_ex.h
│ │ │ ├── stm32f3xx_hal_i2c.h
│ │ │ ├── stm32f3xx_hal_i2c_ex.h
│ │ │ ├── stm32f3xx_hal_pcd.h
│ │ │ ├── stm32f3xx_hal_pcd_ex.h
│ │ │ ├── stm32f3xx_hal_pwr.h
│ │ │ ├── stm32f3xx_hal_pwr_ex.h
│ │ │ ├── stm32f3xx_hal_rcc.h
│ │ │ ├── stm32f3xx_hal_rcc_ex.h
│ │ │ ├── stm32f3xx_hal_spi.h
│ │ │ ├── stm32f3xx_hal_spi_ex.h
│ │ │ ├── stm32f3xx_hal_tim.h
│ │ │ ├── stm32f3xx_hal_tim_ex.h
│ │ │ └── stm32f3xx_hal_tsc.h
│ │ └── src
│ │ ├── cmsis
│ │ ├── startup_stm32f302xc.S
│ │ └── system_stm32f3xx.c
│ │ ├── cortexm
│ │ ├── _initialize_hardware.c
│ │ ├── _reset_hardware.c
│ │ └── exception_handlers.c
│ │ ├── diag
│ │ ├── Trace.c
│ │ └── trace_impl.c
│ │ ├── newlib
│ │ ├── README.txt
│ │ ├── _cxx.cpp
│ │ ├── _exit.c
│ │ ├── _sbrk.c
│ │ ├── _startup.c
│ │ ├── _syscalls.c
│ │ └── assert.c
│ │ └── stm32f3xx
│ │ ├── stm32f3xx_hal.c
│ │ ├── stm32f3xx_hal_cortex.c
│ │ ├── stm32f3xx_hal_dma.c
│ │ ├── stm32f3xx_hal_flash.c
│ │ ├── stm32f3xx_hal_flash_ex.c
│ │ ├── stm32f3xx_hal_gpio.c
│ │ ├── stm32f3xx_hal_i2c.c
│ │ ├── stm32f3xx_hal_i2c_ex.c
│ │ ├── stm32f3xx_hal_pcd.c
│ │ ├── stm32f3xx_hal_pcd_ex.c
│ │ ├── stm32f3xx_hal_pwr.c
│ │ ├── stm32f3xx_hal_pwr_ex.c
│ │ ├── stm32f3xx_hal_rcc.c
│ │ ├── stm32f3xx_hal_rcc_ex.c
│ │ ├── stm32f3xx_hal_spi.c
│ │ ├── stm32f3xx_hal_spi_ex.c
│ │ ├── stm32f3xx_hal_tim.c
│ │ ├── stm32f3xx_hal_tim_ex.c
│ │ └── stm32f3xx_hal_tsc.c
├── firmware
│ ├── .cproject
│ ├── .gitignore
│ ├── .project
│ ├── Middlewares
│ │ └── ST
│ │ │ └── STM32_USB_Device_Library
│ │ │ ├── Class
│ │ │ └── CDC
│ │ │ │ ├── Inc
│ │ │ │ └── usbd_cdc.h
│ │ │ │ └── Src
│ │ │ │ └── usbd_cdc.c
│ │ │ └── Core
│ │ │ ├── Inc
│ │ │ ├── usbd_core.h
│ │ │ ├── usbd_ctlreq.h
│ │ │ ├── usbd_def.h
│ │ │ └── usbd_ioreq.h
│ │ │ └── Src
│ │ │ ├── usbd_core.c
│ │ │ ├── usbd_ctlreq.c
│ │ │ └── usbd_ioreq.c
│ ├── bin
│ │ └── firmware.hex
│ ├── include
│ │ ├── dma.h
│ │ ├── gpio.h
│ │ ├── main.h
│ │ ├── spi.h
│ │ ├── stm32f3xx_hal_conf.h
│ │ ├── stm32f3xx_it.h
│ │ ├── tim.h
│ │ ├── tsc.h
│ │ ├── usb_device.h
│ │ ├── usbd_cdc_if.h
│ │ ├── usbd_conf.h
│ │ └── usbd_desc.h
│ ├── ldscripts
│ │ ├── libs.ld
│ │ ├── mem.ld
│ │ └── sections.ld
│ ├── src
│ │ ├── badge
│ │ │ ├── 3d
│ │ │ │ ├── menu3d.cpp
│ │ │ │ ├── menu3d.h
│ │ │ │ ├── renderer.cpp
│ │ │ │ ├── renderer.h
│ │ │ │ ├── vec_math.cpp
│ │ │ │ └── vec_math.h
│ │ │ ├── AddressState.cpp
│ │ │ ├── AddressState.h
│ │ │ ├── GameOfLife.cpp
│ │ │ ├── GameOfLife.h
│ │ │ ├── KeyStore.cpp
│ │ │ ├── KeyStore.h
│ │ │ ├── Keyboard.cpp
│ │ │ ├── Keyboard.h
│ │ │ ├── MessageState.cpp
│ │ │ ├── MessageState.h
│ │ │ ├── Radio
│ │ │ │ ├── HardwareSPI.cpp
│ │ │ │ ├── HardwareSPI.h
│ │ │ │ ├── RFM69.cpp
│ │ │ │ ├── RFM69.h
│ │ │ │ └── RFM69registers.h
│ │ │ ├── SendMsgState.cpp
│ │ │ ├── SendMsgState.h
│ │ │ ├── bitarray.cpp
│ │ │ ├── bitarray.h
│ │ │ ├── crc.cpp
│ │ │ ├── crc.h
│ │ │ ├── crypto_helper.cpp
│ │ │ ├── crypto_helper.h
│ │ │ ├── dcdarknet_app.cpp
│ │ │ ├── dcdarknet_app.h
│ │ │ ├── display_device.cpp
│ │ │ ├── display_device.h
│ │ │ ├── error_type.cpp
│ │ │ ├── error_type.h
│ │ │ ├── fonts.cpp
│ │ │ ├── fonts.h
│ │ │ ├── gateway.cpp
│ │ │ ├── gateway.h
│ │ │ ├── gui.cpp
│ │ │ ├── gui.h
│ │ │ ├── images
│ │ │ │ ├── cyberez.cpp
│ │ │ │ └── images.h
│ │ │ ├── ir.cpp
│ │ │ ├── ir.h
│ │ │ ├── irmenu.cpp
│ │ │ ├── irmenu.h
│ │ │ ├── leddc25.cpp
│ │ │ ├── leddc25.h
│ │ │ ├── logger.cpp
│ │ │ ├── logger.h
│ │ │ ├── menus.cpp
│ │ │ └── menus.h
│ │ ├── crypto
│ │ │ ├── micro-ecc
│ │ │ │ ├── .gitignore
│ │ │ │ ├── LICENSE.txt
│ │ │ │ ├── README.md
│ │ │ │ ├── asm_arm.inc
│ │ │ │ ├── asm_arm_mult_square.inc
│ │ │ │ ├── asm_arm_mult_square_umaal.inc
│ │ │ │ ├── asm_avr.inc
│ │ │ │ ├── asm_avr_mult_square.inc
│ │ │ │ ├── curve-specific.inc
│ │ │ │ ├── emk_project.py
│ │ │ │ ├── emk_rules.py
│ │ │ │ ├── platform-specific.inc
│ │ │ │ ├── scripts
│ │ │ │ │ ├── mult_arm.py
│ │ │ │ │ ├── mult_avr.py
│ │ │ │ │ ├── mult_avr_extra.py
│ │ │ │ │ ├── square_arm.py
│ │ │ │ │ └── square_avr.py
│ │ │ │ ├── types.h
│ │ │ │ ├── uECC.c
│ │ │ │ ├── uECC.h
│ │ │ │ └── uECC_vli.h
│ │ │ ├── sha256.cpp
│ │ │ └── sha256.h
│ │ ├── dma.c
│ │ ├── gpio.c
│ │ ├── main.cpp
│ │ ├── spi.c
│ │ ├── stm32f3xx_hal_msp.c
│ │ ├── stm32f3xx_it.c
│ │ ├── tim.c
│ │ ├── tsc.c
│ │ ├── usb_device.c
│ │ ├── usbd_cdc_if.c
│ │ ├── usbd_conf.c
│ │ └── usbd_desc.c
│ └── system
│ │ ├── include
│ │ ├── arm
│ │ │ └── semihosting.h
│ │ ├── cmsis
│ │ │ ├── README_DEVICE_30x.txt
│ │ │ ├── arm_common_tables.h
│ │ │ ├── arm_const_structs.h
│ │ │ ├── arm_math.h
│ │ │ ├── cmsis_armcc.h
│ │ │ ├── cmsis_armcc_V6.h
│ │ │ ├── cmsis_device.h
│ │ │ ├── cmsis_gcc.h
│ │ │ ├── core_cm0.h
│ │ │ ├── core_cm0plus.h
│ │ │ ├── core_cm3.h
│ │ │ ├── core_cm4.h
│ │ │ ├── core_cm7.h
│ │ │ ├── core_cmFunc.h
│ │ │ ├── core_cmInstr.h
│ │ │ ├── core_cmSimd.h
│ │ │ ├── core_sc000.h
│ │ │ ├── core_sc300.h
│ │ │ └── device
│ │ │ │ ├── stm32f302xc.h
│ │ │ │ ├── stm32f3xx.h
│ │ │ │ └── system_stm32f3xx.h
│ │ ├── cortexm
│ │ │ └── ExceptionHandlers.h
│ │ ├── diag
│ │ │ └── Trace.h
│ │ └── stm32f3xx
│ │ │ ├── Legacy
│ │ │ └── stm32_hal_legacy.h
│ │ │ ├── stm32f3xx_hal.h
│ │ │ ├── stm32f3xx_hal_cortex.h
│ │ │ ├── stm32f3xx_hal_def.h
│ │ │ ├── stm32f3xx_hal_dma.h
│ │ │ ├── stm32f3xx_hal_dma_ex.h
│ │ │ ├── stm32f3xx_hal_flash.h
│ │ │ ├── stm32f3xx_hal_flash_ex.h
│ │ │ ├── stm32f3xx_hal_gpio.h
│ │ │ ├── stm32f3xx_hal_gpio_ex.h
│ │ │ ├── stm32f3xx_hal_i2c.h
│ │ │ ├── stm32f3xx_hal_i2c_ex.h
│ │ │ ├── stm32f3xx_hal_pcd.h
│ │ │ ├── stm32f3xx_hal_pcd_ex.h
│ │ │ ├── stm32f3xx_hal_pwr.h
│ │ │ ├── stm32f3xx_hal_pwr_ex.h
│ │ │ ├── stm32f3xx_hal_rcc.h
│ │ │ ├── stm32f3xx_hal_rcc_ex.h
│ │ │ ├── stm32f3xx_hal_spi.h
│ │ │ ├── stm32f3xx_hal_spi_ex.h
│ │ │ ├── stm32f3xx_hal_tim.h
│ │ │ ├── stm32f3xx_hal_tim_ex.h
│ │ │ └── stm32f3xx_hal_tsc.h
│ │ └── src
│ │ ├── cmsis
│ │ ├── startup_stm32f302xc.S
│ │ └── system_stm32f3xx.c
│ │ ├── cortexm
│ │ ├── _initialize_hardware.c
│ │ ├── _reset_hardware.c
│ │ └── exception_handlers.c
│ │ ├── diag
│ │ ├── Trace.c
│ │ └── trace_impl.c
│ │ ├── newlib
│ │ ├── README.txt
│ │ ├── _cxx.cpp
│ │ ├── _exit.c
│ │ ├── _sbrk.c
│ │ ├── _startup.c
│ │ ├── _syscalls.c
│ │ └── assert.c
│ │ └── stm32f3xx
│ │ ├── stm32f3xx_hal.c
│ │ ├── stm32f3xx_hal_cortex.c
│ │ ├── stm32f3xx_hal_dma.c
│ │ ├── stm32f3xx_hal_flash.c
│ │ ├── stm32f3xx_hal_flash_ex.c
│ │ ├── stm32f3xx_hal_gpio.c
│ │ ├── stm32f3xx_hal_i2c.c
│ │ ├── stm32f3xx_hal_i2c_ex.c
│ │ ├── stm32f3xx_hal_pcd.c
│ │ ├── stm32f3xx_hal_pcd_ex.c
│ │ ├── stm32f3xx_hal_pwr.c
│ │ ├── stm32f3xx_hal_pwr_ex.c
│ │ ├── stm32f3xx_hal_rcc.c
│ │ ├── stm32f3xx_hal_rcc_ex.c
│ │ ├── stm32f3xx_hal_spi.c
│ │ ├── stm32f3xx_hal_spi_ex.c
│ │ ├── stm32f3xx_hal_tim.c
│ │ ├── stm32f3xx_hal_tim_ex.c
│ │ └── stm32f3xx_hal_tsc.c
├── import.sh
└── programmer
│ ├── nuke_keys.py
│ ├── openocd
│ ├── __init__.py
│ └── flashProgrammer.py
│ ├── program-normal-user.sh
│ ├── program-uber-user.sh
│ ├── program.py
│ └── test.py
└── stm32cube
└── badge-wiring.ioc
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 | *.obj
6 |
7 | # Precompiled Headers
8 | *.gch
9 | *.pch
10 |
11 | # Compiled Dynamic libraries
12 | *.so
13 | *.dylib
14 | *.dll
15 |
16 | # Fortran module files
17 | *.mod
18 | *.smod
19 |
20 | # Compiled Static libraries
21 | *.lai
22 | *.la
23 | *.a
24 | *.lib
25 |
26 | # Executables
27 | *.exe
28 | *.out
29 | *.app
30 |
31 | *.settings
32 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "software/3rdParty/CubeMXImporter"]
2 | path = software/3rdParty/CubeMXImporter
3 | url = https://github.com/cnoviello/CubeMXImporter.git
4 | [submodule "software/DarknetGateway/src/tbb"]
5 | path = software/DarknetGateway/src/tbb
6 | url = https://github.com/01org/tbb.git
7 |
--------------------------------------------------------------------------------
/Debug-ScreenShot-OnBadge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/Debug-ScreenShot-OnBadge.png
--------------------------------------------------------------------------------
/Debug-ScreenShot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/Debug-ScreenShot.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # defcon25-badge
2 | Badge Related items for defcon 25
3 |
4 | Assembly instructions are located here:
5 |
6 | https://dcdark.net/2017/badge/index.html
7 |
8 | -----
9 | Installation of IDE:
10 | Follow the following instructions (step by step):
11 |
12 | http://gnuarmeclipse.github.io/install/
13 |
14 | Notes: on Window's have gotten both Mars and Luna to work
15 | on linux i've only gotten luna to work (on ubuntu 16.04 LTS)
16 |
17 | Once eclipse is set up here's what the debug config needs to look like, notes the 2 -f openocd scripts that must be configured.
18 |
19 | For 2017 development we are using this nucleo board, while it is not the exact MCU we plan to use it is close and the one we want to use does not have a dev kit.
20 |
21 | http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-nucleo/nucleo-f302r8.html
22 |
23 | 
24 |
25 |
26 | If you have the actual badge board you'll need debugging to look like this:
27 |
28 |
29 | 
30 |
--------------------------------------------------------------------------------
/hardware/DC25_Darknet_Badge_BOM.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/DC25_Darknet_Badge_BOM.pdf
--------------------------------------------------------------------------------
/hardware/docs/MCP73831/MCP73831.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/MCP73831/MCP73831.pdf
--------------------------------------------------------------------------------
/hardware/docs/ST7735/ILI9163C.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/ST7735/ILI9163C.pdf
--------------------------------------------------------------------------------
/hardware/docs/ST7735/ST7735-example2.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/ST7735/ST7735-example2.c
--------------------------------------------------------------------------------
/hardware/docs/ST7735/ST7735.h:
--------------------------------------------------------------------------------
1 | #ifndef ST7335_H
2 | #define ST7335_H
3 |
4 | /* Colors are 565 RGB (5 bits Red, 6 bits green, 5 bits blue) */
5 |
6 | #define BLACK 0x0000
7 | #define BLUE 0x001F
8 | #define GREEN 0x07E0
9 | #define CYAN 0x07FF
10 | #define RED 0xF800
11 | #define MAGENTA 0xF81F
12 | #define YELLOW 0xFFE0
13 | #define WHITE 0xFFFF
14 |
15 | #define SPILCD SPI2
16 |
17 | /* MADCTL [MY MX MV]
18 | * MY row address order 1 (bottom to top), 0 (top to bottom)
19 | * MX col address order 1 (right to left), 0 (left to right)
20 | * MV col/row exchange 1 (exchange), 0 normal
21 | */
22 |
23 | #define MADCTLGRAPHICS 0x6
24 | #define MADCTLBMP 0x2
25 |
26 | #define ST7735_width 128
27 | #define ST7735_height 160
28 |
29 | void ST7735_setAddrWindow(uint16_t x0, uint16_t y0,
30 | uint16_t x1, uint16_t y1, uint8_t madctl);
31 | void ST7735_pushColor(uint16_t *color, int cnt);
32 | void ST7735_init();
33 | void ST7735_backLight(uint8_t on);
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/hardware/docs/ST7735/ST7735.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/ST7735/ST7735.pdf
--------------------------------------------------------------------------------
/hardware/docs/ST7735/ST7735R-Sitronix.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/ST7735/ST7735R-Sitronix.pdf
--------------------------------------------------------------------------------
/hardware/docs/ST7735/ST7735S_v1.1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/ST7735/ST7735S_v1.1.pdf
--------------------------------------------------------------------------------
/hardware/docs/ST7735/ST7735_v2.1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/ST7735/ST7735_v2.1.pdf
--------------------------------------------------------------------------------
/hardware/docs/ST7735/notes.txt:
--------------------------------------------------------------------------------
1 | SDA is infact: MOSI as the board is SPI not I2C
2 |
3 | --https://webcache.googleusercontent.com/search?q=cache:zqTKMD6Ik7kJ:https://community.particle.io/t/solved-getting-the-st7735-to-work-with-spark/11392+&cd=3&hl=en&ct=clnk&gl=us
4 |
5 | https://github.com/XarkLabs/PDQ_GFX_Libs/blob/master/PDQ_ST7735/PDQ_ST7735.h line 513...that's the fastest avr can go but can the display go faster?
6 |
7 |
8 |
9 | --1.44 seem to actually be IL19163C (not st7735)
10 | https://luigidifraia.wordpress.com/2016/02/19/lcd-display-panels-casting-some-light-on-the-mess/
11 | https://forum.pjrc.com/threads/25862-ILI9163C-128x128-TFT-driver
12 | https://github.com/sumotoy/TFT_ILI9163C
13 | http://www.ebay.co.uk/itm/111317541232?afsrc=1&rmvSB=true
14 |
15 | https://forum.arduino.cc/index.php?topic=260605.135
16 |
--------------------------------------------------------------------------------
/hardware/docs/rfm69hcw/RFM69HCW-V1.1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/rfm69hcw/RFM69HCW-V1.1.pdf
--------------------------------------------------------------------------------
/hardware/docs/stm32f302rb/21dm00105918.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/stm32f302rb/21dm00105918.pdf
--------------------------------------------------------------------------------
/hardware/docs/stm32f302rb/STM32L4TSC.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/stm32f302rb/STM32L4TSC.pdf
--------------------------------------------------------------------------------
/hardware/docs/stm32f302rb/en.DM00094064.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/stm32f302rb/en.DM00094064.pdf
--------------------------------------------------------------------------------
/hardware/docs/stm32f302rb/en.STM32L4_Peripheral_Touchsense.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/stm32f302rb/en.STM32L4_Peripheral_Touchsense.pdf
--------------------------------------------------------------------------------
/hardware/docs/stm32f302rb/en.brstm32f3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/stm32f302rb/en.brstm32f3.pdf
--------------------------------------------------------------------------------
/hardware/docs/stm32f302rb/en.flstm32nucleo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/stm32f302rb/en.flstm32nucleo.pdf
--------------------------------------------------------------------------------
/hardware/docs/stm32f302rb/stm32f302cb-956187.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/stm32f302rb/stm32f302cb-956187.pdf
--------------------------------------------------------------------------------
/hardware/docs/vsmb2943slx01/vsmb2943slx01-231148.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/hardware/docs/vsmb2943slx01/vsmb2943slx01-231148.pdf
--------------------------------------------------------------------------------
/hardware/todo.txt:
--------------------------------------------------------------------------------
1 | TODO:
2 | * schema:
3 | * [DONE]: need to add sampling pins for touch to capacitor
4 | * [DONE]: Remove capacitors from touch
5 | * [DONE]: add SD card NSS
6 |
7 |
8 | 4 layer ~$10 per board
9 | 2 layer ~5 per board
10 |
--------------------------------------------------------------------------------
/software/BadgeGen/.gitignore:
--------------------------------------------------------------------------------
1 | /Debug/
2 |
--------------------------------------------------------------------------------
/software/BadgeGen/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | BadgeGen2
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/software/BadgeGen/commands.txt:
--------------------------------------------------------------------------------
1 | flash erase_sector 0 57 63
2 | flash write_bank 0 /home/cmdc0de/dev/defcon/defcon25-badge/software/BadgeGen/keys/9a21 0x1FFD4
3 |
4 | dump_image /home/cmdc0de/dev/defcon/defcon25-badge/software/BadgeGen/keys/BADGE.stm 0x8001FFD4 0x1e
5 | #dump_image /home/cmdc0de/dev/defcon/defcon24/BadgeGen/keys/BADGE.stm-all 0x800FFD4 0x1800
6 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/.gitignore:
--------------------------------------------------------------------------------
1 | __build__/
2 | __pycache__
3 | *.pyc
4 | *.pyo
5 | *.pyd
6 | *.pyz
7 | *.egg-info/
8 | .DS_Store
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Kenneth MacKay
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright notice, this
7 | list of conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright notice,
9 | this list of conditions and the following disclaimer in the documentation
10 | and/or other materials provided with the distribution.
11 |
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/README.md:
--------------------------------------------------------------------------------
1 | micro-ecc
2 | ==========
3 |
4 | A small and fast ECDH and ECDSA implementation for 8-bit, 32-bit, and 64-bit processors.
5 |
6 | The static version of micro-ecc (ie, where the curve was selected at compile-time) can be found in the "static" branch.
7 |
8 | Features
9 | --------
10 |
11 | * Resistant to known side-channel attacks.
12 | * Written in C, with optional GCC inline assembly for AVR, ARM and Thumb platforms.
13 | * Supports 8, 32, and 64-bit architectures.
14 | * Small code size.
15 | * No dynamic memory allocation.
16 | * Support for 5 standard curves: secp160r1, secp192r1, secp224r1, secp256r1, and secp256k1.
17 | * BSD 2-clause license.
18 |
19 | Usage Notes
20 | -----------
21 | ### Point Representation ###
22 | Compressed points are represented in the standard format as defined in http://www.secg.org/collateral/sec1_final.pdf; uncompressed points are represented in standard format, but without the `0x04` prefix. All functions except `uECC_compress()` only accept uncompressed points; use `uECC_compress()` and `uECC_decompress()` to convert between compressed and uncompressed point representations.
23 |
24 | Private keys are represented in the standard format.
25 |
26 | ### Using the Code ###
27 |
28 | I recommend just copying (or symlink) the uECC files into your project. Then just `#include "uECC.h"` to use the micro-ecc functions.
29 |
30 | For use with Arduino, you can just create a symlink to the `uECC` directory in your Arduino `libraries` directory. You can then use uECC just like any other Arduino library (uECC should show up in the **Sketch**=>**Import Library** submenu).
31 |
32 | See uECC.h for documentation for each function.
33 |
34 | ### Compilation Notes ###
35 |
36 | * Should compile with any C/C++ compiler that supports stdint.h (this includes Visual Studio 2013).
37 | * If you want to change the defaults for any of the uECC compile-time options (such as `uECC_OPTIMIZATION_LEVEL`), you must change them in your Makefile or similar so that uECC.c is compiled with the desired values (ie, compile uECC.c with `-DuECC_OPTIMIZATION_LEVEL=3` or whatever).
38 | * When compiling for a Thumb-1 platform, you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher).
39 | * When compiling for an ARM/Thumb-2 platform with `uECC_OPTIMIZATION_LEVEL` >= 3, you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher).
40 | * When compiling for AVR, you must have optimizations enabled (compile with `-O1` or higher).
41 | * When building for Windows, you will need to link in the `advapi32.lib` system library.
42 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/emk_rules.py:
--------------------------------------------------------------------------------
1 | c, link = emk.module("c", "link")
2 |
3 | emk.subdir("test")
4 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/platform-specific.inc:
--------------------------------------------------------------------------------
1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2 |
3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_
4 | #define _UECC_PLATFORM_SPECIFIC_H_
5 |
6 | #include "types.h"
7 |
8 | #if (defined(_WIN32) || defined(_WIN64))
9 | /* Windows */
10 |
11 | #define WIN32_LEAN_AND_MEAN
12 | #include
13 | #include
14 |
15 | static int default_RNG(uint8_t *dest, unsigned size) {
16 | HCRYPTPROV prov;
17 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
18 | return 0;
19 | }
20 |
21 | CryptGenRandom(prov, size, (BYTE *)dest);
22 | CryptReleaseContext(prov, 0);
23 | return 1;
24 | }
25 | #define default_RNG_defined 1
26 |
27 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \
28 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX)
29 |
30 | /* Some POSIX-like system with /dev/urandom or /dev/random. */
31 | #include
32 | #include
33 | #include
34 |
35 | #ifndef O_CLOEXEC
36 | #define O_CLOEXEC 0
37 | #endif
38 |
39 | static int default_RNG(uint8_t *dest, unsigned size) {
40 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
41 | if (fd == -1) {
42 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC);
43 | if (fd == -1) {
44 | return 0;
45 | }
46 | }
47 |
48 | char *ptr = (char *)dest;
49 | size_t left = size;
50 | while (left > 0) {
51 | ssize_t bytes_read = read(fd, ptr, left);
52 | if (bytes_read <= 0) { // read failed
53 | close(fd);
54 | return 0;
55 | }
56 | left -= bytes_read;
57 | ptr += bytes_read;
58 | }
59 |
60 | close(fd);
61 | return 1;
62 | }
63 | #define default_RNG_defined 1
64 |
65 | #endif /* platform */
66 |
67 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */
68 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/test/ecc_test/ecc_test.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern "C" {
4 |
5 | static int RNG(uint8_t *dest, unsigned size) {
6 | // Use the least-significant bits from the ADC for an unconnected pin (or connected to a source of
7 | // random noise). This can take a long time to generate random data if the result of analogRead(0)
8 | // doesn't change very frequently.
9 | while (size) {
10 | uint8_t val = 0;
11 | for (unsigned i = 0; i < 8; ++i) {
12 | int init = analogRead(0);
13 | int count = 0;
14 | while (analogRead(0) == init) {
15 | ++count;
16 | }
17 |
18 | if (count == 0) {
19 | val = (val << 1) | (init & 0x01);
20 | } else {
21 | val = (val << 1) | (count & 0x01);
22 | }
23 | }
24 | *dest = val;
25 | ++dest;
26 | --size;
27 | }
28 | // NOTE: it would be a good idea to hash the resulting random data using SHA-256 or similar.
29 | return 1;
30 | }
31 |
32 | } // extern "C"
33 |
34 | void setup() {
35 | Serial.begin(115200);
36 | Serial.print("Testing ecc\n");
37 | uECC_set_rng(&RNG);
38 | }
39 |
40 | void loop() {
41 | const struct uECC_Curve_t * curve = uECC_secp160r1();
42 | uint8_t private1[21];
43 | uint8_t private2[21];
44 |
45 | uint8_t public1[40];
46 | uint8_t public2[40];
47 |
48 | uint8_t secret1[20];
49 | uint8_t secret2[20];
50 |
51 | unsigned long a = millis();
52 | uECC_make_key(public1, private1, curve);
53 | unsigned long b = millis();
54 |
55 | Serial.print("Made key 1 in "); Serial.println(b-a);
56 | a = millis();
57 | uECC_make_key(public2, private2, curve);
58 | b = millis();
59 | Serial.print("Made key 2 in "); Serial.println(b-a);
60 |
61 | a = millis();
62 | int r = uECC_shared_secret(public2, private1, secret1, curve);
63 | b = millis();
64 | Serial.print("Shared secret 1 in "); Serial.println(b-a);
65 | if (!r) {
66 | Serial.print("shared_secret() failed (1)\n");
67 | return;
68 | }
69 |
70 | a = millis();
71 | r = uECC_shared_secret(public1, private2, secret2, curve);
72 | b = millis();
73 | Serial.print("Shared secret 2 in "); Serial.println(b-a);
74 | if (!r) {
75 | Serial.print("shared_secret() failed (2)\n");
76 | return;
77 | }
78 |
79 | if (memcmp(secret1, secret2, 20) != 0) {
80 | Serial.print("Shared secrets are not identical!\n");
81 | } else {
82 | Serial.print("Shared secrets are identical\n");
83 | }
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/test/emk_rules.py:
--------------------------------------------------------------------------------
1 | c, link = emk.module("c", "link")
2 | link.depdirs += [
3 | "$:proj:$"
4 | ]
5 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/test/test_compress.c:
--------------------------------------------------------------------------------
1 | /* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2 |
3 | #include "uECC.h"
4 |
5 | #include
6 | #include
7 |
8 | #ifndef uECC_TEST_NUMBER_OF_ITERATIONS
9 | #define uECC_TEST_NUMBER_OF_ITERATIONS 256
10 | #endif
11 |
12 | void vli_print(char *str, uint8_t *vli, unsigned int size) {
13 | printf("%s ", str);
14 | for(unsigned i=0; i
6 | #include
7 |
8 | void vli_print(char *str, uint8_t *vli, unsigned int size) {
9 | printf("%s ", str);
10 | for(unsigned i=0; i
6 | #include
7 |
8 | void vli_print(uint8_t *vli, unsigned int size) {
9 | for(unsigned i=0; i
6 | #include
7 |
8 | int main() {
9 | int i, c;
10 | uint8_t private[32] = {0};
11 | uint8_t public[64] = {0};
12 | uint8_t hash[32] = {0};
13 | uint8_t sig[64] = {0};
14 |
15 | const struct uECC_Curve_t * curves[5];
16 | int num_curves = 0;
17 | #if uECC_SUPPORTS_secp160r1
18 | curves[num_curves++] = uECC_secp160r1();
19 | #endif
20 | #if uECC_SUPPORTS_secp192r1
21 | curves[num_curves++] = uECC_secp192r1();
22 | #endif
23 | #if uECC_SUPPORTS_secp224r1
24 | curves[num_curves++] = uECC_secp224r1();
25 | #endif
26 | #if uECC_SUPPORTS_secp256r1
27 | curves[num_curves++] = uECC_secp256r1();
28 | #endif
29 | #if uECC_SUPPORTS_secp256k1
30 | curves[num_curves++] = uECC_secp256k1();
31 | #endif
32 |
33 | printf("Testing 256 signatures\n");
34 | for (c = 0; c < num_curves; ++c) {
35 | for (i = 0; i < 256; ++i) {
36 | printf(".");
37 | fflush(stdout);
38 |
39 | if (!uECC_make_key(public, private, curves[c])) {
40 | printf("uECC_make_key() failed\n");
41 | return 1;
42 | }
43 | memcpy(hash, public, sizeof(hash));
44 |
45 | if (!uECC_sign(private, hash, sizeof(hash), sig, curves[c])) {
46 | printf("uECC_sign() failed\n");
47 | return 1;
48 | }
49 |
50 | if (!uECC_verify(public, hash, sizeof(hash), sig, curves[c])) {
51 | printf("uECC_verify() failed\n");
52 | return 1;
53 | }
54 | }
55 | printf("\n");
56 | }
57 |
58 | return 0;
59 | }
60 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/test/test_ecdsa_deterministic.c.example:
--------------------------------------------------------------------------------
1 | /* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2 |
3 | #include "uECC.h"
4 |
5 | #include
6 | #include
7 |
8 | #define SHA256_BLOCK_LENGTH 64
9 | #define SHA256_DIGEST_LENGTH 32
10 |
11 | typedef struct SHA256_CTX {
12 | uint32_t state[8];
13 | uint64_t bitcount;
14 | uint8_t buffer[SHA256_BLOCK_LENGTH];
15 | } SHA256_CTX;
16 |
17 | extern void SHA256_Init(SHA256_CTX *ctx);
18 | extern void SHA256_Update(SHA256_CTX *ctx, const uint8_t *message, size_t message_size);
19 | extern void SHA256_Final(uint8_t digest[SHA256_DIGEST_LENGTH], SHA256_CTX *ctx);
20 |
21 | typedef struct SHA256_HashContext {
22 | uECC_HashContext uECC;
23 | SHA256_CTX ctx;
24 | } SHA256_HashContext;
25 |
26 | static void init_SHA256(const uECC_HashContext *base) {
27 | SHA256_HashContext *context = (SHA256_HashContext *)base;
28 | SHA256_Init(&context->ctx);
29 | }
30 |
31 | static void update_SHA256(const uECC_HashContext *base,
32 | const uint8_t *message,
33 | unsigned message_size) {
34 | SHA256_HashContext *context = (SHA256_HashContext *)base;
35 | SHA256_Update(&context->ctx, message, message_size);
36 | }
37 |
38 | static void finish_SHA256(const uECC_HashContext *base, uint8_t *hash_result) {
39 | SHA256_HashContext *context = (SHA256_HashContext *)base;
40 | SHA256_Final(hash_result, &context->ctx);
41 | }
42 |
43 | int main() {
44 | int i, c;
45 | uint8_t private[32] = {0};
46 | uint8_t public[64] = {0};
47 | uint8_t hash[32] = {0};
48 | uint8_t sig[64] = {0};
49 |
50 | uint8_t tmp[2 * SHA256_DIGEST_LENGTH + SHA256_BLOCK_LENGTH];
51 | SHA256_HashContext ctx = {{
52 | &init_SHA256,
53 | &update_SHA256,
54 | &finish_SHA256,
55 | SHA256_BLOCK_LENGTH,
56 | SHA256_DIGEST_LENGTH,
57 | tmp
58 | }};
59 |
60 | const struct uECC_Curve_t * curves[5];
61 | curves[0] = uECC_secp160r1();
62 | curves[1] = uECC_secp192r1();
63 | curves[2] = uECC_secp224r1();
64 | curves[3] = uECC_secp256r1();
65 | curves[4] = uECC_secp256k1();
66 |
67 | printf("Testing 256 signatures\n");
68 | for (c = 0; c < 5; ++c) {
69 | for (i = 0; i < 256; ++i) {
70 | printf(".");
71 | fflush(stdout);
72 |
73 | if (!uECC_make_key(public, private, curves[c])) {
74 | printf("uECC_make_key() failed\n");
75 | return 1;
76 | }
77 | memcpy(hash, public, sizeof(hash));
78 |
79 | if (!uECC_sign_deterministic(private, hash, sizeof(hash), &ctx.uECC, sig, curves[c])) {
80 | printf("uECC_sign() failed\n");
81 | return 1;
82 | }
83 |
84 | if (!uECC_verify(public, hash, sizeof(hash), sig, curves[c])) {
85 | printf("uECC_verify() failed\n");
86 | return 1;
87 | }
88 | }
89 | printf("\n");
90 | }
91 |
92 | return 0;
93 | }
94 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/micro-ecc/types.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2 |
3 | #ifndef _UECC_TYPES_H_
4 | #define _UECC_TYPES_H_
5 |
6 | #ifndef uECC_PLATFORM
7 | #if __AVR__
8 | #define uECC_PLATFORM uECC_avr
9 | #elif defined(__thumb2__) || defined(_M_ARMT) /* I think MSVC only supports Thumb-2 targets */
10 | #define uECC_PLATFORM uECC_arm_thumb2
11 | #elif defined(__thumb__)
12 | #define uECC_PLATFORM uECC_arm_thumb
13 | #elif defined(__arm__) || defined(_M_ARM)
14 | #define uECC_PLATFORM uECC_arm
15 | #elif defined(__aarch64__)
16 | #define uECC_PLATFORM uECC_arm64
17 | #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__)
18 | #define uECC_PLATFORM uECC_x86
19 | #elif defined(__amd64__) || defined(_M_X64)
20 | #define uECC_PLATFORM uECC_x86_64
21 | #else
22 | #define uECC_PLATFORM uECC_arch_other
23 | #endif
24 | #endif
25 |
26 | #ifndef uECC_ARM_USE_UMAAL
27 | #if (uECC_PLATFORM == uECC_arm) && (__ARM_ARCH >= 6)
28 | #define uECC_ARM_USE_UMAAL 1
29 | #elif (uECC_PLATFORM == uECC_arm_thumb2) && (__ARM_ARCH >= 6) && !__ARM_ARCH_7M__
30 | #define uECC_ARM_USE_UMAAL 1
31 | #else
32 | #define uECC_ARM_USE_UMAAL 0
33 | #endif
34 | #endif
35 |
36 | #ifndef uECC_WORD_SIZE
37 | #if uECC_PLATFORM == uECC_avr
38 | #define uECC_WORD_SIZE 1
39 | #elif (uECC_PLATFORM == uECC_x86_64 || uECC_PLATFORM == uECC_arm64)
40 | #define uECC_WORD_SIZE 8
41 | #else
42 | #define uECC_WORD_SIZE 4
43 | #endif
44 | #endif
45 |
46 | #if (uECC_WORD_SIZE != 1) && (uECC_WORD_SIZE != 4) && (uECC_WORD_SIZE != 8)
47 | #error "Unsupported value for uECC_WORD_SIZE"
48 | #endif
49 |
50 | #if ((uECC_PLATFORM == uECC_avr) && (uECC_WORD_SIZE != 1))
51 | #pragma message ("uECC_WORD_SIZE must be 1 for AVR")
52 | #undef uECC_WORD_SIZE
53 | #define uECC_WORD_SIZE 1
54 | #endif
55 |
56 | #if ((uECC_PLATFORM == uECC_arm || uECC_PLATFORM == uECC_arm_thumb || \
57 | uECC_PLATFORM == uECC_arm_thumb2) && \
58 | (uECC_WORD_SIZE != 4))
59 | #pragma message ("uECC_WORD_SIZE must be 4 for ARM")
60 | #undef uECC_WORD_SIZE
61 | #define uECC_WORD_SIZE 4
62 | #endif
63 |
64 | #if defined(__SIZEOF_INT128__) || ((__clang_major__ * 100 + __clang_minor__) >= 302)
65 | #define SUPPORTS_INT128 1
66 | #else
67 | #define SUPPORTS_INT128 0
68 | #endif
69 |
70 | typedef int8_t wordcount_t;
71 | typedef int16_t bitcount_t;
72 | typedef int8_t cmpresult_t;
73 |
74 | #if (uECC_WORD_SIZE == 1)
75 |
76 | typedef uint8_t uECC_word_t;
77 | typedef uint16_t uECC_dword_t;
78 |
79 | #define HIGH_BIT_SET 0x80
80 | #define uECC_WORD_BITS 8
81 | #define uECC_WORD_BITS_SHIFT 3
82 | #define uECC_WORD_BITS_MASK 0x07
83 |
84 | #elif (uECC_WORD_SIZE == 4)
85 |
86 | typedef uint32_t uECC_word_t;
87 | typedef uint64_t uECC_dword_t;
88 |
89 | #define HIGH_BIT_SET 0x80000000
90 | #define uECC_WORD_BITS 32
91 | #define uECC_WORD_BITS_SHIFT 5
92 | #define uECC_WORD_BITS_MASK 0x01F
93 |
94 | #elif (uECC_WORD_SIZE == 8)
95 |
96 | typedef uint64_t uECC_word_t;
97 | #if SUPPORTS_INT128
98 | typedef unsigned __int128 uECC_dword_t;
99 | #endif
100 |
101 | #define HIGH_BIT_SET 0x8000000000000000ull
102 | #define uECC_WORD_BITS 64
103 | #define uECC_WORD_BITS_SHIFT 6
104 | #define uECC_WORD_BITS_MASK 0x03F
105 |
106 | #endif /* uECC_WORD_SIZE */
107 |
108 | #endif /* _UECC_TYPES_H_ */
109 |
--------------------------------------------------------------------------------
/software/BadgeGen/src/sha256.h:
--------------------------------------------------------------------------------
1 | #ifndef SHA256_H
2 | #define SHA256_H
3 |
4 |
5 | #define uchar unsigned char
6 |
7 | #define uint_64 long long unsigned int
8 |
9 | #define uint32 unsigned int
10 |
11 | struct ShaOBJ {
12 | uint32 state[8];
13 | uint_64 bit_len;
14 | uchar data[64];
15 | uint32 data_len;
16 | };
17 |
18 | void sha256_init(ShaOBJ *ctx);
19 | void sha256_update(ShaOBJ* ctx);
20 | void sha256_add(ShaOBJ* ctx, const unsigned char* msg, uint32 len);
21 | void sha256_digest(ShaOBJ* ctx, unsigned char hash[]);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/software/DarknetGateway/Makefile:
--------------------------------------------------------------------------------
1 | VERSION = 0.0.1
2 | CC = g++
3 | CFLAGS = -Wall -g --std=c++0x -DVERSION=\"$(VERSION)\" -DRPI=1
4 | #LDFLAGS = -lm `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
5 | LDFLAGS = -lm -lcurl -L src/tbb/build/linux_armv7_gcc_cc4.9.2_libc2.19_kernel4.9.28_release -l tbb
6 |
7 | BUILDDIR = build
8 | SOURCEDIR = src
9 | HEADERDIR = src
10 |
11 | SOURCES = $(wildcard $(SOURCEDIR)/*.cpp)
12 | OBJECTS = $(patsubst $(SOURCEDIR)/%.cpp, $(BUILDDIR)/%.o, $(SOURCES))
13 |
14 | NAME = darknet-gateway
15 | BINARY = $(NAME).bin
16 |
17 | ECHO = echo
18 | RM = rm -rf
19 | MKDIR = mkdir
20 | INSTALL = install
21 |
22 | .PHONY: all clean setup
23 |
24 | all: $(BINARY)
25 |
26 |
27 | $(BINARY): tbb $(BUILDDIR)/$(OBJECTS)
28 | $(CC) $(CFLAGS) $(LDFLAGS) -I$(HEADERDIR) -I$(SOURCEDIR) $(OBJECTS) /usr/local/lib/libbcm2835.a -o $(BINARY)
29 |
30 |
31 | $(BUILDDIR)/%.o: $(SOURCEDIR)/%.cpp
32 | $(CC) $(CFLAGS) $(LDFLAGS) -I$(HEADERDIR) -I$(SOURCEDIR) -c $< -o $@
33 |
34 | setup:
35 | $(MKDIR) -p $(BUILDDIR)
36 |
37 | clean:
38 | $(RM) $(BINARY) $(OBJECTS)
39 | make -C src/tbb clean
40 |
41 | distclean: clean
42 |
43 | tbb:
44 | make -C src/tbb
45 |
46 | run:
47 | export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):src/tbb/build/linux_armv7_gcc_cc4.9.2_libc2.19_kernel4.9.28_release;sudo ./$(BINARY)
48 |
49 | help:
50 | @$(ECHO) "Targets:"
51 | @$(ECHO) "all - buildcompile what is necessary"
52 | @$(ECHO) "clean - cleanup old .o and .bin"
53 | @$(ECHO) "install - not yet fully supported"
54 |
--------------------------------------------------------------------------------
/software/DarknetGateway/README.md:
--------------------------------------------------------------------------------
1 | To compile:
2 |
3 | #Prerequisites:
4 |
5 | sudo apt install libcurl4-openssl-dev
6 | wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.52.tar.gz
7 | tar zxvf bcm2835-1.52.tar.gz
8 | cd bcm2835-1.52
9 | make
10 | sudo make install
11 |
12 | git clone --recursive https://github.com/thedarknet/defcon25-badge.git
13 | cd defcon25-badge/software/DarknetGateway
14 | make
15 | sudo ./darknet-gateway.bin
16 |
--------------------------------------------------------------------------------
/software/DarknetGateway/src/Hardware.cpp:
--------------------------------------------------------------------------------
1 | // ArduinoCompat/HardwareSPI.cpp
2 | //
3 | // Interface between Arduino-like SPI interface and STM32F4 Discovery and similar
4 | // using STM32F4xx_DSP_StdPeriph_Lib_V1.3.0
5 |
6 |
7 | #include "Hardware.h"
8 |
9 | ErrorType SPI::masterListen() {
10 | return onMasterListen();
11 | }
12 |
13 | ErrorType SPI::select() {
14 | return onSelect();
15 | }
16 |
17 | ErrorType SPI::unselect() {
18 | return onUnselect();
19 | }
20 |
21 | uint8_t SPI::transfer(uint8_t data) {
22 | return onTransfer(data);
23 | }
24 |
25 | bool SPI::init(SPIFrequency divider, BitOrder bitOrder, SPIMode dataMode) {
26 | return onInit(divider, bitOrder, dataMode);
27 | }
28 |
29 | bool SPI::shutdown() {
30 | return onShutdown();
31 | }
32 |
33 | SPI::~SPI() {
34 |
35 | }
36 |
37 |
38 | Hardware::Hardware(SPI *one, SPI *two) : SPI1(one), SPI2(two) {
39 | }
40 |
41 | ErrorType Hardware::enableIRQ() {
42 | return onEnableIRQ();
43 | }
44 |
45 | ErrorType Hardware::disableIRQ() {
46 | return onDisableIRQ();
47 | }
48 |
49 | ErrorType Hardware::attachInterrupt(int uniqueIRQ, void (*handler)(void), int mode) {
50 | return onAttachInterrupt(uniqueIRQ, handler, mode);
51 | }
52 |
53 | void Hardware::pinMode(uint8_t pin, PINMODE mode) {
54 | onPinMode(pin,mode);
55 | }
56 |
57 | void Hardware::digitalWrite(uint8_t pin, Hardware::PINVAL val) {
58 | onDigitalWrite(pin,val);
59 | }
60 |
61 | uint8_t Hardware::digitalRead(uint8_t pin) {
62 | return onDigitalRead(pin);
63 | }
64 |
65 | SPI *Hardware::getSPI1() {
66 | return SPI1;
67 | }
68 |
69 | SPI *Hardware::getSPI2() {
70 | return SPI2;
71 | }
72 |
73 | Hardware::~Hardware() {
74 |
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/software/DarknetGateway/src/Hardware.h:
--------------------------------------------------------------------------------
1 | //hardware abstraction class
2 | #ifndef _Hardware_h
3 | #define _Hardware_h
4 |
5 | #include
6 | #include
7 |
8 | typedef enum SPIFrequency {
9 | SPI_21_0MHZ = 0, /**< 21 MHz */
10 | SPI_10_5MHZ = 1, /**< 10.5 MHz */
11 | SPI_5_25MHZ = 2, /**< 5.25 MHz */
12 | SPI_2_625MHZ = 3, /**< 2.625 MHz */
13 | SPI_1_3125MHZ = 4, /**< 1.3125 MHz */
14 | SPI_656_25KHZ = 5, /**< 656.25 KHz */
15 | SPI_328_125KHZ = 6, /**< 328.125 KHz */
16 | } SPIFrequency;
17 |
18 | typedef enum BITORDER {
19 | MSB
20 | , LSB
21 | } BitOrder;
22 |
23 | typedef enum SPI_MODE {
24 | SPI_MODE0=0x00
25 | ,SPI_MODE1=0x04
26 | ,SPI_MODE2=0x08
27 | ,SPI_MODE3=0x0C
28 | } SPIMode;
29 |
30 | class SPI {
31 | public:
32 | ErrorType masterListen();
33 | ErrorType select();
34 | ErrorType unselect();
35 | uint8_t transfer(uint8_t data);
36 | bool init(SPIFrequency divider, BitOrder bitOrder, SPIMode dataMode);
37 | bool shutdown();
38 | protected:
39 | virtual ~SPI()=0;
40 | virtual ErrorType onMasterListen()=0;
41 | virtual ErrorType onSelect()=0;
42 | virtual ErrorType onUnselect()=0;
43 | virtual uint8_t onTransfer(uint8_t data)=0;
44 | virtual bool onInit(SPIFrequency divider, BitOrder bitOrder, SPIMode dataMode)=0;
45 | virtual bool onShutdown()=0;
46 | };
47 |
48 |
49 | class Hardware {
50 | public:
51 | enum PINMODE {
52 | OUTPUT=0
53 | ,INPUT=1
54 | };
55 |
56 | enum PINVAL {
57 | PIN_LOW=0
58 | ,PIN_HIGH=1
59 | };
60 | public:
61 | static Hardware &get();
62 | public:
63 | ErrorType enableIRQ();
64 | ErrorType disableIRQ();
65 | ErrorType attachInterrupt(int uniqueIRQ, void (*handler)(void), int mode);
66 | SPI *getSPI1();
67 | SPI *getSPI2();
68 | void pinMode(uint8_t pin, PINMODE mode);
69 | void digitalWrite(uint8_t pin, PINVAL val);
70 | uint8_t digitalRead(uint8_t pin);
71 | ///returns milliseconds since application start
72 | uint32_t millis();
73 | protected:
74 | Hardware(SPI *one, SPI *two);
75 | virtual ~Hardware()=0;
76 | virtual ErrorType onEnableIRQ()=0;
77 | virtual ErrorType onDisableIRQ()=0;
78 | virtual ErrorType onAttachInterrupt(int uniqueIRQ, void (*handler)(void), int mode)=0;
79 | virtual void onPinMode(uint8_t pin, PINMODE mode)=0;
80 | virtual void onDigitalWrite(uint8_t pin, PINVAL val)=0;
81 | virtual uint8_t onDigitalRead(uint8_t pin)=0;
82 | private:
83 | SPI *SPI1;
84 | SPI *SPI2;
85 | };
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/software/DarknetGateway/src/RPIHardware.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "RPIHardware.h"
3 | #include
4 | #include
5 | #include
6 |
7 | RPISPI::RPISPI(int channel, int cs) : Channel(channel), CS(cs) {
8 | }
9 |
10 | RPISPI::~RPISPI() {
11 | shutdown();
12 | }
13 |
14 | ErrorType RPISPI::onMasterListen() {
15 | return unselect();
16 | }
17 |
18 | ErrorType RPISPI::onSelect() {
19 | //todo add this to a interface for GPIO
20 | bcm2835_gpio_write(CS,0);
21 | return ErrorType();
22 | }
23 |
24 | ErrorType RPISPI::onUnselect() {
25 | //todo add this to a interface for GPIO
26 | bcm2835_gpio_write(CS,1);
27 | return ErrorType();
28 | }
29 |
30 | uint8_t RPISPI::onTransfer(uint8_t data) {
31 | return bcm2835_spi_transfer(data);
32 | }
33 |
34 | bool RPISPI::onInit(SPIFrequency divider, BitOrder bitOrder, SPIMode dataMode) {
35 | if(bcm2835_init()) {
36 | bcm2835_gpio_fsel(CS,BCM2835_GPIO_FSEL_OUTP);
37 | // We control CS line manually don't assert CEx line!
38 | bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);
39 | //todo map from generic to RPI specific
40 | bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256);
41 | bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
42 | bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
43 | bcm2835_spi_begin();
44 | return true;
45 | }
46 | return false;
47 | }
48 |
49 | bool RPISPI::onShutdown() {
50 | bcm2835_spi_end();
51 | return true;
52 | }
53 |
54 |
55 | RPIHardware::RPIHardware(SPI *one, SPI* two) : Hardware(one,two) {
56 | }
57 |
58 | RPIHardware::~RPIHardware() {
59 |
60 | }
61 |
62 | ErrorType RPIHardware::onEnableIRQ() {
63 | return ErrorType();
64 | }
65 |
66 | ErrorType RPIHardware::onDisableIRQ() {
67 | return ErrorType();
68 | }
69 |
70 |
71 | ErrorType RPIHardware::onAttachInterrupt(int uniqueIRQ, void (*handler)(void), int mode) {
72 | UniqueIRQ = uniqueIRQ;
73 | IRQHandler = handler;
74 | return ErrorType();
75 | }
76 |
77 | void RPIHardware::checkIRQ() {
78 | if (bcm2835_gpio_eds(UniqueIRQ)) {
79 | // Now clear the eds flag by setting it to 1
80 | bcm2835_gpio_set_eds(UniqueIRQ);
81 | printf("Rising event detect for pin GPIO%d\n", UniqueIRQ);
82 | (*IRQHandler)();
83 | }
84 | }
85 |
86 | void RPIHardware::onPinMode(uint8_t pin, Hardware::PINMODE mode) {
87 | if(mode==Hardware::OUTPUT) {
88 | bcm2835_gpio_fsel(pin,BCM2835_GPIO_FSEL_OUTP);
89 | } else {
90 | bcm2835_gpio_fsel(pin,BCM2835_GPIO_FSEL_INPT);
91 | }
92 | }
93 |
94 | void RPIHardware::onDigitalWrite(uint8_t pin, Hardware::PINVAL val) {
95 | bcm2835_gpio_write(pin,val);
96 | }
97 |
98 | uint8_t RPIHardware::onDigitalRead(uint8_t pin) {
99 | return bcm2835_gpio_lev(pin);
100 | }
101 |
102 | static auto ApplicationStartTime = std::chrono::system_clock::now();
103 |
104 | //returns milliseconds since application start
105 | uint32_t Hardware::millis() {
106 | auto diff = std::chrono::system_clock::now()-ApplicationStartTime;
107 | return std::chrono::duration_cast(diff).count();
108 | }
109 |
110 |
--------------------------------------------------------------------------------
/software/DarknetGateway/src/RPIHardware.h:
--------------------------------------------------------------------------------
1 | //hardware abstraction class
2 | #ifndef _RPIHardware_h
3 | #define _RPIHardware_h
4 |
5 | #include
6 | #include "Hardware.h"
7 |
8 | class RPISPI : public SPI {
9 | public:
10 | RPISPI(int channel, int cs);
11 | virtual ~RPISPI();
12 | virtual ErrorType onMasterListen();
13 | virtual ErrorType onSelect();
14 | virtual ErrorType onUnselect();
15 | virtual uint8_t onTransfer(uint8_t data);
16 | virtual bool onInit(SPIFrequency divider, BitOrder bitOrder, SPIMode dataMode);
17 | virtual bool onShutdown();
18 | private:
19 | int Channel;
20 | int CS;
21 | };
22 |
23 | class RPIHardware : public Hardware {
24 | public:
25 | RPIHardware(SPI *spi1, SPI *spi2);
26 | void checkIRQ();
27 | virtual ~RPIHardware();
28 | protected:
29 | virtual ErrorType onEnableIRQ();
30 | virtual ErrorType onDisableIRQ();
31 | virtual ErrorType onAttachInterrupt(int uniqueIRQ, void (*handler)(void), int mode);
32 | virtual void onPinMode(uint8_t pin, PINMODE mode);
33 | virtual void onDigitalWrite(uint8_t pin, PINVAL val);
34 | virtual uint8_t onDigitalRead(uint8_t pin);
35 | protected:
36 | uint8_t UniqueIRQ;
37 | void (*IRQHandler)();
38 |
39 | };
40 |
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/software/DarknetGateway/src/error_type.cpp:
--------------------------------------------------------------------------------
1 | #include "error_type.h"
2 |
3 | ErrorType::ErrorType() : ErrorNumber(ErrorType::ErrorNum::NO_ERROR) {
4 | }
5 |
6 | ErrorType::ErrorType(ErrorNum en) : ErrorNumber(en) {
7 | }
8 |
9 | bool ErrorType::ok() {
10 | return ErrorNumber==ErrorNum::NO_ERROR;
11 | }
12 |
13 |
14 | const char *ErrorType::getMessage() {
15 | return "ErrorType: TODO";
16 | }
17 |
18 | ErrorType::ErrorType(const ErrorType &r) {
19 | (*this)=r;
20 | }
21 |
22 | ErrorType &ErrorType::operator=(const ErrorType &r) {
23 | ErrorNumber = r.ErrorNumber;
24 | return (*this);
25 | }
26 |
--------------------------------------------------------------------------------
/software/DarknetGateway/src/error_type.h:
--------------------------------------------------------------------------------
1 | #ifndef ERROR_TYPE_H
2 | #define ERROR_TYPE_H
3 |
4 | #include
5 |
6 | class ErrorType {
7 | public:
8 | enum ErrorNum {
9 | NO_ERROR = 0,
10 | SPI_INIT_ERROR
11 | };
12 | public:
13 | ErrorType();
14 | ErrorType(ErrorNum en);
15 | ErrorType(const ErrorType &r);
16 | bool ok();
17 | ErrorType &operator=(const ErrorType &r);
18 | uint8_t getError() {return ErrorNumber;}
19 | const char *getMessage();
20 | private:
21 | ErrorNum ErrorNumber;
22 | };
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/software/cube-src/firmware/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | firmware
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
25 | fr.ac6.mcu.ide.core.MCUProjectNature
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/software/cube-src/firmware/Drivers/CMSIS/Device/ST/STM32F3xx/Include/stm32f302xc.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/cube-src/firmware/Drivers/CMSIS/Device/ST/STM32F3xx/Include/stm32f302xc.h
--------------------------------------------------------------------------------
/software/cube-src/firmware/Drivers/CMSIS/Device/ST/STM32F3xx/Include/stm32f3xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/cube-src/firmware/Drivers/CMSIS/Device/ST/STM32F3xx/Include/stm32f3xx.h
--------------------------------------------------------------------------------
/software/cube-src/firmware/Inc/stm32f3xx_it.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f3xx_it.h
4 | * @brief This file contains the headers of the interrupt handlers.
5 | ******************************************************************************
6 | *
7 | * COPYRIGHT(c) 2017 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 |
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __STM32F3xx_IT_H
36 | #define __STM32F3xx_IT_H
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | /* Exported types ------------------------------------------------------------*/
44 | /* Exported constants --------------------------------------------------------*/
45 | /* Exported macro ------------------------------------------------------------*/
46 | /* Exported functions ------------------------------------------------------- */
47 |
48 | void NMI_Handler(void);
49 | void HardFault_Handler(void);
50 | void MemManage_Handler(void);
51 | void BusFault_Handler(void);
52 | void UsageFault_Handler(void);
53 | void DebugMon_Handler(void);
54 | void SysTick_Handler(void);
55 | void EXTI2_TSC_IRQHandler(void);
56 | void EXTI4_IRQHandler(void);
57 | void DMA1_Channel5_IRQHandler(void);
58 | void USB_LP_CAN_RX0_IRQHandler(void);
59 | void TIM3_IRQHandler(void);
60 | void DMA2_Channel1_IRQHandler(void);
61 | void DMA2_Channel2_IRQHandler(void);
62 |
63 | #ifdef __cplusplus
64 | }
65 | #endif
66 |
67 | #endif /* __STM32F3xx_IT_H */
68 |
69 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
70 |
--------------------------------------------------------------------------------
/software/cube-src/firmware/Inc/usb_device.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : USB_DEVICE
4 | * @version : v2.0_Cube
5 | * @brief : Header for usb_device file.
6 | ******************************************************************************
7 | *
8 | * Copyright (c) 2017 STMicroelectronics International N.V.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted, provided that the following conditions are met:
13 | *
14 | * 1. Redistribution of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. Neither the name of STMicroelectronics nor the names of other
20 | * contributors to this software may be used to endorse or promote products
21 | * derived from this software without specific written permission.
22 | * 4. This software, including modifications and/or derivative works of this
23 | * software, must execute solely and exclusively on microcontroller or
24 | * microprocessor devices manufactured by or for STMicroelectronics.
25 | * 5. Redistribution and use of this software other than as permitted under
26 | * this license is void and will automatically terminate your rights under
27 | * this license.
28 | *
29 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
30 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
33 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
34 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
37 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 | *
42 | ******************************************************************************
43 | */
44 | /* Define to prevent recursive inclusion -------------------------------------*/
45 | #ifndef __usb_device_H
46 | #define __usb_device_H
47 | #ifdef __cplusplus
48 | extern "C" {
49 | #endif
50 |
51 | /* Includes ------------------------------------------------------------------*/
52 | #include "stm32f3xx.h"
53 | #include "stm32f3xx_hal.h"
54 | #include "usbd_def.h"
55 |
56 | extern USBD_HandleTypeDef hUsbDeviceFS;
57 |
58 | /* USB_Device init function */
59 | void MX_USB_DEVICE_Init(void);
60 |
61 | #ifdef __cplusplus
62 | }
63 | #endif
64 | #endif /*__usb_device_H */
65 |
66 | /**
67 | * @}
68 | */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
75 |
--------------------------------------------------------------------------------
/software/cube-src/firmware/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_req.h
4 | * @author MCD Application Team
5 | * @version V2.4.2
6 | * @date 11-December-2015
7 | * @brief Header file for the usbd_req.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2015 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __USB_REQUEST_H
30 | #define __USB_REQUEST_H
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | /* Includes ------------------------------------------------------------------*/
37 | #include "usbd_def.h"
38 |
39 |
40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
41 | * @{
42 | */
43 |
44 | /** @defgroup USBD_REQ
45 | * @brief header file for the usbd_req.c file
46 | * @{
47 | */
48 |
49 | /** @defgroup USBD_REQ_Exported_Defines
50 | * @{
51 | */
52 | /**
53 | * @}
54 | */
55 |
56 |
57 | /** @defgroup USBD_REQ_Exported_Types
58 | * @{
59 | */
60 | /**
61 | * @}
62 | */
63 |
64 |
65 |
66 | /** @defgroup USBD_REQ_Exported_Macros
67 | * @{
68 | */
69 | /**
70 | * @}
71 | */
72 |
73 | /** @defgroup USBD_REQ_Exported_Variables
74 | * @{
75 | */
76 | /**
77 | * @}
78 | */
79 |
80 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype
81 | * @{
82 | */
83 |
84 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
85 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
86 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
87 |
88 |
89 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
90 |
91 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata);
92 |
93 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len);
94 | /**
95 | * @}
96 | */
97 |
98 | #ifdef __cplusplus
99 | }
100 | #endif
101 |
102 | #endif /* __USB_REQUEST_H */
103 |
104 | /**
105 | * @}
106 | */
107 |
108 | /**
109 | * @}
110 | */
111 |
112 |
113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
114 |
--------------------------------------------------------------------------------
/software/cube-src/firmware/firmware.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | firmware
5 | STM32F302RBTx
6 | SWD
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/software/firmware-test/.gitignore:
--------------------------------------------------------------------------------
1 | /Debug/
2 |
--------------------------------------------------------------------------------
/software/firmware-test/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | firmware-test
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/software/firmware-test/.settings/language.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/software/firmware-test/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_req.h
4 | * @author MCD Application Team
5 | * @version V2.4.1
6 | * @date 19-June-2015
7 | * @brief Header file for the usbd_req.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2015 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __USB_REQUEST_H
30 | #define __USB_REQUEST_H
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | /* Includes ------------------------------------------------------------------*/
37 | #include "usbd_def.h"
38 |
39 |
40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
41 | * @{
42 | */
43 |
44 | /** @defgroup USBD_REQ
45 | * @brief header file for the usbd_req.c file
46 | * @{
47 | */
48 |
49 | /** @defgroup USBD_REQ_Exported_Defines
50 | * @{
51 | */
52 | /**
53 | * @}
54 | */
55 |
56 |
57 | /** @defgroup USBD_REQ_Exported_Types
58 | * @{
59 | */
60 | /**
61 | * @}
62 | */
63 |
64 |
65 |
66 | /** @defgroup USBD_REQ_Exported_Macros
67 | * @{
68 | */
69 | /**
70 | * @}
71 | */
72 |
73 | /** @defgroup USBD_REQ_Exported_Variables
74 | * @{
75 | */
76 | /**
77 | * @}
78 | */
79 |
80 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype
81 | * @{
82 | */
83 |
84 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
85 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
86 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
87 |
88 |
89 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
90 |
91 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata);
92 |
93 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len);
94 | /**
95 | * @}
96 | */
97 |
98 | #ifdef __cplusplus
99 | }
100 | #endif
101 |
102 | #endif /* __USB_REQUEST_H */
103 |
104 | /**
105 | * @}
106 | */
107 |
108 | /**
109 | * @}
110 | */
111 |
112 |
113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
114 |
--------------------------------------------------------------------------------
/software/firmware-test/include/dma.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : dma.h
4 | * Description : This file contains all the function prototypes for
5 | * the dma.c file
6 | ******************************************************************************
7 | *
8 | * COPYRIGHT(c) 2017 STMicroelectronics
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *
32 | ******************************************************************************
33 | */
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __dma_H
36 | #define __dma_H
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | #include "stm32f3xx_hal.h"
44 |
45 | /* DMA memory to memory transfer handles -------------------------------------*/
46 |
47 | /* USER CODE BEGIN Includes */
48 |
49 | /* USER CODE END Includes */
50 |
51 | /* USER CODE BEGIN Private defines */
52 |
53 | /* USER CODE END Private defines */
54 |
55 | void MX_DMA_Init(void);
56 |
57 | /* USER CODE BEGIN Prototypes */
58 |
59 | /* USER CODE END Prototypes */
60 |
61 | #ifdef __cplusplus
62 | }
63 | #endif
64 |
65 | #endif /* __dma_H */
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
72 |
--------------------------------------------------------------------------------
/software/firmware-test/include/gpio.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : gpio.h
4 | * Description : This file contains all the functions prototypes for
5 | * the gpio
6 | ******************************************************************************
7 | *
8 | * COPYRIGHT(c) 2017 STMicroelectronics
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *
32 | ******************************************************************************
33 | */
34 |
35 | /* Define to prevent recursive inclusion -------------------------------------*/
36 | #ifndef __gpio_H
37 | #define __gpio_H
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | #include "stm32f3xx_hal.h"
44 |
45 | /* USER CODE BEGIN Includes */
46 |
47 | /* USER CODE END Includes */
48 |
49 | /* USER CODE BEGIN Private defines */
50 |
51 | /* USER CODE END Private defines */
52 |
53 | void MX_GPIO_Init(void);
54 |
55 | /* USER CODE BEGIN Prototypes */
56 |
57 | /* USER CODE END Prototypes */
58 |
59 | #ifdef __cplusplus
60 | }
61 | #endif
62 | #endif /*__ pinoutConfig_H */
63 |
64 | /**
65 | * @}
66 | */
67 |
68 | /**
69 | * @}
70 | */
71 |
72 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
73 |
--------------------------------------------------------------------------------
/software/firmware-test/include/spi.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : SPI.h
4 | * Description : This file provides code for the configuration
5 | * of the SPI instances.
6 | ******************************************************************************
7 | *
8 | * COPYRIGHT(c) 2017 STMicroelectronics
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *
32 | ******************************************************************************
33 | */
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __spi_H
36 | #define __spi_H
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | /* Includes ------------------------------------------------------------------*/
42 | #include "stm32f3xx_hal.h"
43 |
44 | /* USER CODE BEGIN Includes */
45 |
46 | /* USER CODE END Includes */
47 |
48 | extern SPI_HandleTypeDef hspi1;
49 | extern SPI_HandleTypeDef hspi2;
50 |
51 | /* USER CODE BEGIN Private defines */
52 |
53 | /* USER CODE END Private defines */
54 |
55 | void MX_SPI1_Init(void);
56 | void MX_SPI2_Init(void);
57 |
58 | /* USER CODE BEGIN Prototypes */
59 |
60 | /* USER CODE END Prototypes */
61 |
62 | #ifdef __cplusplus
63 | }
64 | #endif
65 | #endif /*__ spi_H */
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
76 |
--------------------------------------------------------------------------------
/software/firmware-test/include/stm32f3xx_it.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f3xx_it.h
4 | * @brief This file contains the headers of the interrupt handlers.
5 | ******************************************************************************
6 | *
7 | * COPYRIGHT(c) 2017 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 |
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __STM32F3xx_IT_H
36 | #define __STM32F3xx_IT_H
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | /* Exported types ------------------------------------------------------------*/
44 | /* Exported constants --------------------------------------------------------*/
45 | /* Exported macro ------------------------------------------------------------*/
46 | /* Exported functions ------------------------------------------------------- */
47 |
48 | void NMI_Handler(void);
49 | void HardFault_Handler(void);
50 | void MemManage_Handler(void);
51 | void BusFault_Handler(void);
52 | void UsageFault_Handler(void);
53 | void DebugMon_Handler(void);
54 | void SysTick_Handler(void);
55 | void DMA1_Channel2_IRQHandler(void);
56 | void DMA1_Channel3_IRQHandler(void);
57 | void DMA1_Channel5_IRQHandler(void);
58 | void USB_LP_CAN_RX0_IRQHandler(void);
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 |
64 | #endif /* __STM32F3xx_IT_H */
65 |
66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
67 |
--------------------------------------------------------------------------------
/software/firmware-test/include/tim.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : TIM.h
4 | * Description : This file provides code for the configuration
5 | * of the TIM instances.
6 | ******************************************************************************
7 | *
8 | * COPYRIGHT(c) 2017 STMicroelectronics
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *
32 | ******************************************************************************
33 | */
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __tim_H
36 | #define __tim_H
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | /* Includes ------------------------------------------------------------------*/
42 | #include "stm32f3xx_hal.h"
43 |
44 | /* USER CODE BEGIN Includes */
45 |
46 | /* USER CODE END Includes */
47 |
48 | extern TIM_HandleTypeDef htim16;
49 | extern TIM_HandleTypeDef htim17;
50 |
51 | /* USER CODE BEGIN Private defines */
52 |
53 | /* USER CODE END Private defines */
54 |
55 | void MX_TIM16_Init(void);
56 | void MX_TIM17_Init(void);
57 |
58 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
59 |
60 |
61 | /* USER CODE BEGIN Prototypes */
62 |
63 | /* USER CODE END Prototypes */
64 |
65 | #ifdef __cplusplus
66 | }
67 | #endif
68 | #endif /*__ tim_H */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /**
75 | * @}
76 | */
77 |
78 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
79 |
--------------------------------------------------------------------------------
/software/firmware-test/include/tsc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : TSC.h
4 | * Description : This file provides code for the configuration
5 | * of the TSC instances.
6 | ******************************************************************************
7 | *
8 | * COPYRIGHT(c) 2017 STMicroelectronics
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *
32 | ******************************************************************************
33 | */
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __tsc_H
36 | #define __tsc_H
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | /* Includes ------------------------------------------------------------------*/
42 | #include "stm32f3xx_hal.h"
43 |
44 | /* USER CODE BEGIN Includes */
45 |
46 | /* USER CODE END Includes */
47 |
48 | extern TSC_HandleTypeDef htsc;
49 |
50 | /* USER CODE BEGIN Private defines */
51 |
52 | /* USER CODE END Private defines */
53 |
54 | void MX_TSC_Init(void);
55 |
56 | /* USER CODE BEGIN Prototypes */
57 |
58 | /* USER CODE END Prototypes */
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 | #endif /*__ tsc_H */
64 |
65 | /**
66 | * @}
67 | */
68 |
69 | /**
70 | * @}
71 | */
72 |
73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
74 |
--------------------------------------------------------------------------------
/software/firmware-test/include/usb_device.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : USB_DEVICE
4 | * @version : v1.0_Cube
5 | * @brief : Header for usb_device file.
6 | ******************************************************************************
7 | * COPYRIGHT(c) 2017 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 | /* Define to prevent recursive inclusion -------------------------------------*/
34 | #ifndef __usb_device_H
35 | #define __usb_device_H
36 | #ifdef __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | /* Includes ------------------------------------------------------------------*/
41 | #include "stm32f3xx.h"
42 | #include "stm32f3xx_hal.h"
43 | #include "usbd_def.h"
44 |
45 | extern USBD_HandleTypeDef hUsbDeviceFS;
46 |
47 | /* USB_Device init function */
48 | void MX_USB_DEVICE_Init(void);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 | #endif /*__usb_device_H */
54 |
55 | /**
56 | * @}
57 | */
58 |
59 | /**
60 | * @}
61 | */
62 |
63 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
64 |
--------------------------------------------------------------------------------
/software/firmware-test/include/usbd_desc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : usbd_desc.h
4 | * @version : v1.0_Cube
5 | * @brief : Header for usbd_desc file.
6 | ******************************************************************************
7 | * COPYRIGHT(c) 2017 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 |
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __USBD_DESC__H__
36 | #define __USBD_DESC__H__
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 | /* Includes ------------------------------------------------------------------*/
42 | #include "usbd_def.h"
43 |
44 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
45 | * @{
46 | */
47 |
48 | /** @defgroup USB_DESC
49 | * @brief general defines for the usb device library file
50 | * @{
51 | */
52 |
53 | /** @defgroup USB_DESC_Exported_Defines
54 | * @{
55 | */
56 |
57 | /**
58 | * @}
59 | */
60 |
61 | /** @defgroup USBD_DESC_Exported_TypesDefinitions
62 | * @{
63 | */
64 | /**
65 | * @}
66 | */
67 |
68 | /** @defgroup USBD_DESC_Exported_Macros
69 | * @{
70 | */
71 | /**
72 | * @}
73 | */
74 |
75 | /** @defgroup USBD_DESC_Exported_Variables
76 | * @{
77 | */
78 | extern USBD_DescriptorsTypeDef FS_Desc;
79 | /**
80 | * @}
81 | */
82 |
83 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype
84 | * @{
85 | */
86 |
87 | /**
88 | * @}
89 | */
90 | #ifdef __cplusplus
91 | }
92 | #endif
93 |
94 | #endif /* __USBD_DESC_H */
95 |
96 | /**
97 | * @}
98 | */
99 |
100 | /**
101 | * @}
102 | */
103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
104 |
--------------------------------------------------------------------------------
/software/firmware-test/ldscripts/libs.ld:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Placeholder to list other libraries required by the application.
4 |
5 | GROUP(
6 | )
7 |
8 | */
9 |
--------------------------------------------------------------------------------
/software/firmware-test/ldscripts/mem.ld:
--------------------------------------------------------------------------------
1 | /*
2 | * Memory Spaces Definitions.
3 | *
4 | * Need modifying for a specific board.
5 | * FLASH.ORIGIN: starting address of flash
6 | * FLASH.LENGTH: length of flash
7 | * RAM.ORIGIN: starting address of RAM bank 0
8 | * RAM.LENGTH: length of RAM bank 0
9 | *
10 | * The values below can be addressed in further linker scripts
11 | * using functions like 'ORIGIN(RAM)' or 'LENGTH(RAM)'.
12 | */
13 |
14 | MEMORY
15 | {
16 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K
17 | CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 8K
18 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
19 | FLASHB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
20 | EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0
21 | EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
22 | EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0
23 | EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0
24 | MEMORY_ARRAY (xrw) : ORIGIN = 0x20002000, LENGTH = 0
25 | }
26 |
27 | /*
28 | * For external ram use something like:
29 |
30 | RAM (xrw) : ORIGIN = 0x64000000, LENGTH = 2048K
31 |
32 | */
33 |
--------------------------------------------------------------------------------
/software/firmware-test/src/badge/dcdarknet_app.cpp:
--------------------------------------------------------------------------------
1 | #include "dcdarknet_app.h"
2 | #include "display_device.h"
3 |
4 | DCDarkNetApp::DCDarkNetApp() {
5 |
6 | }
7 |
8 | DisplayST7735 Display(128,160, DisplayST7735::PORTAIT);
9 |
10 | ErrorType DCDarkNetApp::init() {
11 | ErrorType et;
12 | et = Display.init();
13 | return et;
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/software/firmware-test/src/badge/dcdarknet_app.h:
--------------------------------------------------------------------------------
1 | #ifndef _DCDARKNET_APP_H
2 | #define _DCDARKNET_APP_H
3 |
4 | #include "error_type.h"
5 |
6 | class DCDarkNetApp {
7 | public:
8 | DCDarkNetApp();
9 | ErrorType init();
10 | private:
11 |
12 | };
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/software/firmware-test/src/badge/error_type.cpp:
--------------------------------------------------------------------------------
1 | #include "error_type.h"
2 |
3 | ErrorType::ErrorType() : ErrorNumber(ErrorNum::NO_ERROR) {
4 | }
5 |
6 | ErrorType::ErrorType(ErrorNum en) : ErrorNumber(en) {
7 | }
8 |
9 | bool ErrorType::ok() {
10 | return ErrorNumber==ErrorNum::NO_ERROR;
11 | }
12 |
--------------------------------------------------------------------------------
/software/firmware-test/src/badge/error_type.h:
--------------------------------------------------------------------------------
1 | #ifndef ERROR_TYPE_H
2 | #define ERROR_TYPE_H
3 |
4 | #include "stdint.h"
5 |
6 | class ErrorType {
7 | public:
8 | enum ErrorNum {
9 | NO_ERROR = 0,
10 | SPI_INIT_ERROR
11 | };
12 | public:
13 | ErrorType();
14 | ErrorType(ErrorNum en);
15 | bool ok();
16 | private:
17 | ErrorNum ErrorNumber;
18 | };
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/software/firmware-test/src/badge/logger.cpp:
--------------------------------------------------------------------------------
1 | #include "logger.h"
2 | #include
3 | #include
4 |
5 | using darknet::LogManager;
6 | using darknet::Logger;
7 | using darknet::LOG_LEVEL;
8 |
9 | LogManager *LogManager::mSelf = 0;
10 |
11 | LogManager &LogManager::get() {
12 | if(0==mSelf) {
13 | mSelf = new LogManager();
14 | trace_initialize();
15 | }
16 | return *mSelf;
17 | }
18 |
19 | LogManager::LogManager() : CurrentLogLevel(LOG_LEVEL::LOG_NO_LEVEL){
20 |
21 | }
22 |
23 | void LogManager::setLogLevel(LOG_LEVEL l) {
24 | CurrentLogLevel = l;
25 | }
26 |
27 | LOG_LEVEL LogManager::getLogLevel() const {
28 | return CurrentLogLevel;
29 | }
30 |
31 | static Logger *Loggers[darknet::NUMBER_OF_LOGGERS] = {0};
32 |
33 | void LogManager::addLogger(uint32_t id, Logger *l) {
34 | if(id=darknet::NUMBER_OF_LOGGERS) return 0;
40 | return Loggers[id];
41 | }
42 |
43 | ////////////////////////////////////////
44 |
45 | Logger::Logger(LOG_LEVEL l) : CurrentLogLevel(l) {
46 |
47 | }
48 |
49 | const LOG_LEVEL &Logger::getLogLevel() {
50 | return CurrentLogLevel;
51 | }
52 |
53 | void Logger::printf(const LogManager &lm, const char *format,...) {
54 | if(lm.getLogLevel()<=getLogLevel()) {
55 | va_list ap;
56 | va_start (ap, format);
57 | static char buf[64];
58 | int ret = vsnprintf (buf, sizeof(buf), format, ap);
59 | if(ret>0) {
60 | onPrintf(buf,(uint16_t)ret);
61 | }
62 | va_end (ap);
63 | }
64 | }
65 |
66 |
67 | Logger::~Logger() {
68 |
69 | }
70 |
71 |
72 |
73 | darknet::STM32Logger::STM32Logger(LOG_LEVEL l) : Logger(l) {
74 |
75 | }
76 |
77 | void darknet::STM32Logger::onPrintf(const char *msg, uint16_t size) {
78 | trace_write (msg, (unsigned int)size);
79 | }
80 |
--------------------------------------------------------------------------------
/software/firmware-test/src/badge/logger.h:
--------------------------------------------------------------------------------
1 | #ifndef DCDARK_LOGGER_H
2 | #define DCDARK_LOGGER_H
3 |
4 | #include
5 | #include
6 |
7 | namespace darknet {
8 | class Logger;
9 | static const uint32_t DEBUG_LOGGER_ID = 0;
10 | static const uint32_t INFO_LOGGER_ID = 1;
11 | static const uint32_t ERROR_LOGGER_ID = 2;
12 | static const uint32_t NUMBER_OF_LOGGERS = 3;
13 |
14 | enum LOG_LEVEL {
15 | LOG_DEBUG_LEVEL = 0
16 | , LOG_INFO_LEVEL = 1
17 | , LOG_ERROR_LEVEL = 2
18 | , LOG_NO_LEVEL = 3
19 | };
20 | class LogManager {
21 | public:
22 | void setLogLevel(LOG_LEVEL l);
23 | LOG_LEVEL getLogLevel() const;
24 | Logger *getLogger(const uint32_t &logID);
25 | void addLogger(uint32_t id, Logger *l);
26 | public:
27 | static LogManager &get();
28 | protected:
29 | LogManager();
30 | private:
31 | static LogManager *mSelf;
32 | LOG_LEVEL CurrentLogLevel;
33 | };
34 | class Logger {
35 | public:
36 | Logger(LOG_LEVEL l);
37 | const LOG_LEVEL &getLogLevel();
38 | void printf(const LogManager &lm, const char *format,...);
39 | virtual ~Logger();
40 | protected:
41 | virtual void onPrintf(const char *msg, uint16_t size)=0;
42 | private:
43 | LOG_LEVEL CurrentLogLevel;
44 | };
45 | class STM32Logger : public darknet::Logger {
46 | public:
47 | STM32Logger(LOG_LEVEL l);
48 | protected:
49 | virtual void onPrintf(const char *msg, uint16_t size);
50 | };
51 | }
52 |
53 | #define DBGMSG(a) if(LogManger::get().getLogger(DEBUG_LOGGER_ID)) \
54 | LogManger::get().getLogger(DEBUG_LOGGER_ID)->printf(LogManger::get().getLogger(DEBUG_LOGGER_ID),a)
55 | #define INFOMSG(a) if(LogManger::get().getLogger(INFO_LOGGER_ID)) \
56 | LogManger::get().getLogger(INFO_LOGGER_ID)->printf(LogManger::get().getLogger(INFO_LOGGER_ID),a)
57 | #define ERRMSG(a) if(LogManger::get().getLogger(ERROR_LOGGER_ID)) \
58 | LogManger::get().getLogger(ERROR_LOGGER_ID)->printf(LogManger::get().getLogger(ERROR_LOGGER_ID),a)
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/software/firmware-test/src/stm32f3xx_hal_msp.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * File Name : stm32f3xx_hal_msp.c
4 | * Description : This file provides code for the MSP Initialization
5 | * and de-Initialization codes.
6 | ******************************************************************************
7 | *
8 | * COPYRIGHT(c) 2017 STMicroelectronics
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *
32 | ******************************************************************************
33 | */
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f3xx_hal.h"
36 |
37 | /* USER CODE BEGIN 0 */
38 |
39 | /* USER CODE END 0 */
40 |
41 | /**
42 | * Initializes the Global MSP.
43 | */
44 | void HAL_MspInit(void)
45 | {
46 | /* USER CODE BEGIN MspInit 0 */
47 |
48 | /* USER CODE END MspInit 0 */
49 |
50 | __HAL_RCC_SYSCFG_CLK_ENABLE();
51 |
52 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
53 |
54 | /* System interrupt init*/
55 | /* MemoryManagement_IRQn interrupt configuration */
56 | HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
57 | /* BusFault_IRQn interrupt configuration */
58 | HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
59 | /* UsageFault_IRQn interrupt configuration */
60 | HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
61 | /* DebugMonitor_IRQn interrupt configuration */
62 | HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
63 | /* SysTick_IRQn interrupt configuration */
64 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
65 |
66 | /* USER CODE BEGIN MspInit 1 */
67 |
68 | /* USER CODE END MspInit 1 */
69 | }
70 |
71 | /* USER CODE BEGIN 1 */
72 |
73 | /* USER CODE END 1 */
74 |
75 | /**
76 | * @}
77 | */
78 |
79 | /**
80 | * @}
81 | */
82 |
83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
84 |
--------------------------------------------------------------------------------
/software/firmware-test/src/usb_device.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : USB_DEVICE
4 | * @version : v1.0_Cube
5 | * @brief : This file implements the USB Device
6 | ******************************************************************************
7 | *
8 | * COPYRIGHT(c) 2017 STMicroelectronics
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 | * may be used to endorse or promote products derived from this software
19 | * without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *
32 | ******************************************************************************
33 | */
34 |
35 | /* Includes ------------------------------------------------------------------*/
36 |
37 | #include "usb_device.h"
38 | #include "usbd_core.h"
39 | #include "usbd_desc.h"
40 | #include "usbd_cdc.h"
41 | #include "usbd_cdc_if.h"
42 |
43 | /* USB Device Core handle declaration */
44 | USBD_HandleTypeDef hUsbDeviceFS;
45 |
46 | /* init function */
47 | void MX_USB_DEVICE_Init(void)
48 | {
49 | /* Init Device Library,Add Supported Class and Start the library*/
50 | USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
51 |
52 | USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC);
53 |
54 | USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);
55 |
56 | USBD_Start(&hUsbDeviceFS);
57 |
58 | }
59 | /**
60 | * @}
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
68 |
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/README_DEVICE_30x.txt:
--------------------------------------------------------------------------------
1 | The stm32f30x.h and system_stm32f30x.h files are from stsw-stm32108.zip,
2 | the folder:
3 |
4 | STM32F30x_DSP_StdPeriph_Lib_V1.0.0/Libraries/CMSIS/Device/ST/STM32F30x/Include
5 |
6 | The cmsis_device.h is added for convenience.
7 |
8 |
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/cmsis_device.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | #ifndef STM32F3_CMSIS_DEVICE_H_
7 | #define STM32F3_CMSIS_DEVICE_H_
8 |
9 | #if defined(STM32F30X)
10 | #include "stm32f3xx.h"
11 | #elif defined(STM32F37X)
12 | #include "stm32f3xx.h"
13 | #else
14 | #error "No CMSIS header file"
15 | #endif
16 |
17 | #endif // STM32F3_CMSIS_DEVICE_H_
18 |
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f301x8.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f301x8.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f302x8.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f302x8.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f302xc.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f302xc.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f302xe.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f302xe.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f303x8.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f303x8.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f303xc.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f303xc.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f303xe.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f303xe.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f318xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f318xx.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f328xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f328xx.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f334x8.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f334x8.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f358xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f358xx.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f373xc.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f373xc.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f378xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f378xx.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f398xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f398xx.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cmsis/device/stm32f3xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware-test/system/include/cmsis/device/stm32f3xx.h
--------------------------------------------------------------------------------
/software/firmware-test/system/include/cortexm/ExceptionHandlers.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | #ifndef CORTEXM_EXCEPTION_HANDLERS_H_
7 | #define CORTEXM_EXCEPTION_HANDLERS_H_
8 |
9 | #include
10 |
11 | #if defined(DEBUG)
12 | #define __DEBUG_BKPT() asm volatile ("bkpt 0")
13 | #endif
14 |
15 | // ----------------------------------------------------------------------------
16 |
17 | #if defined(__cplusplus)
18 | extern "C"
19 | {
20 | #endif
21 |
22 | // External references to cortexm_handlers.c
23 |
24 | extern void
25 | Reset_Handler (void);
26 | extern void
27 | NMI_Handler (void);
28 | extern void
29 | HardFault_Handler (void);
30 |
31 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
32 | extern void
33 | MemManage_Handler (void);
34 | extern void
35 | BusFault_Handler (void);
36 | extern void
37 | UsageFault_Handler (void);
38 | extern void
39 | DebugMon_Handler (void);
40 | #endif
41 |
42 | extern void
43 | SVC_Handler (void);
44 |
45 | extern void
46 | PendSV_Handler (void);
47 | extern void
48 | SysTick_Handler (void);
49 |
50 | // Exception Stack Frame of the Cortex-M3 or Cortex-M4 processor.
51 | typedef struct
52 | {
53 | uint32_t r0;
54 | uint32_t r1;
55 | uint32_t r2;
56 | uint32_t r3;
57 | uint32_t r12;
58 | uint32_t lr;
59 | uint32_t pc;
60 | uint32_t psr;
61 | #if defined(__ARM_ARCH_7EM__)
62 | uint32_t s[16];
63 | #endif
64 | } ExceptionStackFrame;
65 |
66 | #if defined(TRACE)
67 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
68 | void
69 | dumpExceptionStack (ExceptionStackFrame* frame, uint32_t cfsr, uint32_t mmfar,
70 | uint32_t bfar, uint32_t lr);
71 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
72 | #if defined(__ARM_ARCH_6M__)
73 | void
74 | dumpExceptionStack (ExceptionStackFrame* frame, uint32_t lr);
75 | #endif // defined(__ARM_ARCH_6M__)
76 | #endif // defined(TRACE)
77 |
78 | void
79 | HardFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr);
80 |
81 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
82 | void
83 | UsageFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr);
84 | void
85 | BusFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr);
86 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
87 |
88 | #if defined(__cplusplus)
89 | }
90 | #endif
91 |
92 | // ----------------------------------------------------------------------------
93 |
94 | #endif // CORTEXM_EXCEPTION_HANDLERS_H_
95 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/cortexm/_initialize_hardware.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include "cmsis_device.h"
9 |
10 | // ----------------------------------------------------------------------------
11 |
12 | extern unsigned int __vectors_start;
13 |
14 | // Forward declarations.
15 |
16 | void
17 | __initialize_hardware_early(void);
18 |
19 | void
20 | __initialize_hardware(void);
21 |
22 | // ----------------------------------------------------------------------------
23 |
24 | // This is the early hardware initialisation routine, it can be
25 | // redefined in the application for more complex cases that
26 | // require early inits (before BSS init).
27 | //
28 | // Called early from _start(), right before data & bss init.
29 | //
30 | // After Reset the Cortex-M processor is in Thread mode,
31 | // priority is Privileged, and the Stack is set to Main.
32 |
33 | void
34 | __attribute__((weak))
35 | __initialize_hardware_early(void)
36 | {
37 | // Call the CSMSIS system initialisation routine.
38 | SystemInit();
39 |
40 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
41 | // Set VTOR to the actual address, provided by the linker script.
42 | // Override the manual, possibly wrong, SystemInit() setting.
43 | SCB->VTOR = (uint32_t)(&__vectors_start);
44 | #endif
45 |
46 | // The current version of SystemInit() leaves the value of the clock
47 | // in a RAM variable (SystemCoreClock), which will be cleared shortly,
48 | // so it needs to be recomputed after the RAM initialisations
49 | // are completed.
50 |
51 | #if defined(OS_INCLUDE_STARTUP_INIT_FP) || (defined (__VFP_FP__) && !defined (__SOFTFP__))
52 |
53 | // Normally FP init is done by SystemInit(). In case this is not done
54 | // there, it is possible to force its inclusion by defining
55 | // OS_INCLUDE_STARTUP_INIT_FP.
56 |
57 | // Enable the Cortex-M4 FPU only when -mfloat-abi=hard.
58 | // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)
59 |
60 | // Set bits 20-23 to enable CP10 and CP11 coprocessor
61 | SCB->CPACR |= (0xF << 20);
62 |
63 | #endif // (__VFP_FP__) && !(__SOFTFP__)
64 |
65 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
66 | SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk;
67 | #endif
68 | }
69 |
70 | // This is the second hardware initialisation routine, it can be
71 | // redefined in the application for more complex cases that
72 | // require custom inits (before constructors), otherwise these can
73 | // be done in main().
74 | //
75 | // Called from _start(), right after data & bss init, before
76 | // constructors.
77 |
78 | void
79 | __attribute__((weak))
80 | __initialize_hardware(void)
81 | {
82 | // Call the CSMSIS system clock routine to store the clock frequency
83 | // in the SystemCoreClock global RAM location.
84 | SystemCoreClockUpdate();
85 | }
86 |
87 | // ----------------------------------------------------------------------------
88 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/cortexm/_reset_hardware.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include "cmsis_device.h"
9 |
10 | // ----------------------------------------------------------------------------
11 |
12 | extern void
13 | __attribute__((noreturn))
14 | NVIC_SystemReset(void);
15 |
16 | // ----------------------------------------------------------------------------
17 |
18 | // Forward declarations
19 |
20 | void
21 | __reset_hardware(void);
22 |
23 | // ----------------------------------------------------------------------------
24 |
25 | // This is the default hardware reset routine; it can be
26 | // redefined in the application for more complex applications.
27 | //
28 | // Called from _exit().
29 |
30 | void
31 | __attribute__((weak,noreturn))
32 | __reset_hardware()
33 | {
34 | NVIC_SystemReset();
35 | }
36 |
37 | // ----------------------------------------------------------------------------
38 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/diag/Trace.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #if defined(TRACE)
9 |
10 | #include
11 | #include
12 | #include "diag/Trace.h"
13 | #include "string.h"
14 |
15 | #ifndef OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE
16 | #define OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE (128)
17 | #endif
18 |
19 | // ----------------------------------------------------------------------------
20 |
21 | int
22 | trace_printf(const char* format, ...)
23 | {
24 | int ret;
25 | va_list ap;
26 |
27 | va_start (ap, format);
28 |
29 | // TODO: rewrite it to no longer use newlib, it is way too heavy
30 |
31 | static char buf[OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE];
32 |
33 | // Print to the local buffer
34 | ret = vsnprintf (buf, sizeof(buf), format, ap);
35 | if (ret > 0)
36 | {
37 | // Transfer the buffer to the device
38 | ret = trace_write (buf, (size_t)ret);
39 | }
40 |
41 | va_end (ap);
42 | return ret;
43 | }
44 |
45 | int
46 | trace_puts(const char *s)
47 | {
48 | trace_write(s, strlen(s));
49 | return trace_write("\n", 1);
50 | }
51 |
52 | int
53 | trace_putchar(int c)
54 | {
55 | trace_write((const char*)&c, 1);
56 | return c;
57 | }
58 |
59 | void
60 | trace_dump_args(int argc, char* argv[])
61 | {
62 | trace_printf("main(argc=%d, argv=[", argc);
63 | for (int i = 0; i < argc; ++i)
64 | {
65 | if (i != 0)
66 | {
67 | trace_printf(", ");
68 | }
69 | trace_printf("\"%s\"", argv[i]);
70 | }
71 | trace_printf("]);\n");
72 | }
73 |
74 | // ----------------------------------------------------------------------------
75 |
76 | #endif // TRACE
77 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/newlib/README.txt:
--------------------------------------------------------------------------------
1 |
2 | The following files extend or replace some of the the newlib functionality:
3 |
4 | _startup.c: a customised startup sequence, written in C
5 |
6 | _exit.c: a customised exit() implementation
7 |
8 | _syscalls.c: local versions of the libnosys/librdimon code
9 |
10 | _sbrk.c: a custom _sbrk() to match the actual linker scripts
11 |
12 | assert.c: implementation for the asserion macros
13 |
14 | _cxx.cpp: local versions of some C++ support, to avoid references to
15 | large functions.
16 |
17 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/newlib/_cxx.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | // These functions are redefined locally, to avoid references to some
9 | // heavy implementations in the standard C++ library.
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | #include
14 | #include
15 | #include "diag/Trace.h"
16 |
17 | // ----------------------------------------------------------------------------
18 |
19 | namespace __gnu_cxx
20 | {
21 | void
22 | __attribute__((noreturn))
23 | __verbose_terminate_handler();
24 |
25 | void
26 | __verbose_terminate_handler()
27 | {
28 | trace_puts(__func__);
29 | abort();
30 | }
31 | }
32 |
33 | // ----------------------------------------------------------------------------
34 |
35 | extern "C"
36 | {
37 | void
38 | __attribute__((noreturn))
39 | __cxa_pure_virtual();
40 |
41 | void
42 | __cxa_pure_virtual()
43 | {
44 | trace_puts(__func__);
45 | abort();
46 | }
47 | }
48 |
49 | // ----------------------------------------------------------------------------
50 |
51 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/newlib/_exit.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include
9 | #include "diag/Trace.h"
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | #if !defined(DEBUG)
14 | extern void
15 | __attribute__((noreturn))
16 | __reset_hardware(void);
17 | #endif
18 |
19 | // ----------------------------------------------------------------------------
20 |
21 | // Forward declaration
22 |
23 | void
24 | _exit(int code);
25 |
26 | // ----------------------------------------------------------------------------
27 |
28 | // On Release, call the hardware reset procedure.
29 | // On Debug we just enter an infinite loop, to be used as landmark when halting
30 | // the debugger.
31 | //
32 | // It can be redefined in the application, if more functionality
33 | // is required.
34 |
35 | void
36 | __attribute__((weak))
37 | _exit(int code __attribute__((unused)))
38 | {
39 | #if !defined(DEBUG)
40 | __reset_hardware();
41 | #endif
42 |
43 | // TODO: write on trace
44 | while (1)
45 | ;
46 | }
47 |
48 | // ----------------------------------------------------------------------------
49 |
50 | void
51 | __attribute__((weak,noreturn))
52 | abort(void)
53 | {
54 | trace_puts("abort(), exiting...");
55 |
56 | _exit(1);
57 | }
58 |
59 | // ----------------------------------------------------------------------------
60 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/newlib/_sbrk.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include
9 | #include
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | caddr_t
14 | _sbrk(int incr);
15 |
16 | // ----------------------------------------------------------------------------
17 |
18 | // The definitions used here should be kept in sync with the
19 | // stack definitions in the linker script.
20 |
21 | caddr_t
22 | _sbrk(int incr)
23 | {
24 | extern char _Heap_Begin; // Defined by the linker.
25 | extern char _Heap_Limit; // Defined by the linker.
26 |
27 | static char* current_heap_end;
28 | char* current_block_address;
29 |
30 | if (current_heap_end == 0)
31 | {
32 | current_heap_end = &_Heap_Begin;
33 | }
34 |
35 | current_block_address = current_heap_end;
36 |
37 | // Need to align heap to word boundary, else will get
38 | // hard faults on Cortex-M0. So we assume that heap starts on
39 | // word boundary, hence make sure we always add a multiple of
40 | // 4 to it.
41 | incr = (incr + 3) & (~3); // align value to 4
42 | if (current_heap_end + incr > &_Heap_Limit)
43 | {
44 | // Some of the libstdc++-v3 tests rely upon detecting
45 | // out of memory errors, so do not abort here.
46 | #if 0
47 | extern void abort (void);
48 |
49 | _write (1, "_sbrk: Heap and stack collision\n", 32);
50 |
51 | abort ();
52 | #else
53 | // Heap has overflowed
54 | errno = ENOMEM;
55 | return (caddr_t) - 1;
56 | #endif
57 | }
58 |
59 | current_heap_end += incr;
60 |
61 | return (caddr_t) current_block_address;
62 | }
63 |
64 | // ----------------------------------------------------------------------------
65 |
66 |
--------------------------------------------------------------------------------
/software/firmware-test/system/src/newlib/assert.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include "diag/Trace.h"
11 |
12 | // ----------------------------------------------------------------------------
13 |
14 | void
15 | __attribute__((noreturn))
16 | __assert_func (const char *file, int line, const char *func,
17 | const char *failedexpr)
18 | {
19 | trace_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
20 | failedexpr, file, line, func ? ", function: " : "",
21 | func ? func : "");
22 | abort ();
23 | /* NOTREACHED */
24 | }
25 |
26 | // ----------------------------------------------------------------------------
27 |
28 | // This is STM32 specific, but can be used on other platforms too.
29 | // If you need it, add the following to your application header:
30 |
31 | //#ifdef USE_FULL_ASSERT
32 | //#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
33 | //void assert_failed(uint8_t* file, uint32_t line);
34 | //#else
35 | //#define assert_param(expr) ((void)0)
36 | //#endif // USE_FULL_ASSERT
37 |
38 | #if defined(USE_FULL_ASSERT)
39 |
40 | void
41 | assert_failed (uint8_t* file, uint32_t line);
42 |
43 | // Called from the assert_param() macro, usually defined in the stm32f*_conf.h
44 | void
45 | __attribute__((noreturn, weak))
46 | assert_failed (uint8_t* file, uint32_t line)
47 | {
48 | trace_printf ("assert_param() failed: file \"%s\", line %d\n", file, line);
49 | abort ();
50 | /* NOTREACHED */
51 | }
52 |
53 | #endif // defined(USE_FULL_ASSERT)
54 |
55 | // ----------------------------------------------------------------------------
56 |
--------------------------------------------------------------------------------
/software/firmware/.gitignore:
--------------------------------------------------------------------------------
1 | /Debug/
2 | /Release/
3 | /Debug-Size/
4 |
--------------------------------------------------------------------------------
/software/firmware/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | firmware
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/software/firmware/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_req.h
4 | * @author MCD Application Team
5 | * @version V2.4.2
6 | * @date 11-December-2015
7 | * @brief Header file for the usbd_req.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2015 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __USB_REQUEST_H
30 | #define __USB_REQUEST_H
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | /* Includes ------------------------------------------------------------------*/
37 | #include "usbd_def.h"
38 |
39 |
40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY
41 | * @{
42 | */
43 |
44 | /** @defgroup USBD_REQ
45 | * @brief header file for the usbd_req.c file
46 | * @{
47 | */
48 |
49 | /** @defgroup USBD_REQ_Exported_Defines
50 | * @{
51 | */
52 | /**
53 | * @}
54 | */
55 |
56 |
57 | /** @defgroup USBD_REQ_Exported_Types
58 | * @{
59 | */
60 | /**
61 | * @}
62 | */
63 |
64 |
65 |
66 | /** @defgroup USBD_REQ_Exported_Macros
67 | * @{
68 | */
69 | /**
70 | * @}
71 | */
72 |
73 | /** @defgroup USBD_REQ_Exported_Variables
74 | * @{
75 | */
76 | /**
77 | * @}
78 | */
79 |
80 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype
81 | * @{
82 | */
83 |
84 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
85 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
86 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
87 |
88 |
89 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
90 |
91 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata);
92 |
93 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len);
94 | /**
95 | * @}
96 | */
97 |
98 | #ifdef __cplusplus
99 | }
100 | #endif
101 |
102 | #endif /* __USB_REQUEST_H */
103 |
104 | /**
105 | * @}
106 | */
107 |
108 | /**
109 | * @}
110 | */
111 |
112 |
113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
114 |
--------------------------------------------------------------------------------
/software/firmware/include/stm32f3xx_it.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f3xx_it.h
4 | * @brief This file contains the headers of the interrupt handlers.
5 | ******************************************************************************
6 | *
7 | * COPYRIGHT(c) 2017 STMicroelectronics
8 | *
9 | * Redistribution and use in source and binary forms, with or without modification,
10 | * are permitted provided that the following conditions are met:
11 | * 1. Redistributions of source code must retain the above copyright notice,
12 | * this list of conditions and the following disclaimer.
13 | * 2. Redistributions in binary form must reproduce the above copyright notice,
14 | * this list of conditions and the following disclaimer in the documentation
15 | * and/or other materials provided with the distribution.
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
17 | * may be used to endorse or promote products derived from this software
18 | * without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | ******************************************************************************
32 | */
33 |
34 | /* Define to prevent recursive inclusion -------------------------------------*/
35 | #ifndef __STM32F3xx_IT_H
36 | #define __STM32F3xx_IT_H
37 |
38 | #ifdef __cplusplus
39 | extern "C" {
40 | #endif
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | /* Exported types ------------------------------------------------------------*/
44 | /* Exported constants --------------------------------------------------------*/
45 | /* Exported macro ------------------------------------------------------------*/
46 | /* Exported functions ------------------------------------------------------- */
47 |
48 | void NMI_Handler(void);
49 | void HardFault_Handler(void);
50 | void MemManage_Handler(void);
51 | void BusFault_Handler(void);
52 | void UsageFault_Handler(void);
53 | void DebugMon_Handler(void);
54 | void SysTick_Handler(void);
55 | void DMA1_Channel5_IRQHandler(void);
56 | void USB_LP_CAN_RX0_IRQHandler(void);
57 | void DMA2_Channel1_IRQHandler(void);
58 | void DMA2_Channel2_IRQHandler(void);
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 |
64 | #endif /* __STM32F3xx_IT_H */
65 |
66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
67 |
--------------------------------------------------------------------------------
/software/firmware/include/usb_device.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file : USB_DEVICE
4 | * @version : v2.0_Cube
5 | * @brief : Header for usb_device file.
6 | ******************************************************************************
7 | *
8 | * Copyright (c) 2017 STMicroelectronics International N.V.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted, provided that the following conditions are met:
13 | *
14 | * 1. Redistribution of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. Neither the name of STMicroelectronics nor the names of other
20 | * contributors to this software may be used to endorse or promote products
21 | * derived from this software without specific written permission.
22 | * 4. This software, including modifications and/or derivative works of this
23 | * software, must execute solely and exclusively on microcontroller or
24 | * microprocessor devices manufactured by or for STMicroelectronics.
25 | * 5. Redistribution and use of this software other than as permitted under
26 | * this license is void and will automatically terminate your rights under
27 | * this license.
28 | *
29 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
30 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
33 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
34 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
37 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 | *
42 | ******************************************************************************
43 | */
44 | /* Define to prevent recursive inclusion -------------------------------------*/
45 | #ifndef __usb_device_H
46 | #define __usb_device_H
47 | #ifdef __cplusplus
48 | extern "C" {
49 | #endif
50 |
51 | /* Includes ------------------------------------------------------------------*/
52 | #include "stm32f3xx.h"
53 | #include "stm32f3xx_hal.h"
54 | #include "usbd_def.h"
55 |
56 | extern USBD_HandleTypeDef hUsbDeviceFS;
57 |
58 | /* USB_Device init function */
59 | void MX_USB_DEVICE_Init(void);
60 |
61 | #ifdef __cplusplus
62 | }
63 | #endif
64 | #endif /*__usb_device_H */
65 |
66 | /**
67 | * @}
68 | */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
75 |
--------------------------------------------------------------------------------
/software/firmware/ldscripts/libs.ld:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Placeholder to list other libraries required by the application.
4 |
5 | GROUP(
6 | )
7 |
8 | */
9 |
--------------------------------------------------------------------------------
/software/firmware/ldscripts/mem.ld:
--------------------------------------------------------------------------------
1 | /*
2 | * Memory Spaces Definitions.
3 | *
4 | * Need modifying for a specific board.
5 | * FLASH.ORIGIN: starting address of flash
6 | * FLASH.LENGTH: length of flash
7 | * RAM.ORIGIN: starting address of RAM bank 0
8 | * RAM.LENGTH: length of RAM bank 0
9 | *
10 | * The values below can be addressed in further linker scripts
11 | * using functions like 'ORIGIN(RAM)' or 'LENGTH(RAM)'.
12 | */
13 |
14 | MEMORY
15 | {
16 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
17 | CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 16K
18 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
19 | FLASHB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
20 | EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0
21 | EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
22 | EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0
23 | EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0
24 | MEMORY_ARRAY (xrw) : ORIGIN = 0x20002000, LENGTH = 0
25 | }
26 |
27 | /*
28 | * For external ram use something like:
29 |
30 | RAM (xrw) : ORIGIN = 0x64000000, LENGTH = 2048K
31 |
32 | */
33 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/3d/menu3d.h:
--------------------------------------------------------------------------------
1 | #ifndef MENU3D
2 | #define MENU3D
3 |
4 | #include "../menus.h"
5 | #include "renderer.h"
6 |
7 | class Model;
8 |
9 | class Menu3D : public StateBase {
10 | public:
11 | Menu3D();
12 | virtual ~Menu3D();
13 | public:
14 | protected:
15 | virtual ErrorType onInit(RunContext &rc);
16 | virtual ReturnStateContext onRun(RunContext &rc);
17 | virtual ErrorType onShutdown();
18 | void initMenu3d(RunContext &rc);
19 | void update(RunContext &rc);
20 | void render(RunContext &rc);
21 | private:
22 | Model model;
23 | Vec3f light_dir;
24 | Vec3f eye;
25 | static const Vec3f center;
26 | static const Vec3f up;
27 | uint8_t CanvasWidth;
28 | uint8_t CanvasHeight;
29 | };
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/3d/renderer.h:
--------------------------------------------------------------------------------
1 | #ifndef RENDERER_H
2 | #define RENDERER_H
3 |
4 | #include "vec_math.h"
5 | #include "../display_device.h"
6 |
7 |
8 | extern Matrix ModelView;
9 | extern Matrix Viewport;
10 | extern Matrix Projection;
11 |
12 | struct VertexStruct {
13 | Vec3f pos;
14 | RGBColor color;
15 | //VertexStruct(const Vec3f &p, const RGBColor &r) : pos(p), color(r) {}
16 | };
17 |
18 |
19 | class Model {
20 | //no model matrix to save space and computation we assume identity
21 | public:
22 | enum MODEL_FORMAT {
23 | VERTS,
24 | STRIPS
25 | };
26 | Model();
27 | void set(const VertexStruct *v, uint16_t nv, const uint16_t *i, uint16_t ni, MODEL_FORMAT format);
28 | const Vec3f &normal(uint16_t face, uint8_t nVert) const;
29 | const Vec3f &vert(uint16_t face, uint8_t nVert) const;
30 | uint32_t nFaces() const;
31 | const Matrix &getModelTransform() const {return ModelTransform;}
32 | void setTransformation(float t) {ModelTransform.setRotation(t);}
33 | void scale(float t) {ModelTransform.scale(t);}
34 | private:
35 | const VertexStruct *Verts;
36 | uint16_t NumVerts;
37 | const uint16_t *Indexes;
38 | uint8_t NumIndexes;
39 | Matrix ModelTransform;
40 | MODEL_FORMAT Format;
41 | };
42 |
43 |
44 | class IShader {
45 | public:
46 | IShader();
47 | virtual ~IShader() = 0;
48 | virtual Vec3i vertex(const Matrix &ModelViewProj, const Model &model, int iface, int nthvert) = 0;
49 | virtual bool fragment(Vec3f bar, RGBColor &color) = 0;
50 | void setLightDir(const Vec3f &ld);
51 | const Vec3f &getLightDir() const;
52 | private:
53 | Vec3f LightDir;
54 | };
55 |
56 | class FlatShader: public IShader {
57 | public:
58 | FlatShader();
59 | virtual ~FlatShader();
60 |
61 | virtual Vec3i vertex(const Matrix &ModelViewProj, const Model &model, int iface, int nthvert);
62 | virtual bool fragment(Vec3f bar, RGBColor &color);
63 | private:
64 | mat<3, 3, float> varying_tri;
65 | };
66 |
67 | struct GouraudShader: public IShader {
68 | public:
69 | GouraudShader();
70 | virtual ~GouraudShader();
71 | virtual Vec3i vertex(const Matrix &ModelViewProj, const Model &model, int iface, int nthvert);
72 | virtual bool fragment(Vec3f bar, RGBColor &color);
73 | private:
74 | mat<3, 3, float> varying_tri;
75 | Vec3f varying_ity;
76 | };
77 |
78 | class ToonShader: public IShader {
79 | public:
80 | ToonShader();
81 | virtual ~ToonShader();
82 | virtual Vec3i vertex(const Matrix &ModelViewProj, const Model &model, int iface, int nthvert);
83 | virtual bool fragment(Vec3f bar, RGBColor &color);
84 | private:
85 | mat<3, 3, float> varying_tri;
86 | Vec3f varying_ity;
87 |
88 | };
89 |
90 | void viewport(int x, int y, int w, int h);
91 | void projection(float coeff = 0.f); // coeff = -1/c
92 | void lookat(const Vec3f &eye, const Vec3f ¢er, const Vec3f &up);
93 | //void triangle(Vec3i *pts, IShader &shader, BitArray &zbuffer, DisplayST7735 *display);
94 | void triangle(Vec3i *pts, IShader &shader, BitArray &zbuffer, DisplayST7735 *display, const Vec2i &bboxmin, const Vec2i &bboxmax, uint16_t canvasWdith);
95 |
96 | template T CLAMP(const T& value, const T& low, const T& high) {
97 | return value < low ? low : (value > high ? high : value);
98 | }
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/AddressState.h:
--------------------------------------------------------------------------------
1 | #ifndef ADDRESS_STATE_H
2 | #define ADDRESS_STATE_H
3 |
4 | #include "menus.h"
5 |
6 | class AddressState: public StateBase {
7 | public:
8 | AddressState();
9 | virtual ~AddressState();
10 | void resetSelection();
11 | protected:
12 | virtual ErrorType onInit(RunContext &rc);
13 | virtual ReturnStateContext onRun(RunContext &rc);
14 | virtual ErrorType onShutdown();
15 | void setNext4Items(uint16_t startAt, RunContext &rc);
16 | private:
17 | GUI_ListData AddressList;
18 | GUI_ListItemData Items[4];
19 | ContactStore::Contact CurrentContactList[4];
20 | GUI_ListData ContactDetails;
21 | GUI_ListItemData DetailItems[5];
22 | char RadioIDBuf[12];
23 | char PublicKey[64];
24 | char SignatureKey[128];
25 | uint8_t Index;
26 | GUI_ListData *DisplayList;
27 | };
28 |
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/GameOfLife.h:
--------------------------------------------------------------------------------
1 | #ifndef GAME_OF_LIFE_H
2 | #define GAME_OF_LIFE_H
3 |
4 | #include "menus.h"
5 |
6 | class GameOfLife: public StateBase {
7 | public:
8 | GameOfLife();
9 | virtual ~GameOfLife();
10 | public:
11 | static const int width = 32;
12 | static const int height = 64;
13 | static const uint32_t NEED_DRAW = 1<
5 |
6 | class KeyBoardLetterCtx {
7 | private:
8 | int16_t CursorPosition :10;
9 | int16_t Started :1;
10 | int16_t UnderBar :1;
11 | char *Buffer;
12 | char CurrentLetter;
13 | uint16_t BufferSize;
14 | uint32_t LastTimeLetterWasPushed;
15 | uint8_t LetterSelection;
16 | uint32_t LastBlinkTime;
17 | uint8_t LastPin;
18 | public:
19 | void processButtonPush(uint8_t button, const char *buttonLetters);
20 | bool isKeySelectionTimedOut();
21 | void timerStart();
22 | void timerStop();
23 | void incPosition();
24 | void decPosition();
25 | uint8_t getCursorPosition();
26 | void setCurrentLetterInBufferAndInc();
27 | void blinkLetter();
28 | KeyBoardLetterCtx();
29 | void resetChar();
30 | void finalize();
31 | void init(char *b, uint16_t s);
32 | };
33 |
34 | KeyBoardLetterCtx &getKeyboardContext();
35 | class DialerMode;
36 |
37 | class QKeyboard {
38 | public:
39 | struct PinConfig {
40 | uint32_t Pin;
41 | uint32_t SamplePin;
42 | uint32_t GroupIndex;
43 | PinConfig() :
44 | Pin(0), SamplePin(0), GroupIndex(0) {
45 | }
46 | PinConfig(uint32_t pin, uint32_t sample, uint32_t gi) :
47 | Pin(pin), SamplePin(sample), GroupIndex(gi) {
48 | }
49 | };
50 | static const uint8_t NO_PIN_SELECTED = 0xFF;
51 | static const uint8_t NOT_A_NUMBER = 0xFF;
52 | static const uint8_t NO_LETTER_SELECTED = 0xFF;
53 | static const uint8_t TIMES_BUTTON_MUST_BE_HELD = 2;
54 | enum KEYS {
55 | ONE = 0
56 | , TWO = 1
57 | , THREE = 2
58 | , FOUR = 3
59 | , FIVE = 4
60 | , SIX = 5
61 | , SEVEN = 6
62 | , EIGHT = 7
63 | , NINE = 8
64 | , ZERO = 9
65 | , HOOK = 10
66 | , BACK = ONE
67 | , ENTER = HOOK
68 | , UP=FIVE
69 | , DOWN=SIX
70 | };
71 | public:
72 | QKeyboard(const PinConfig *pinConfig, uint8_t count);
73 | void scan();
74 | ///last button pushed
75 | uint8_t getLastPinPushed();
76 | //last button pushed and held for at least TIMES_BUTTON_MUST_BE_HELD
77 | uint8_t getLastPinSeleted();
78 | uint8_t getLastKeyReleased();
79 | bool wasKeyReleased();
80 | void updateContext(KeyBoardLetterCtx &ctx);
81 | void reset();
82 | uint32_t getLastPinSelectedTick() {
83 | return LastPinSelectedTick;
84 | }
85 | char getNumberAsCharacter();
86 | void resetLastPinTick();
87 | bool isDialerMode();
88 | void setDialerMode(bool b);
89 | protected:
90 | void setLetter();
91 | private:
92 | const PinConfig *PC;
93 | uint8_t Count;
94 | uint8_t LastSelectedPin;
95 | uint8_t TimesLastPinSelected;
96 | uint8_t KeyJustReleased;
97 | uint32_t LastPinSelectedTick;
98 | private:
99 | DialerMode *DM;
100 | };
101 |
102 | #endif
103 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/MessageState.h:
--------------------------------------------------------------------------------
1 | #ifndef EVENT_STATE_H
2 | #define EVENT_STATE_H
3 |
4 | #include "menus.h"
5 | #include "Radio/RFM69.h"
6 |
7 | class MessageState: public StateBase {
8 | public:
9 | struct RadioMessage {
10 | char Msg[RF69_MAX_DATA_LEN];
11 | uint16_t FromUID;
12 | int8_t Rssi;
13 | RadioMessage();
14 | };
15 | enum {
16 | MESSAGE_LIST, DETAIL
17 | };
18 | public:
19 | MessageState();
20 | virtual ~MessageState();
21 | void addRadioMessage(const char *msg, uint16_t msgSize, uint16_t uid, uint8_t rssi);
22 | bool hasNewMessage() {return NewMessage;}
23 | protected:
24 | virtual ErrorType onInit(RunContext &rc);
25 | virtual ReturnStateContext onRun(RunContext &rc);
26 | virtual ErrorType onShutdown();
27 | private:
28 | RadioMessage RMsgs[8];
29 | uint8_t InternalState;
30 | GUI_ListData RadioList;
31 | GUI_ListItemData Items[8];
32 | uint8_t CurrentPos:7;
33 | uint8_t NewMessage:1;
34 | public:
35 | static const uint16_t MAX_R_MSGS = (sizeof(RMsgs) / sizeof(RMsgs[0]));
36 | };
37 | /*
38 | class EventState: public StateBase {
39 | public:
40 | struct MessageData {
41 | char Msg[24];
42 | MessageData();
43 | };
44 | public:
45 | EventState();
46 | virtual ~EventState();
47 | void addMessage(const char *pMsg);
48 | protected:
49 | virtual ErrorType onInit();
50 | virtual ReturnStateContext onRun(QKeyboard &kb);
51 | virtual ErrorType onShutdown();
52 | private:
53 | MessageData Msgs[5];
54 | uint8_t CurrentPos;
55 | GUI_ListData EventList;
56 | GUI_ListItemData Items[5];
57 | };
58 | */
59 | #endif
60 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/Radio/HardwareSPI.cpp:
--------------------------------------------------------------------------------
1 | // ArduinoCompat/HardwareSPI.cpp
2 | //
3 | // Interface between Arduino-like SPI interface and STM32F4 Discovery and similar
4 | // using STM32F4xx_DSP_StdPeriph_Lib_V1.3.0
5 |
6 |
7 | #include "HardwareSPI.h"
8 | #include
9 |
10 | HardwareSPI SPI;
11 |
12 | HardwareSPI::HardwareSPI() {
13 | }
14 |
15 | void HardwareSPI::begin() {
16 | //HAL_SPI_MspInit(&hspi1);
17 | }
18 |
19 | void HardwareSPI::end(void) {
20 | HAL_SPI_MspDeInit(&hspi3);
21 | }
22 |
23 | uint8_t HardwareSPI::transfer(uint8_t data) {
24 | /*
25 | typedef enum
26 | {
27 | HAL_OK = 0x00,
28 | HAL_ERROR = 0x01,
29 | HAL_BUSY = 0x02,
30 | HAL_TIMEOUT = 0x03
31 | } HAL_StatusTypeDef;
32 | */
33 |
34 | if (HAL_OK == HAL_SPI_TransmitReceive(&hspi3, &data, &data, 1, 1000)) {
35 | return data;
36 | }
37 | return 0;
38 |
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/Radio/HardwareSPI.h:
--------------------------------------------------------------------------------
1 | // ArduinoCompat/HardwareSPI.h
2 | // STM32 implementattion of Arduino compatible SPI class
3 |
4 | #ifndef _HardwareSPI_h
5 | #define _HardwareSPI_h
6 |
7 | #include
8 |
9 | typedef enum SPIFrequency {
10 | SPI_21_0MHZ = 0, /**< 21 MHz */
11 | SPI_10_5MHZ = 1, /**< 10.5 MHz */
12 | SPI_5_25MHZ = 2, /**< 5.25 MHz */
13 | SPI_2_625MHZ = 3, /**< 2.625 MHz */
14 | SPI_1_3125MHZ = 4, /**< 1.3125 MHz */
15 | SPI_656_25KHZ = 5, /**< 656.25 KHz */
16 | SPI_328_125KHZ = 6, /**< 328.125 KHz */
17 | } SPIFrequency;
18 |
19 | #define SPI_MODE0 0x00
20 | #define SPI_MODE1 0x04
21 | #define SPI_MODE2 0x08
22 | #define SPI_MODE3 0x0C
23 |
24 | class HardwareSPI {
25 | public:
26 | HardwareSPI(); // Only port SPI1 is currently supported
27 | void begin();
28 | void end(void);
29 | uint8_t transfer(uint8_t data);
30 | };
31 | extern HardwareSPI SPI;
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/SendMsgState.cpp:
--------------------------------------------------------------------------------
1 | #include "SendMsgState.h"
2 | #include "Radio/RFM69.h"
3 |
4 | SendMsgState::SendMsgState() :
5 | StateBase(), RadioID(0), AgentName(0), MsgBuffer(), InternalState(TYPE_MESSAGE) {
6 |
7 | }
8 | SendMsgState::~SendMsgState() {
9 |
10 | }
11 | void SendMsgState::setContactToMessage(const uint16_t radioID, const char *agentName) {
12 | RadioID = radioID;
13 | AgentName = agentName;
14 | }
15 |
16 | ErrorType SendMsgState::onInit(RunContext &rc) {
17 | if (shouldReset()) {
18 | memset(&MsgBuffer[0], 0, sizeof(MsgBuffer));
19 | getKeyboardContext().init(&MsgBuffer[0], sizeof(MsgBuffer));
20 | } else {
21 | clearState(DONT_RESET);
22 | }
23 | InternalState = TYPE_MESSAGE;
24 | rc.getDisplay().fillScreen(RGBColor::BLACK);
25 | return ErrorType();
26 | }
27 |
28 | ReturnStateContext SendMsgState::onRun(RunContext &rc) {
29 | StateBase *nextState = this;
30 | switch (InternalState) {
31 | case TYPE_MESSAGE: {
32 | rc.getDisplay().drawString(0,10,(const char *)"Send Message: ");
33 | rc.getDisplay().drawString(0,20,&MsgBuffer[0],RGBColor::WHITE, RGBColor::BLACK,1,true);
34 | //keyboard entry
35 | rc.getKB().updateContext(getKeyboardContext());
36 | uint8_t pin = rc.getKB().getLastKeyReleased();
37 | if (pin == QKeyboard::ENTER) { //return has been pushed
38 | getKeyboardContext().finalize();
39 | InternalState = INTERNAL_STATE::CONFIRM_SEND;
40 | }
41 | }
42 | break;
43 | case CONFIRM_SEND: {
44 | rc.getDisplay().drawStringOnLine(1,(const char *)"Send by pressing return (hook).");
45 | rc.getDisplay().drawStringOnLine(3,(const char *)"Cancel by pressing back (1).");
46 | //gui_lable_multiline(&MsgBuffer[0], 0, 30, 128, 64, 0, 0);
47 | uint8_t pin = rc.getKB().getLastKeyReleased();
48 | if (pin == QKeyboard::BACK) {
49 | InternalState = TYPE_MESSAGE;
50 | } else if (pin == QKeyboard::ENTER) {
51 | InternalState = SENDING;
52 | }
53 | }
54 | break;
55 | case SENDING: {
56 | static char buf[32];
57 | sprintf(&buf[0], "Sending Message to: %s", AgentName);
58 | rc.getDisplay().drawString(0,10,&buf[0]);
59 | #ifdef DONT_USE_ACK
60 | rc.getRadio().send(RadioID, &MsgBuffer[0], strlen(&MsgBuffer[0]), false);
61 | nextState = StateFactory::getDisplayMessageState(StateFactory::getMenuState(), "Message Sent!", 5000);
62 | #else
63 | //TODO get ack working
64 | if (getRadio().sendWithRetry(RadioID, &MsgBuffer[0], strlen(&MsgBuffer[0]), 1, 400)) {
65 | nextState = StateFactory::getDisplayMessageState(StateFactory::getMenuState(), "Message Sent Successfully!",
66 | 5000);
67 | } else {
68 | static char ResultBuf[64];
69 | sprintf(&ResultBuf[0],"Failed to send: \nAddress: %d\n N: %s", RadioID,AgentName);
70 | nextState = StateFactory::getDisplayMessageState(StateFactory::getSendMessageState(),
71 | &ResultBuf[0], 8000);
72 | setState(DONT_RESET);
73 | }
74 | #endif
75 | }
76 | break;
77 | }
78 | return ReturnStateContext(nextState);
79 | }
80 |
81 | ErrorType SendMsgState::onShutdown() {
82 | if (shouldReset()) {
83 | RadioID = 0;
84 | AgentName = 0;
85 | }
86 | return ErrorType();
87 | }
88 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/SendMsgState.h:
--------------------------------------------------------------------------------
1 | #ifndef SEND_MSG_STATE_H
2 | #define SEND_MSG_STATE_H
3 |
4 | #include "menus.h"
5 |
6 | class SendMsgState: public StateBase {
7 | public:
8 | static const uint16_t NO_CONTACT = 0xFFFF;
9 | enum INTERNAL_STATE {
10 | TYPE_MESSAGE, CONFIRM_SEND, SENDING
11 | };
12 | SendMsgState();
13 | virtual ~SendMsgState();
14 | void setContactToMessage(const uint16_t radioID, const char *agentName);
15 | protected:
16 | virtual ErrorType onInit(RunContext &rc);
17 | virtual ReturnStateContext onRun(RunContext &rc);
18 | virtual ErrorType onShutdown();
19 | private:
20 | uint16_t RadioID;
21 | const char *AgentName;
22 | char MsgBuffer[60];
23 | INTERNAL_STATE InternalState;
24 |
25 | };
26 |
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/bitarray.cpp:
--------------------------------------------------------------------------------
1 | #include "bitarray.h"
2 | #include
3 |
4 |
5 | BitArray::BitArray(uint8_t *array, uint32_t slots, uint8_t bitsPerSlot) :
6 | Array(array), Slots(slots), BitsPerSlot(bitsPerSlot), NumBytes(((Slots * BitsPerSlot) / 8) + 1) {
7 | clear();
8 | }
9 |
10 | void BitArray::clear() {
11 | memset(&Array[0], 0, NumBytes);
12 | }
13 |
14 | uint8_t BitArray::getValueAsByte(uint32_t slot) {
15 | uint32_t byte = (slot * BitsPerSlot) / 8;
16 | uint32_t bitOffSet = (slot * BitsPerSlot) % 8;
17 | uint32_t retVal = 0;
18 | for (int i = 0; i < BitsPerSlot; ++i) {
19 | if (Array[byte] & (1 << bitOffSet)) {
20 | retVal |= (1 << i);
21 | }
22 | bitOffSet = (++bitOffSet) % 8;
23 | if (!bitOffSet)
24 | byte++;
25 | }
26 | return retVal & 0xFF;
27 | }
28 |
29 | void BitArray::setValueAsByte(uint32_t slot, uint8_t value) {
30 | uint32_t byte = (slot * BitsPerSlot) / 8;
31 | uint32_t bitOffSet = (slot * BitsPerSlot) % 8;
32 | for (int i = 0; i < BitsPerSlot; ++i) {
33 | if (value & (1 << i)) {
34 | Array[byte] |= (1 << bitOffSet);
35 | } else {
36 | Array[byte] &= ~(1 << bitOffSet);
37 | }
38 | bitOffSet = ++bitOffSet % 8;
39 | if (!bitOffSet)
40 | byte++;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/bitarray.h:
--------------------------------------------------------------------------------
1 | #ifndef BIT_ARRAY_H
2 | #define BIT_ARRAY_H
3 |
4 | #include
5 |
6 | class BitArray {
7 | public:
8 | BitArray(uint8_t *array, uint32_t slots, uint8_t bitsPerSlot);
9 | void clear();
10 | uint8_t getValueAsByte(uint32_t slot);
11 | void setValueAsByte(uint32_t slot, uint8_t value);
12 | uint8_t getBitsPerSlot() {return BitsPerSlot;}
13 | private:
14 | uint8_t *Array;
15 | const uint32_t Slots;
16 | const uint8_t BitsPerSlot;
17 | const uint32_t NumBytes;
18 | };
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/crc.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * \file crc.c
3 | * Functions and types for CRC checks.
4 | *
5 | * Generated on Mon Jul 18 07:07:41 2016,
6 | * by pycrc v0.9, https://pycrc.org
7 | * using the configuration:
8 | * Width = 8
9 | * Poly = 0x07
10 | * Xor_In = 0x00
11 | * ReflectIn = False
12 | * Xor_Out = 0x00
13 | * ReflectOut = False
14 | * Algorithm = table-driven
15 | *****************************************************************************/
16 | #include "crc.h" /* include the header file generated with pycrc */
17 | #include
18 | #include
19 |
20 | /**
21 | * Static table used for the table_driven implementation.
22 | *****************************************************************************/
23 | static const crc_t crc_table[16] = {
24 | 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d
25 | };
26 |
27 | /**
28 | * Update the crc value with new data.
29 | *
30 | * \param crc The current crc value.
31 | * \param data Pointer to a buffer of \a data_len bytes.
32 | * \param data_len Number of bytes in the \a data buffer.
33 | * \return The updated crc value.
34 | *****************************************************************************/
35 | crc_t crc_update(crc_t crc, const void *data, size_t data_len)
36 | {
37 | const unsigned char *d = (const unsigned char *)data;
38 | unsigned int tbl_idx;
39 |
40 | while (data_len--) {
41 | tbl_idx = (crc >> 4) ^ (*d >> 4);
42 | crc = crc_table[tbl_idx & 0x0f] ^ (crc << 4);
43 | tbl_idx = (crc >> 4) ^ (*d >> 0);
44 | crc = crc_table[tbl_idx & 0x0f] ^ (crc << 4);
45 |
46 | d++;
47 | }
48 | return crc & 0xff;
49 | }
50 |
51 |
52 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/crc.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \file crc.h
3 | * Functions and types for CRC checks.
4 | *
5 | * Generated on Mon Jul 18 07:08:22 2016,
6 | * by pycrc v0.9, https://pycrc.org
7 | * using the configuration:
8 | * Width = 8
9 | * Poly = 0x07
10 | * Xor_In = 0x00
11 | * ReflectIn = False
12 | * Xor_Out = 0x00
13 | * ReflectOut = False
14 | * Algorithm = table-driven
15 | *****************************************************************************/
16 | #ifndef __CRC_H__
17 | #define __CRC_H__
18 |
19 | #include
20 | #include
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif
25 |
26 |
27 | /**
28 | * The definition of the used algorithm.
29 | *
30 | * This is not used anywhere in the generated code, but it may be used by the
31 | * application code to call algoritm-specific code, is desired.
32 | *****************************************************************************/
33 | #define CRC_ALGO_TABLE_DRIVEN 1
34 |
35 |
36 | /**
37 | * The type of the CRC values.
38 | *
39 | * This type must be big enough to contain at least 8 bits.
40 | *****************************************************************************/
41 | typedef uint_fast8_t crc_t;
42 |
43 |
44 | /**
45 | * Calculate the initial crc value.
46 | *
47 | * \return The initial crc value.
48 | *****************************************************************************/
49 | static inline crc_t crc_init(void)
50 | {
51 | return 0x00;
52 | }
53 |
54 |
55 | /**
56 | * Update the crc value with new data.
57 | *
58 | * \param crc The current crc value.
59 | * \param data Pointer to a buffer of \a data_len bytes.
60 | * \param data_len Number of bytes in the \a data buffer.
61 | * \return The updated crc value.
62 | *****************************************************************************/
63 | crc_t crc_update(crc_t crc, const void *data, size_t data_len);
64 |
65 |
66 | /**
67 | * Calculate the final crc value.
68 | *
69 | * \param crc The current crc value.
70 | * \return The final crc value.
71 | *****************************************************************************/
72 | static inline crc_t crc_finalize(crc_t crc)
73 | {
74 | return crc ^ 0x00;
75 | }
76 |
77 |
78 | #ifdef __cplusplus
79 | } /* closing brace for extern "C" */
80 | #endif
81 |
82 | #endif /* __CRC_H__ */
83 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/crypto_helper.cpp:
--------------------------------------------------------------------------------
1 | #include "crypto_helper.h"
2 |
3 | void init_SHA256(const uECC_HashContext *base) {
4 | SHA256_HashContext *context = (SHA256_HashContext *) base;
5 | sha256_init(&context->ctx);
6 | }
7 |
8 | void update_SHA256(const uECC_HashContext *base, const uint8_t *message, unsigned message_size) {
9 | SHA256_HashContext *context = (SHA256_HashContext *) base;
10 | sha256_add(&context->ctx, message, message_size);
11 | }
12 |
13 | void finish_SHA256(const uECC_HashContext *base, uint8_t *hash_result) {
14 | SHA256_HashContext *context = (SHA256_HashContext *) base;
15 | //SHA256_Final(hash_result, &context->ctx);
16 | sha256_digest(&context->ctx, hash_result);
17 | }
18 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/crypto_helper.h:
--------------------------------------------------------------------------------
1 | #ifndef CRYPTO_HELPER_H
2 | #define CRYPTO_HELPER_H
3 |
4 | #include
5 | #include
6 |
7 | ////////////////////////////////////////////////////
8 | typedef struct SHA256_HashContext {
9 | uECC_HashContext uECC;
10 | ShaOBJ ctx;
11 | } SHA256_HashContext;
12 |
13 | void init_SHA256(const uECC_HashContext *base);
14 |
15 | void update_SHA256(const uECC_HashContext *base, const uint8_t *message, unsigned message_size);
16 |
17 | void finish_SHA256(const uECC_HashContext *base, uint8_t *hash_result);
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/dcdarknet_app.h:
--------------------------------------------------------------------------------
1 | #ifndef _DCDARKNET_APP_H
2 | #define _DCDARKNET_APP_H
3 |
4 | #include "error_type.h"
5 |
6 | class StateBase;
7 |
8 | class DCDarkNetApp {
9 | public:
10 | enum COMPONENTS_ITEMS {
11 | LCD = (1<<0),
12 | RADIO = (1<<1),
13 | IR = (1<<2),
14 | FLASH_MEM = (1<<3)
15 | };
16 | static const uint8_t AGENT_NETWORK = 1;
17 | static const uint8_t GATEWAY_NETWORK = 200;
18 | static const uint16_t GATEWAY_RADIO_ID = 0xFFFE;
19 | public:
20 | DCDarkNetApp();
21 | uint32_t init();
22 | void run();
23 | private:
24 | StateBase *CurrentState;
25 | };
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/error_type.cpp:
--------------------------------------------------------------------------------
1 | #include "error_type.h"
2 |
3 | ErrorType::ErrorType() : ErrorNumber(ErrorNum::NO_ERROR) {
4 | }
5 |
6 | ErrorType::ErrorType(ErrorNum en) : ErrorNumber(en) {
7 | }
8 |
9 | bool ErrorType::ok() {
10 | return ErrorNumber==ErrorNum::NO_ERROR;
11 | }
12 |
13 |
14 | const char *ErrorType::getMessage() {
15 | return "ErrorType: TODO";
16 | }
17 |
18 | ErrorType::ErrorType(const ErrorType &r) {
19 | (*this)=r;
20 | }
21 |
22 | ErrorType &ErrorType::operator=(const ErrorType &r) {
23 | ErrorNumber = r.ErrorNumber;
24 | return (*this);
25 | }
26 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/error_type.h:
--------------------------------------------------------------------------------
1 | #ifndef ERROR_TYPE_H
2 | #define ERROR_TYPE_H
3 |
4 | #include "stdint.h"
5 |
6 | class ErrorType {
7 | public:
8 | enum ErrorNum {
9 | NO_ERROR = 0,
10 | SPI_INIT_ERROR
11 | };
12 | public:
13 | ErrorType();
14 | ErrorType(ErrorNum en);
15 | ErrorType(const ErrorType &r);
16 | bool ok();
17 | ErrorType &operator=(const ErrorType &r);
18 | uint8_t getError() {return ErrorNumber;}
19 | const char *getMessage();
20 | private:
21 | ErrorNum ErrorNumber;
22 | };
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/fonts.h:
--------------------------------------------------------------------------------
1 | /**
2 | * original author: Tilen Majerle
3 | * modification for STM32f10x: Alexander Lutsai
4 | ----------------------------------------------------------------------
5 | Copyright (C) Alexander Lutsai, 2016
6 | Copyright (C) Tilen Majerle, 2015
7 |
8 | This program is free software: you can redistribute it and/or modify
9 | it under the terms of the GNU General Public License as published by
10 | the Free Software Foundation, either version 3 of the License, or
11 | any later version.
12 |
13 | This program is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with this program. If not, see .
20 | ----------------------------------------------------------------------
21 | */
22 | #ifndef FONTS_H
23 | #define FONTS_H 120
24 |
25 | /* C++ detection */
26 | //#ifdef __cplusplus
27 | //extern C {
28 | //#endif
29 |
30 | /**
31 | *
32 | * Default fonts library. It is used in all LCD based libraries.
33 | *
34 | * \par Supported fonts
35 | *
36 | * Currently, these fonts are supported:
37 | * - 7 x 10 pixels
38 | * - 11 x 18 pixels
39 | * - 16 x 26 pixels
40 | */
41 | #include
42 | #include "string.h"
43 |
44 | /**
45 | * @defgroup LIB_Typedefs
46 | * @brief Library Typedefs
47 | * @{
48 | */
49 |
50 | /**
51 | * @brief Font structure used on my LCD libraries
52 | */
53 | typedef struct {
54 | uint8_t FontWidth; /*!< Font width in pixels */
55 | uint8_t FontHeight; /*!< Font height in pixels */
56 | uint8_t CharBytes; /*!< Count of bytes for one character */
57 | const uint8_t *data; /*!< Pointer to data font data array */
58 | } FontDef_t;
59 |
60 | /**
61 | * @brief String length and height
62 | */
63 | typedef struct {
64 | uint16_t Length; /*!< String length in units of pixels */
65 | uint16_t Height; /*!< String height in units of pixels */
66 | } FONTS_SIZE_t;
67 |
68 | /**
69 | * @}
70 | */
71 |
72 | /**
73 | * @defgroup FONTS_FontVariables
74 | * @brief Library font variables
75 | * @{
76 | */
77 |
78 | extern FontDef_t Font_6x10;
79 |
80 |
81 | /**
82 | * @}
83 | */
84 |
85 | /**
86 | * @defgroup FONTS_Functions
87 | * @brief Library functions
88 | * @{
89 | */
90 |
91 | /**
92 | * @brief Calculates string length and height in units of pixels depending on string and font used
93 | * @param *str: String to be checked for length and height
94 | * @param *SizeStruct: Pointer to empty @ref FONTS_SIZE_t structure where informations will be saved
95 | * @param *Font: Pointer to @ref FontDef_t font used for calculations
96 | * @retval Pointer to string used for length and height
97 | */
98 | char* FONTS_GetStringSize(char* str, FONTS_SIZE_t* SizeStruct, FontDef_t* Font);
99 |
100 | /**
101 | * @}
102 | */
103 |
104 | /**
105 | * @}
106 | */
107 |
108 | /**
109 | * @}
110 | */
111 |
112 | /* C++ detection */
113 | //#ifdef __cplusplus
114 | //}
115 | //#endif
116 |
117 |
118 | #endif
119 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/gateway.cpp:
--------------------------------------------------------------------------------
1 | #include "gateway.h"
2 |
3 | #include "Radio/RFM69.h"
4 | #include "dcdarknet_app.h"
5 |
6 | Gateway::Gateway() :
7 | InternalState(REQUEST_REP), Counter(0) {
8 |
9 | }
10 |
11 | Gateway::~Gateway() {
12 |
13 | }
14 |
15 | ErrorType Gateway::onInit(RunContext &rc) {
16 | InternalState = REQUEST_REP;
17 | rc.getDisplay().fillScreen(RGBColor::BLACK);
18 | return ErrorType();
19 | }
20 |
21 | struct GatewayRepMessage {
22 | const uint8_t MessageID;
23 | uint16_t RadioID;
24 | char AgentName[ContactStore::AGENT_NAME_LENGTH];
25 | GatewayRepMessage() :
26 | MessageID(Gateway::REQUEST_REP_MSG), RadioID(0), AgentName() {
27 | }
28 | }__attribute__((packed));
29 |
30 | struct IntGatewayResponse {
31 | const uint8_t MessageID;
32 | uint8_t Success;
33 | int32_t Result;
34 | IntGatewayResponse() :
35 | MessageID(0), Success(false), Result(0) {
36 | }
37 | }__attribute__((packed));
38 |
39 | ReturnStateContext Gateway::onRun(RunContext &rc) {
40 | StateBase *nextState = this;
41 | switch (InternalState) {
42 | case REQUEST_REP: {
43 | rc.getRadio().setNetwork(DCDarkNetApp::GATEWAY_NETWORK);
44 | GatewayRepMessage grm;
45 | grm.RadioID = rc.getContactStore().getMyInfo().getUniqueID();
46 | strcpy(&grm.AgentName[0], rc.getContactStore().getSettings().getAgentName());
47 | //rc.getRadio().send(DCDarkNetApp::GATEWAY_RADIO_ID, &grm, sizeof(grm), true);
48 | rc.getDisplay().drawString(2, 10, "Request sent \nto Gateway.", RGBColor::WHITE, RGBColor::BLACK, 1, true);
49 | rc.getDisplay().drawString(2, 40, "Waiting for ack\n from Gateway.", RGBColor::WHITE, RGBColor::BLACK, 1, true);
50 | if (rc.getRadio().sendWithRetry(DCDarkNetApp::GATEWAY_RADIO_ID, &grm, sizeof(grm), 3, 40)) {
51 | InternalState = RECEIVING;
52 | } else {
53 | nextState = StateFactory::getDisplayMessageState(StateFactory::getMenuState(), "No response from Gateway",
54 | 3000);
55 | }
56 |
57 | }
58 | break;
59 | case RECEIVING: {
60 | if (rc.getRadio().receiveDone()) {
61 | if (rc.getRadio().DATALEN == sizeof(IntGatewayResponse)
62 | && rc.getRadio().SENDERID == DCDarkNetApp::GATEWAY_RADIO_ID) {
63 | IntGatewayResponse *grrm = (IntGatewayResponse *) &rc.getRadio().DATA[0];
64 | char buf[48];
65 | sprintf(&buf[0], "You have %d reputation points", grrm->Result);
66 | rc.getDisplay().fillScreen(RGBColor::BLUE);
67 | rc.getDisplay().drawString(2, 30, &buf[0], RGBColor::BLACK, RGBColor::BLUE, 2, true);
68 | Counter = getTimesRunCalledSinceLastReset() + 100;
69 | InternalState = FINISHING;
70 | }
71 | } else if (this->getTimesRunCalledSinceLastReset() > 10000) {
72 | nextState = StateFactory::getDisplayMessageState(StateFactory::getMenuState(), "No response from Gateway",
73 | 3000);
74 | }
75 | }
76 | break;
77 | case FINISHING: {
78 | if (Counter < getTimesRunCalledSinceLastReset()) {
79 | nextState = StateFactory::getMenuState();
80 | }
81 | }
82 | break;
83 | }
84 | if (rc.getKB().wasKeyReleased()) {
85 | nextState = StateFactory::getMenuState();
86 | }
87 | if (nextState != this) {
88 | rc.getRadio().setNetwork(DCDarkNetApp::AGENT_NETWORK);
89 | }
90 | return ReturnStateContext(nextState);
91 | }
92 |
93 | ErrorType Gateway::onShutdown() {
94 | return ErrorType();
95 | }
96 |
97 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/gateway.h:
--------------------------------------------------------------------------------
1 | #ifndef DC_DARKNET_GATEWAY_H
2 | #define DC_DARKNET_GATEWAY_H
3 |
4 | #include "menus.h"
5 |
6 | class Gateway: public StateBase {
7 | public:
8 | Gateway();
9 | virtual ~Gateway();
10 | static const uint8_t REQUEST_REP_MSG = 1;
11 | static const uint8_t INT_REPONSE_MSG = 2;
12 | protected:
13 | enum INTERNAL_STATE {
14 | REQUEST_REP,
15 | WAITING_FOR_REQUEST_ACK,
16 | RECEIVING,
17 | FINISHING
18 | };
19 | virtual ErrorType onInit(RunContext &rc);
20 | virtual ReturnStateContext onRun(RunContext &rc);
21 | virtual ErrorType onShutdown();
22 | private:
23 | INTERNAL_STATE InternalState;
24 | uint32_t Counter;
25 | };
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/gui.h:
--------------------------------------------------------------------------------
1 | #ifndef GUI_H
2 | #define GUI_H
3 |
4 | #include
5 | #include "display_device.h"
6 | #include "fonts.h"
7 |
8 |
9 | //running line
10 | #define GUI_TickerSpeed 500
11 | #define GUI_TickerEndDelay 3
12 | class GUI_TickerData {
13 | public:
14 | GUI_TickerData(const char * txt, uint8_t X, uint8_t Y, uint8_t W, uint8_t H);
15 | const char *text;
16 | uint8_t x, y, w, h, BorderSize, FontScalar;
17 | RGBColor bg, TextColor;
18 | uint32_t startTick;
19 | };
20 |
21 | class GUI_ListItemData {
22 | public:
23 | GUI_ListItemData(uint8_t id1, const char *msg, bool scroll, uint16_t timeBetwenScrolls) :
24 | id(id1), text(msg), Scrollable(scroll), TimeBetweenScroll(timeBetwenScrolls), LastScrollTime(0), LastScrollPosition(
25 | 0) {
26 |
27 | }
28 | GUI_ListItemData(uint8_t id, const char *msg) :
29 | Scrollable(0), TimeBetweenScroll(1000), LastScrollTime(0), LastScrollPosition(0) {
30 | this->id = id;
31 | text = msg;
32 | }
33 | GUI_ListItemData() :
34 | id(0), text(0), Scrollable(0), TimeBetweenScroll(1000), LastScrollTime(0), LastScrollPosition(0) {
35 | }
36 | void set(uint8_t n, const char *msg) {
37 | id = n;
38 | text = msg;
39 | }
40 | uint16_t id; /*!< Item's id */
41 | const char* text; /*!< Item's text*/
42 | uint16_t Scrollable :1;
43 | uint16_t TimeBetweenScroll :12;
44 | uint32_t LastScrollTime;
45 | uint8_t LastScrollPosition;
46 | const char *getScrollOffset();
47 | void setShouldScroll();
48 | bool shouldScroll();
49 | void resetScrollable() {
50 | Scrollable = 1;
51 | LastScrollTime = 0;
52 | LastScrollPosition = 0;
53 | }
54 | };
55 |
56 | class GUI_ListData {
57 | public:
58 | GUI_ListData(const char *h, GUI_ListItemData *is, uint8_t x, uint8_t y, uint8_t w, uint8_t height, uint8_t si,
59 | uint8_t ic) {
60 | header = h;
61 | items = is;
62 | this->x = x;
63 | this->y = y;
64 | this->w = w;
65 | this->h = height;
66 | selectedItem = si;
67 | ItemsCount = ic;
68 | }
69 | const char* header; /*!< Header*/
70 | GUI_ListItemData *items; /*!< Item's array*/
71 | uint16_t ItemsCount; /*!< Item's array*/
72 | uint8_t x, y, w, h;
73 | uint16_t selectedItem;
74 | };
75 |
76 | class GUI {
77 | public:
78 | GUI(DisplayST7735 *display);
79 | bool init();
80 | void drawTicker(GUI_TickerData *dt);
81 | uint8_t drawList(GUI_ListData* list) const;
82 |
83 | private:
84 | DisplayST7735 *Display;
85 | };
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/images/images.h:
--------------------------------------------------------------------------------
1 | #ifndef DCDARKNET_IMAGES_H
2 | #define DCDARKNET_IMAGES_H
3 |
4 | struct DCImage {
5 | unsigned int width;
6 | unsigned int height;
7 | unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
8 | const char *pixel_data;
9 | };
10 |
11 | const DCImage &getCyberez();
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/ir.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __IR_H__
3 | #define __IR_H__
4 |
5 | #ifdef __cplusplus
6 | extern "C" {
7 | #else
8 | #include
9 | #endif
10 |
11 |
12 | void IRInit(void);
13 | void IRStop();
14 | void IRTxBuff(uint8_t *buff, size_t len);
15 | int32_t IRRxBlocking(uint32_t timeout_ms);
16 |
17 | int32_t IRBytesAvailable();
18 | uint8_t *IRGetBuff();
19 | bool IRDataReady();
20 | void IRStartRx();
21 | void IRStopRX();
22 | //int32_t IRGetState();
23 |
24 | #ifdef __cplusplus
25 | }
26 | #endif
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/irmenu.h:
--------------------------------------------------------------------------------
1 | #ifndef IRMENU_H_
2 | #define IRMENU_H
3 |
4 | #include "menus.h"
5 |
6 | class IRState: public StateBase {
7 | public:
8 | struct AliceInitConvo {
9 | uint8_t irmsgid;
10 | uint8_t AlicePublicKey[ContactStore::PUBLIC_KEY_COMPRESSED_LENGTH];
11 | uint16_t AliceRadioID;
12 | char AliceName[ContactStore::AGENT_NAME_LENGTH];
13 | };
14 |
15 | struct BobReplyToInit {
16 | uint8_t irmsgid;
17 | uint8_t BoBPublicKey[ContactStore::PUBLIC_KEY_COMPRESSED_LENGTH];
18 | uint16_t BoBRadioID;
19 | char BobAgentName[ContactStore::AGENT_NAME_LENGTH];
20 | uint8_t SignatureOfAliceData[ContactStore::SIGNATURE_LENGTH];
21 | };
22 |
23 | struct AliceToBobSignature {
24 | uint8_t irmsgid;
25 | uint8_t signature[48];
26 | };
27 | public:
28 | IRState(uint16_t timeOutMS, uint16_t RetryCount);
29 | virtual ~IRState();
30 | void ListenForAlice(RunContext &rc);
31 | void BeTheBob();
32 | protected:
33 | virtual ErrorType onInit(RunContext &rc);
34 | virtual ReturnStateContext onRun(RunContext &rc);
35 | virtual ErrorType onShutdown();
36 | private:
37 | uint16_t TimeoutMS;
38 | uint8_t RetryCount;
39 | uint8_t CurrentRetryCount;
40 | uint32_t TimeInState;
41 | AliceInitConvo AIC;
42 | BobReplyToInit BRTI;
43 | AliceToBobSignature ATBS;
44 | uint16_t TransmitInternalState;
45 | uint16_t ReceiveInternalState;
46 | };
47 |
48 | #endif
49 |
50 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/leddc25.h:
--------------------------------------------------------------------------------
1 | #ifndef LEDDC25_H
2 | #define LEDDC25_H
3 |
4 | /*
5 | * @author cmdc0de
6 | * @date 6/12/2017
7 | *
8 | * Class to encapsulate controlling of LEDS on DC25 darknet badge
9 | */
10 | class LedDC25 {
11 | public:
12 | struct PinConfig {
13 | uint16_t Pin;
14 | GPIO_TypeDef *Port;
15 | PinConfig() :
16 | Pin(0), Port(0) {
17 | }
18 | PinConfig(uint16_t pin, GPIO_TypeDef *port) :
19 | Pin(pin), Port(port) {
20 | }
21 | };
22 | public:
23 | enum LED_ID {
24 | LED_STATUS = (1 << 0)
25 | , LED_STATUS_OFFSET = 0
26 | , LED_1 = (1 << 1)
27 | , LED_1_OFFSET = 1
28 | , LED_2 = (1 << 2)
29 | , LED_2_OFFSET = 2
30 | , LED_3 = (1 << 3)
31 | , LED_3_OFFSET = 3
32 | , LED_4 = (1 << 4)
33 | , LED_4_OFFSET = 4
34 | , LED_5 = (1 << 5)
35 | , LED_5_OFFSET = 5
36 | , LED_6 = (1 << 6)
37 | , LED_6_OFFSET = 6
38 | , LED_7 = (1 << 7)
39 | , LED_7_OFFSET = 7
40 | , LED_8 = (1 << 8)
41 | , LED_8_OFFSET = 8
42 | , LED_9 = (1 << 9)
43 | , LED_9_OFFSET = 9
44 | , LED_0 = (1 << 10)
45 | , LED_0_OFFSET = 10
46 | , ALL = LED_STATUS | LED_1 | LED_2 | LED_3 | LED_4 | LED_5 | LED_6 | LED_7 | LED_8 | LED_9 | LED_0
47 | , LED_COUNT = 11
48 | };
49 | enum LED_DANCE_TYPE {
50 | NONE = 0
51 | , DIALER = 1
52 | , RANDOM = 2
53 | , INIT = 3
54 | , CLOCK_WISE_CIRCLE = 4
55 | , COUNTER_CLOCK_WISE_CIRCLE=5
56 | , TOTAL_DANCE_TYPES = 6
57 | };
58 | public:
59 | LedDC25();
60 | ~LedDC25();
61 | void setAllOn();
62 | void setAllOff();
63 | void setLedOn(LED_ID ledid);
64 | void setLedOff(LED_ID ledid);
65 | bool isLedOn(LED_ID ledid);
66 | void setDanceType(LED_DANCE_TYPE t);
67 | void setDanceType(LED_DANCE_TYPE t, uint8_t data);
68 | void process();
69 | protected:
70 | void setInternalLedOn(uint32_t t);
71 | void SetInternalLedOff(uint32_t t);
72 | private:
73 | uint16_t LedState;
74 | uint8_t DanceType;
75 | uint8_t DanceTypeData;
76 | static const PinConfig PC[LED_COUNT];
77 | uint32_t lastBlinkTime;
78 | uint32_t lastDialerTime;
79 | uint8_t DialerData;
80 | int8_t Counter;
81 |
82 | };
83 |
84 | #endif
85 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/logger.cpp:
--------------------------------------------------------------------------------
1 | #include "logger.h"
2 | #include
3 | #include
4 |
5 | using darknet::LogManager;
6 | using darknet::Logger;
7 | using darknet::LOG_LEVEL;
8 |
9 | LogManager *LogManager::mSelf = 0;
10 |
11 | LogManager &LogManager::get() {
12 | if(0==mSelf) {
13 | mSelf = new LogManager();
14 | trace_initialize();
15 | }
16 | return *mSelf;
17 | }
18 |
19 | LogManager::LogManager() : CurrentLogLevel(LOG_LEVEL::LOG_NO_LEVEL){
20 |
21 | }
22 |
23 | void LogManager::setLogLevel(LOG_LEVEL l) {
24 | CurrentLogLevel = l;
25 | }
26 |
27 | LOG_LEVEL LogManager::getLogLevel() const {
28 | return CurrentLogLevel;
29 | }
30 |
31 | static Logger *Loggers[darknet::NUMBER_OF_LOGGERS] = {0};
32 |
33 | void LogManager::addLogger(uint32_t id, Logger *l) {
34 | if(id=darknet::NUMBER_OF_LOGGERS) return 0;
40 | return Loggers[id];
41 | }
42 |
43 | ////////////////////////////////////////
44 |
45 | Logger::Logger(LOG_LEVEL l) : CurrentLogLevel(l) {
46 |
47 | }
48 |
49 | const LOG_LEVEL &Logger::getLogLevel() {
50 | return CurrentLogLevel;
51 | }
52 |
53 | void Logger::printf(const LogManager &lm, const char *format,...) {
54 | if(lm.getLogLevel()<=getLogLevel()) {
55 | va_list ap;
56 | va_start (ap, format);
57 | static char buf[64];
58 | int ret = vsnprintf (buf, sizeof(buf), format, ap);
59 | if(ret>0) {
60 | onPrintf(buf,(uint16_t)ret);
61 | }
62 | va_end (ap);
63 | }
64 | }
65 |
66 |
67 | Logger::~Logger() {
68 |
69 | }
70 |
71 |
72 |
73 | darknet::STM32Logger::STM32Logger(LOG_LEVEL l) : Logger(l) {
74 |
75 | }
76 |
77 | void darknet::STM32Logger::onPrintf(const char *msg, uint16_t size) {
78 | trace_write (msg, (unsigned int)size);
79 | }
80 |
--------------------------------------------------------------------------------
/software/firmware/src/badge/logger.h:
--------------------------------------------------------------------------------
1 | #ifndef DCDARK_LOGGER_H
2 | #define DCDARK_LOGGER_H
3 |
4 | #include
5 | #include
6 |
7 | namespace darknet {
8 | class Logger;
9 | static const uint32_t DEBUG_LOGGER_ID = 0;
10 | static const uint32_t INFO_LOGGER_ID = 1;
11 | static const uint32_t ERROR_LOGGER_ID = 2;
12 | static const uint32_t NUMBER_OF_LOGGERS = 3;
13 |
14 | enum LOG_LEVEL {
15 | LOG_DEBUG_LEVEL = 0
16 | , LOG_INFO_LEVEL = 1
17 | , LOG_ERROR_LEVEL = 2
18 | , LOG_NO_LEVEL = 3
19 | };
20 | class LogManager {
21 | public:
22 | void setLogLevel(LOG_LEVEL l);
23 | LOG_LEVEL getLogLevel() const;
24 | Logger *getLogger(const uint32_t &logID);
25 | void addLogger(uint32_t id, Logger *l);
26 | public:
27 | static LogManager &get();
28 | protected:
29 | LogManager();
30 | private:
31 | static LogManager *mSelf;
32 | LOG_LEVEL CurrentLogLevel;
33 | };
34 | class Logger {
35 | public:
36 | Logger(LOG_LEVEL l);
37 | const LOG_LEVEL &getLogLevel();
38 | void printf(const LogManager &lm, const char *format,...);
39 | virtual ~Logger();
40 | protected:
41 | virtual void onPrintf(const char *msg, uint16_t size)=0;
42 | private:
43 | LOG_LEVEL CurrentLogLevel;
44 | };
45 | class STM32Logger : public darknet::Logger {
46 | public:
47 | STM32Logger(LOG_LEVEL l);
48 | protected:
49 | virtual void onPrintf(const char *msg, uint16_t size);
50 | };
51 | }
52 |
53 | #define DBGMSG(...) if(LogManager::get().getLogger(darknet::DEBUG_LOGGER_ID)) \
54 | darknet::LogManager::get().getLogger(darknet::DEBUG_LOGGER_ID)->printf(darknet::LogManager::get(),##__VA_ARGS__)
55 | #define INFOMSG(...) if(darknet::LogManager::get().getLogger(darknet::INFO_LOGGER_ID)) \
56 | darknet::LogManager::get().getLogger(darknet::INFO_LOGGER_ID)->printf(darknet::LogManager::get(),##__VA_ARGS__)
57 | #define ERRMSG(...) if(darknet::LogManager::get().getLogger(darknet::ERROR_LOGGER_ID)) \
58 | darknet::LogManager::get().getLogger(darknet::ERROR_LOGGER_ID)->printf(darknet::LogManager::get(),##__VA_ARGS__)
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/software/firmware/src/crypto/micro-ecc/.gitignore:
--------------------------------------------------------------------------------
1 | __build__/
2 | __pycache__
3 | *.pyc
4 | *.pyo
5 | *.pyd
6 | *.pyz
7 | *.egg-info/
8 | .DS_Store
--------------------------------------------------------------------------------
/software/firmware/src/crypto/micro-ecc/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, Kenneth MacKay
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright notice, this
7 | list of conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright notice,
9 | this list of conditions and the following disclaimer in the documentation
10 | and/or other materials provided with the distribution.
11 |
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 |
--------------------------------------------------------------------------------
/software/firmware/src/crypto/micro-ecc/README.md:
--------------------------------------------------------------------------------
1 | micro-ecc
2 | ==========
3 |
4 | A small and fast ECDH and ECDSA implementation for 8-bit, 32-bit, and 64-bit processors.
5 |
6 | The static version of micro-ecc (ie, where the curve was selected at compile-time) can be found in the "static" branch.
7 |
8 | Features
9 | --------
10 |
11 | * Resistant to known side-channel attacks.
12 | * Written in C, with optional GCC inline assembly for AVR, ARM and Thumb platforms.
13 | * Supports 8, 32, and 64-bit architectures.
14 | * Small code size.
15 | * No dynamic memory allocation.
16 | * Support for 5 standard curves: secp160r1, secp192r1, secp224r1, secp256r1, and secp256k1.
17 | * BSD 2-clause license.
18 |
19 | Usage Notes
20 | -----------
21 | ### Point Representation ###
22 | Compressed points are represented in the standard format as defined in http://www.secg.org/collateral/sec1_final.pdf; uncompressed points are represented in standard format, but without the `0x04` prefix. All functions except `uECC_compress()` only accept uncompressed points; use `uECC_compress()` and `uECC_decompress()` to convert between compressed and uncompressed point representations.
23 |
24 | Private keys are represented in the standard format.
25 |
26 | ### Using the Code ###
27 |
28 | I recommend just copying (or symlink) the uECC files into your project. Then just `#include "uECC.h"` to use the micro-ecc functions.
29 |
30 | For use with Arduino, you can just create a symlink to the `uECC` directory in your Arduino `libraries` directory. You can then use uECC just like any other Arduino library (uECC should show up in the **Sketch**=>**Import Library** submenu).
31 |
32 | See uECC.h for documentation for each function.
33 |
34 | ### Compilation Notes ###
35 |
36 | * Should compile with any C/C++ compiler that supports stdint.h (this includes Visual Studio 2013).
37 | * If you want to change the defaults for any of the uECC compile-time options (such as `uECC_OPTIMIZATION_LEVEL`), you must change them in your Makefile or similar so that uECC.c is compiled with the desired values (ie, compile uECC.c with `-DuECC_OPTIMIZATION_LEVEL=3` or whatever).
38 | * When compiling for a Thumb-1 platform, you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher).
39 | * When compiling for an ARM/Thumb-2 platform with `uECC_OPTIMIZATION_LEVEL` >= 3, you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher).
40 | * When compiling for AVR, you must have optimizations enabled (compile with `-O1` or higher).
41 | * When building for Windows, you will need to link in the `advapi32.lib` system library.
42 |
--------------------------------------------------------------------------------
/software/firmware/src/crypto/micro-ecc/emk_rules.py:
--------------------------------------------------------------------------------
1 | c, link = emk.module("c", "link")
2 |
3 | emk.subdir("test")
4 |
--------------------------------------------------------------------------------
/software/firmware/src/crypto/micro-ecc/platform-specific.inc:
--------------------------------------------------------------------------------
1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2 |
3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_
4 | #define _UECC_PLATFORM_SPECIFIC_H_
5 |
6 | #include "types.h"
7 |
8 | #if (defined(_WIN32) || defined(_WIN64))
9 | /* Windows */
10 |
11 | #define WIN32_LEAN_AND_MEAN
12 | #include
13 | #include
14 |
15 | static int default_RNG(uint8_t *dest, unsigned size) {
16 | HCRYPTPROV prov;
17 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
18 | return 0;
19 | }
20 |
21 | CryptGenRandom(prov, size, (BYTE *)dest);
22 | CryptReleaseContext(prov, 0);
23 | return 1;
24 | }
25 | #define default_RNG_defined 1
26 |
27 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \
28 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX)
29 |
30 | /* Some POSIX-like system with /dev/urandom or /dev/random. */
31 | #include
32 | #include
33 | #include
34 |
35 | #ifndef O_CLOEXEC
36 | #define O_CLOEXEC 0
37 | #endif
38 |
39 | static int default_RNG(uint8_t *dest, unsigned size) {
40 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
41 | if (fd == -1) {
42 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC);
43 | if (fd == -1) {
44 | return 0;
45 | }
46 | }
47 |
48 | char *ptr = (char *)dest;
49 | size_t left = size;
50 | while (left > 0) {
51 | ssize_t bytes_read = read(fd, ptr, left);
52 | if (bytes_read <= 0) { // read failed
53 | close(fd);
54 | return 0;
55 | }
56 | left -= bytes_read;
57 | ptr += bytes_read;
58 | }
59 |
60 | close(fd);
61 | return 1;
62 | }
63 | #define default_RNG_defined 1
64 |
65 | #endif /* platform */
66 |
67 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */
68 |
--------------------------------------------------------------------------------
/software/firmware/src/crypto/micro-ecc/types.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2 |
3 | #ifndef _UECC_TYPES_H_
4 | #define _UECC_TYPES_H_
5 |
6 | #ifndef uECC_PLATFORM
7 | #if __AVR__
8 | #define uECC_PLATFORM uECC_avr
9 | #elif defined(__thumb2__) || defined(_M_ARMT) /* I think MSVC only supports Thumb-2 targets */
10 | #define uECC_PLATFORM uECC_arm_thumb2
11 | #elif defined(__thumb__)
12 | #define uECC_PLATFORM uECC_arm_thumb
13 | #elif defined(__arm__) || defined(_M_ARM)
14 | #define uECC_PLATFORM uECC_arm
15 | #elif defined(__aarch64__)
16 | #define uECC_PLATFORM uECC_arm64
17 | #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__)
18 | #define uECC_PLATFORM uECC_x86
19 | #elif defined(__amd64__) || defined(_M_X64)
20 | #define uECC_PLATFORM uECC_x86_64
21 | #else
22 | #define uECC_PLATFORM uECC_arch_other
23 | #endif
24 | #endif
25 |
26 | #ifndef uECC_ARM_USE_UMAAL
27 | #if (uECC_PLATFORM == uECC_arm) && (__ARM_ARCH >= 6)
28 | #define uECC_ARM_USE_UMAAL 1
29 | #elif (uECC_PLATFORM == uECC_arm_thumb2) && (__ARM_ARCH >= 6) && !__ARM_ARCH_7M__
30 | #define uECC_ARM_USE_UMAAL 1
31 | #else
32 | #define uECC_ARM_USE_UMAAL 0
33 | #endif
34 | #endif
35 |
36 | #ifndef uECC_WORD_SIZE
37 | #if uECC_PLATFORM == uECC_avr
38 | #define uECC_WORD_SIZE 1
39 | #elif (uECC_PLATFORM == uECC_x86_64 || uECC_PLATFORM == uECC_arm64)
40 | #define uECC_WORD_SIZE 8
41 | #else
42 | #define uECC_WORD_SIZE 4
43 | #endif
44 | #endif
45 |
46 | #if (uECC_WORD_SIZE != 1) && (uECC_WORD_SIZE != 4) && (uECC_WORD_SIZE != 8)
47 | #error "Unsupported value for uECC_WORD_SIZE"
48 | #endif
49 |
50 | #if ((uECC_PLATFORM == uECC_avr) && (uECC_WORD_SIZE != 1))
51 | #pragma message ("uECC_WORD_SIZE must be 1 for AVR")
52 | #undef uECC_WORD_SIZE
53 | #define uECC_WORD_SIZE 1
54 | #endif
55 |
56 | #if ((uECC_PLATFORM == uECC_arm || uECC_PLATFORM == uECC_arm_thumb || \
57 | uECC_PLATFORM == uECC_arm_thumb2) && \
58 | (uECC_WORD_SIZE != 4))
59 | #pragma message ("uECC_WORD_SIZE must be 4 for ARM")
60 | #undef uECC_WORD_SIZE
61 | #define uECC_WORD_SIZE 4
62 | #endif
63 |
64 | #if defined(__SIZEOF_INT128__) || ((__clang_major__ * 100 + __clang_minor__) >= 302)
65 | #define SUPPORTS_INT128 1
66 | #else
67 | #define SUPPORTS_INT128 0
68 | #endif
69 |
70 | typedef int8_t wordcount_t;
71 | typedef int16_t bitcount_t;
72 | typedef int8_t cmpresult_t;
73 |
74 | #if (uECC_WORD_SIZE == 1)
75 |
76 | typedef uint8_t uECC_word_t;
77 | typedef uint16_t uECC_dword_t;
78 |
79 | #define HIGH_BIT_SET 0x80
80 | #define uECC_WORD_BITS 8
81 | #define uECC_WORD_BITS_SHIFT 3
82 | #define uECC_WORD_BITS_MASK 0x07
83 |
84 | #elif (uECC_WORD_SIZE == 4)
85 |
86 | typedef uint32_t uECC_word_t;
87 | typedef uint64_t uECC_dword_t;
88 |
89 | #define HIGH_BIT_SET 0x80000000
90 | #define uECC_WORD_BITS 32
91 | #define uECC_WORD_BITS_SHIFT 5
92 | #define uECC_WORD_BITS_MASK 0x01F
93 |
94 | #elif (uECC_WORD_SIZE == 8)
95 |
96 | typedef uint64_t uECC_word_t;
97 | #if SUPPORTS_INT128
98 | typedef unsigned __int128 uECC_dword_t;
99 | #endif
100 |
101 | #define HIGH_BIT_SET 0x8000000000000000ull
102 | #define uECC_WORD_BITS 64
103 | #define uECC_WORD_BITS_SHIFT 6
104 | #define uECC_WORD_BITS_MASK 0x03F
105 |
106 | #endif /* uECC_WORD_SIZE */
107 |
108 | #endif /* _UECC_TYPES_H_ */
109 |
--------------------------------------------------------------------------------
/software/firmware/src/crypto/sha256.h:
--------------------------------------------------------------------------------
1 | #ifndef SHA256_H
2 | #define SHA256_H
3 |
4 |
5 | #define uchar unsigned char
6 |
7 | #define uint_64 long long unsigned int
8 |
9 | #define uint32 unsigned long
10 |
11 | static const uint32 SHA256_HASH_SIZE = 32;
12 |
13 | struct ShaOBJ {
14 | uint32 state[8];
15 | uint_64 bit_len;
16 | uchar data[64];
17 | uint32 data_len;
18 | };
19 |
20 | void sha256_init(ShaOBJ *ctx);
21 | void sha256_update(ShaOBJ* ctx);
22 | void sha256_add(ShaOBJ* ctx, const unsigned char* msg, uint32 len);
23 | void sha256_digest(ShaOBJ* ctx, unsigned char hash[SHA256_HASH_SIZE]);
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/software/firmware/system/include/cmsis/README_DEVICE_30x.txt:
--------------------------------------------------------------------------------
1 | The stm32f30x.h and system_stm32f30x.h files are from stsw-stm32108.zip,
2 | the folder:
3 |
4 | STM32F30x_DSP_StdPeriph_Lib_V1.0.0/Libraries/CMSIS/Device/ST/STM32F30x/Include
5 |
6 | The cmsis_device.h is added for convenience.
7 |
8 |
--------------------------------------------------------------------------------
/software/firmware/system/include/cmsis/cmsis_device.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | #ifndef STM32F3_CMSIS_DEVICE_H_
7 | #define STM32F3_CMSIS_DEVICE_H_
8 |
9 | #if defined(STM32F30X)
10 | #include "stm32f3xx.h"
11 | #elif defined(STM32F37X)
12 | #include "stm32f3xx.h"
13 | #else
14 | #error "No CMSIS header file"
15 | #endif
16 |
17 | #endif // STM32F3_CMSIS_DEVICE_H_
18 |
--------------------------------------------------------------------------------
/software/firmware/system/include/cmsis/device/stm32f302xc.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware/system/include/cmsis/device/stm32f302xc.h
--------------------------------------------------------------------------------
/software/firmware/system/include/cmsis/device/stm32f3xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/firmware/system/include/cmsis/device/stm32f3xx.h
--------------------------------------------------------------------------------
/software/firmware/system/include/cortexm/ExceptionHandlers.h:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | #ifndef CORTEXM_EXCEPTION_HANDLERS_H_
7 | #define CORTEXM_EXCEPTION_HANDLERS_H_
8 |
9 | #include
10 |
11 | #if defined(DEBUG)
12 | #define __DEBUG_BKPT() asm volatile ("bkpt 0")
13 | #endif
14 |
15 | // ----------------------------------------------------------------------------
16 |
17 | #if defined(__cplusplus)
18 | extern "C"
19 | {
20 | #endif
21 |
22 | // External references to cortexm_handlers.c
23 |
24 | extern void
25 | Reset_Handler (void);
26 | extern void
27 | NMI_Handler (void);
28 | extern void
29 | HardFault_Handler (void);
30 |
31 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
32 | extern void
33 | MemManage_Handler (void);
34 | extern void
35 | BusFault_Handler (void);
36 | extern void
37 | UsageFault_Handler (void);
38 | extern void
39 | DebugMon_Handler (void);
40 | #endif
41 |
42 | extern void
43 | SVC_Handler (void);
44 |
45 | extern void
46 | PendSV_Handler (void);
47 | extern void
48 | SysTick_Handler (void);
49 |
50 | // Exception Stack Frame of the Cortex-M3 or Cortex-M4 processor.
51 | typedef struct
52 | {
53 | uint32_t r0;
54 | uint32_t r1;
55 | uint32_t r2;
56 | uint32_t r3;
57 | uint32_t r12;
58 | uint32_t lr;
59 | uint32_t pc;
60 | uint32_t psr;
61 | #if defined(__ARM_ARCH_7EM__)
62 | uint32_t s[16];
63 | #endif
64 | } ExceptionStackFrame;
65 |
66 | #if defined(TRACE)
67 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
68 | void
69 | dumpExceptionStack (ExceptionStackFrame* frame, uint32_t cfsr, uint32_t mmfar,
70 | uint32_t bfar, uint32_t lr);
71 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
72 | #if defined(__ARM_ARCH_6M__)
73 | void
74 | dumpExceptionStack (ExceptionStackFrame* frame, uint32_t lr);
75 | #endif // defined(__ARM_ARCH_6M__)
76 | #endif // defined(TRACE)
77 |
78 | void
79 | HardFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr);
80 |
81 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
82 | void
83 | UsageFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr);
84 | void
85 | BusFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr);
86 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
87 |
88 | #if defined(__cplusplus)
89 | }
90 | #endif
91 |
92 | // ----------------------------------------------------------------------------
93 |
94 | #endif // CORTEXM_EXCEPTION_HANDLERS_H_
95 |
--------------------------------------------------------------------------------
/software/firmware/system/src/cortexm/_initialize_hardware.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include "cmsis_device.h"
9 |
10 | // ----------------------------------------------------------------------------
11 |
12 | extern unsigned int __vectors_start;
13 |
14 | // Forward declarations.
15 |
16 | void
17 | __initialize_hardware_early(void);
18 |
19 | void
20 | __initialize_hardware(void);
21 |
22 | // ----------------------------------------------------------------------------
23 |
24 | // This is the early hardware initialisation routine, it can be
25 | // redefined in the application for more complex cases that
26 | // require early inits (before BSS init).
27 | //
28 | // Called early from _start(), right before data & bss init.
29 | //
30 | // After Reset the Cortex-M processor is in Thread mode,
31 | // priority is Privileged, and the Stack is set to Main.
32 |
33 | void
34 | __attribute__((weak))
35 | __initialize_hardware_early(void)
36 | {
37 | // Call the CSMSIS system initialisation routine.
38 | SystemInit();
39 |
40 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
41 | // Set VTOR to the actual address, provided by the linker script.
42 | // Override the manual, possibly wrong, SystemInit() setting.
43 | SCB->VTOR = (uint32_t)(&__vectors_start);
44 | #endif
45 |
46 | // The current version of SystemInit() leaves the value of the clock
47 | // in a RAM variable (SystemCoreClock), which will be cleared shortly,
48 | // so it needs to be recomputed after the RAM initialisations
49 | // are completed.
50 |
51 | #if defined(OS_INCLUDE_STARTUP_INIT_FP) || (defined (__VFP_FP__) && !defined (__SOFTFP__))
52 |
53 | // Normally FP init is done by SystemInit(). In case this is not done
54 | // there, it is possible to force its inclusion by defining
55 | // OS_INCLUDE_STARTUP_INIT_FP.
56 |
57 | // Enable the Cortex-M4 FPU only when -mfloat-abi=hard.
58 | // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)
59 |
60 | // Set bits 20-23 to enable CP10 and CP11 coprocessor
61 | SCB->CPACR |= (0xF << 20);
62 |
63 | #endif // (__VFP_FP__) && !(__SOFTFP__)
64 |
65 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
66 | SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk;
67 | #endif
68 | }
69 |
70 | // This is the second hardware initialisation routine, it can be
71 | // redefined in the application for more complex cases that
72 | // require custom inits (before constructors), otherwise these can
73 | // be done in main().
74 | //
75 | // Called from _start(), right after data & bss init, before
76 | // constructors.
77 |
78 | void
79 | __attribute__((weak))
80 | __initialize_hardware(void)
81 | {
82 | // Call the CSMSIS system clock routine to store the clock frequency
83 | // in the SystemCoreClock global RAM location.
84 | SystemCoreClockUpdate();
85 | }
86 |
87 | // ----------------------------------------------------------------------------
88 |
--------------------------------------------------------------------------------
/software/firmware/system/src/cortexm/_reset_hardware.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include "cmsis_device.h"
9 |
10 | // ----------------------------------------------------------------------------
11 |
12 | extern void
13 | __attribute__((noreturn))
14 | NVIC_SystemReset(void);
15 |
16 | // ----------------------------------------------------------------------------
17 |
18 | // Forward declarations
19 |
20 | void
21 | __reset_hardware(void);
22 |
23 | // ----------------------------------------------------------------------------
24 |
25 | // This is the default hardware reset routine; it can be
26 | // redefined in the application for more complex applications.
27 | //
28 | // Called from _exit().
29 |
30 | void
31 | __attribute__((weak,noreturn))
32 | __reset_hardware()
33 | {
34 | NVIC_SystemReset();
35 | }
36 |
37 | // ----------------------------------------------------------------------------
38 |
--------------------------------------------------------------------------------
/software/firmware/system/src/diag/Trace.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #if defined(TRACE)
9 |
10 | #include
11 | #include
12 | #include "diag/Trace.h"
13 | #include "string.h"
14 |
15 | #ifndef OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE
16 | #define OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE (128)
17 | #endif
18 |
19 | // ----------------------------------------------------------------------------
20 |
21 | int
22 | trace_printf(const char* format, ...)
23 | {
24 | int ret;
25 | va_list ap;
26 |
27 | va_start (ap, format);
28 |
29 | // TODO: rewrite it to no longer use newlib, it is way too heavy
30 |
31 | static char buf[OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE];
32 |
33 | // Print to the local buffer
34 | ret = vsnprintf (buf, sizeof(buf), format, ap);
35 | if (ret > 0)
36 | {
37 | // Transfer the buffer to the device
38 | ret = trace_write (buf, (size_t)ret);
39 | }
40 |
41 | va_end (ap);
42 | return ret;
43 | }
44 |
45 | int
46 | trace_puts(const char *s)
47 | {
48 | trace_write(s, strlen(s));
49 | return trace_write("\n", 1);
50 | }
51 |
52 | int
53 | trace_putchar(int c)
54 | {
55 | trace_write((const char*)&c, 1);
56 | return c;
57 | }
58 |
59 | void
60 | trace_dump_args(int argc, char* argv[])
61 | {
62 | trace_printf("main(argc=%d, argv=[", argc);
63 | for (int i = 0; i < argc; ++i)
64 | {
65 | if (i != 0)
66 | {
67 | trace_printf(", ");
68 | }
69 | trace_printf("\"%s\"", argv[i]);
70 | }
71 | trace_printf("]);\n");
72 | }
73 |
74 | // ----------------------------------------------------------------------------
75 |
76 | #endif // TRACE
77 |
--------------------------------------------------------------------------------
/software/firmware/system/src/newlib/README.txt:
--------------------------------------------------------------------------------
1 |
2 | The following files extend or replace some of the the newlib functionality:
3 |
4 | _startup.c: a customised startup sequence, written in C
5 |
6 | _exit.c: a customised exit() implementation
7 |
8 | _syscalls.c: local versions of the libnosys/librdimon code
9 |
10 | _sbrk.c: a custom _sbrk() to match the actual linker scripts
11 |
12 | assert.c: implementation for the asserion macros
13 |
14 | _cxx.cpp: local versions of some C++ support, to avoid references to
15 | large functions.
16 |
17 |
--------------------------------------------------------------------------------
/software/firmware/system/src/newlib/_cxx.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | // These functions are redefined locally, to avoid references to some
9 | // heavy implementations in the standard C++ library.
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | #include
14 | #include
15 | #include "diag/Trace.h"
16 |
17 | // ----------------------------------------------------------------------------
18 |
19 | namespace __gnu_cxx
20 | {
21 | void
22 | __attribute__((noreturn))
23 | __verbose_terminate_handler();
24 |
25 | void
26 | __verbose_terminate_handler()
27 | {
28 | trace_puts(__func__);
29 | abort();
30 | }
31 | }
32 |
33 | // ----------------------------------------------------------------------------
34 |
35 | extern "C"
36 | {
37 | void
38 | __attribute__((noreturn))
39 | __cxa_pure_virtual();
40 |
41 | void
42 | __cxa_pure_virtual()
43 | {
44 | trace_puts(__func__);
45 | abort();
46 | }
47 | }
48 |
49 | // ----------------------------------------------------------------------------
50 |
51 |
--------------------------------------------------------------------------------
/software/firmware/system/src/newlib/_exit.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include
9 | #include "diag/Trace.h"
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | #if !defined(DEBUG)
14 | extern void
15 | __attribute__((noreturn))
16 | __reset_hardware(void);
17 | #endif
18 |
19 | // ----------------------------------------------------------------------------
20 |
21 | // Forward declaration
22 |
23 | void
24 | _exit(int code);
25 |
26 | // ----------------------------------------------------------------------------
27 |
28 | // On Release, call the hardware reset procedure.
29 | // On Debug we just enter an infinite loop, to be used as landmark when halting
30 | // the debugger.
31 | //
32 | // It can be redefined in the application, if more functionality
33 | // is required.
34 |
35 | void
36 | __attribute__((weak))
37 | _exit(int code __attribute__((unused)))
38 | {
39 | #if !defined(DEBUG)
40 | __reset_hardware();
41 | #endif
42 |
43 | // TODO: write on trace
44 | while (1)
45 | ;
46 | }
47 |
48 | // ----------------------------------------------------------------------------
49 |
50 | void
51 | __attribute__((weak,noreturn))
52 | abort(void)
53 | {
54 | trace_puts("abort(), exiting...");
55 |
56 | _exit(1);
57 | }
58 |
59 | // ----------------------------------------------------------------------------
60 |
--------------------------------------------------------------------------------
/software/firmware/system/src/newlib/_sbrk.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include
9 | #include
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | caddr_t
14 | _sbrk(int incr);
15 |
16 | // ----------------------------------------------------------------------------
17 |
18 | // The definitions used here should be kept in sync with the
19 | // stack definitions in the linker script.
20 |
21 | caddr_t
22 | _sbrk(int incr)
23 | {
24 | extern char _Heap_Begin; // Defined by the linker.
25 | extern char _Heap_Limit; // Defined by the linker.
26 |
27 | static char* current_heap_end;
28 | char* current_block_address;
29 |
30 | if (current_heap_end == 0)
31 | {
32 | current_heap_end = &_Heap_Begin;
33 | }
34 |
35 | current_block_address = current_heap_end;
36 |
37 | // Need to align heap to word boundary, else will get
38 | // hard faults on Cortex-M0. So we assume that heap starts on
39 | // word boundary, hence make sure we always add a multiple of
40 | // 4 to it.
41 | incr = (incr + 3) & (~3); // align value to 4
42 | if (current_heap_end + incr > &_Heap_Limit)
43 | {
44 | // Some of the libstdc++-v3 tests rely upon detecting
45 | // out of memory errors, so do not abort here.
46 | #if 0
47 | extern void abort (void);
48 |
49 | _write (1, "_sbrk: Heap and stack collision\n", 32);
50 |
51 | abort ();
52 | #else
53 | // Heap has overflowed
54 | errno = ENOMEM;
55 | return (caddr_t) - 1;
56 | #endif
57 | }
58 |
59 | current_heap_end += incr;
60 |
61 | return (caddr_t) current_block_address;
62 | }
63 |
64 | // ----------------------------------------------------------------------------
65 |
66 |
--------------------------------------------------------------------------------
/software/firmware/system/src/newlib/assert.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include "diag/Trace.h"
11 |
12 | // ----------------------------------------------------------------------------
13 |
14 | void
15 | __attribute__((noreturn))
16 | __assert_func (const char *file, int line, const char *func,
17 | const char *failedexpr)
18 | {
19 | trace_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
20 | failedexpr, file, line, func ? ", function: " : "",
21 | func ? func : "");
22 | abort ();
23 | /* NOTREACHED */
24 | }
25 |
26 | // ----------------------------------------------------------------------------
27 |
28 | // This is STM32 specific, but can be used on other platforms too.
29 | // If you need it, add the following to your application header:
30 |
31 | //#ifdef USE_FULL_ASSERT
32 | //#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
33 | //void assert_failed(uint8_t* file, uint32_t line);
34 | //#else
35 | //#define assert_param(expr) ((void)0)
36 | //#endif // USE_FULL_ASSERT
37 |
38 | #if defined(USE_FULL_ASSERT)
39 |
40 | void
41 | assert_failed (uint8_t* file, uint32_t line);
42 |
43 | // Called from the assert_param() macro, usually defined in the stm32f*_conf.h
44 | void
45 | __attribute__((noreturn, weak))
46 | assert_failed (uint8_t* file, uint32_t line)
47 | {
48 | trace_printf ("assert_param() failed: file \"%s\", line %d\n", file, line);
49 | abort ();
50 | /* NOTREACHED */
51 | }
52 |
53 | #endif // defined(USE_FULL_ASSERT)
54 |
55 | // ----------------------------------------------------------------------------
56 |
--------------------------------------------------------------------------------
/software/import.sh:
--------------------------------------------------------------------------------
1 | python ./3rdParty/CubeMXImporter/cubemximporter.py firmware ./cube-src/firmware/
2 |
--------------------------------------------------------------------------------
/software/programmer/nuke_keys.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # This will erase the keys! (it will print them out before doing it though...)
5 | #
6 |
7 | import argparse
8 | from openocd.flashProgrammer import flashProgrammer
9 |
10 | MAIN_FLASH_ADDR = 0x8000000
11 | FLASH_BASE = 0x8000000
12 | KEY_FLASH_OFFSET = 0x1ffd4
13 | SECTOR_SIZE = 0x800
14 | KEY_BYTES = 30
15 |
16 | parser = argparse.ArgumentParser()
17 | parser.add_argument('--openocd_dir', action='store', default='/home/cmdc0de/opt/gnuarmeclipse/openocd/0.10.0-201701241841/', help='Open OCD dev directory')
18 |
19 | args, unknown = parser.parse_known_args()
20 |
21 | try:
22 | flasher = flashProgrammer(args.openocd_dir)
23 |
24 | if flasher.connected is True:
25 | flasher._sendCmd('reset halt')
26 |
27 | # Read device unique ID
28 | uid_bytes = flasher.readMem(0x1FFFF7E8, 12)
29 | uid = ''
30 | for byte in range(len(uid_bytes)):
31 | uid += '{:02X}'.format(uid_bytes[byte])
32 | print('uid:')
33 | print(uid)
34 |
35 | # Read device unique ID
36 | key_bytes = flasher.readMem(FLASH_BASE + KEY_FLASH_OFFSET, KEY_BYTES)
37 | key = ''
38 | for byte in range(len(key_bytes)):
39 | key += '{:02X}'.format(key_bytes[byte])
40 | print('key:')
41 | print(key)
42 |
43 | print('Nuking keys!')
44 | flasher.erase(FLASH_BASE + 0x20000 - SECTOR_SIZE, SECTOR_SIZE)
45 |
46 | finally:
47 | # Make sure we kill the flasher process, otherwise openocd thread
48 | # stays open in background
49 | if flasher:
50 | flasher.kill()
51 |
--------------------------------------------------------------------------------
/software/programmer/openocd/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thedarknet/defcon25-badge/36768f274d4c1c5537d74f9f966640b25490ba97/software/programmer/openocd/__init__.py
--------------------------------------------------------------------------------
/software/programmer/program-normal-user.sh:
--------------------------------------------------------------------------------
1 | python program.py --openocd_dir $HOME/opt/gnuarmeclipse/openocd/0.10.0-201701241841/ --key_dir $HOME/dev/defcon/defcon25-badge/software/BadgeGen/keys --flash $HOME/dev/defcon/defcon25-badge/software/firmware/bin/firmware.hex
2 |
--------------------------------------------------------------------------------
/software/programmer/program-uber-user.sh:
--------------------------------------------------------------------------------
1 | python program.py --openocd_dir $HOME/opt/gnuarmeclipse/openocd/0.10.0-201701241841/ --key_dir $HOME/dev/defcon/defcon25-badge/software/BadgeGen/keys-uber --flash $HOME/dev/defcon/defcon25-badge/software/firmware/bin/firmware.hex
2 |
--------------------------------------------------------------------------------
/software/programmer/test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | from openocd.flashProgrammer import flashProgrammer
5 |
6 | #
7 | # Quick example of reading UID, erasing flash, programming flash, and reading back flash
8 | #
9 | flasher = flashProgrammer()
10 |
11 | if flasher.connected is True:
12 | flasher._sendCmd('reset halt')
13 |
14 | # Read device unique ID
15 | uid_bytes = flasher.readMem(0x1FFFF7E8, 12)
16 | uid = ''
17 | for byte in range(len(uid_bytes)):
18 | uid += '{:02X}'.format(uid_bytes[byte])
19 | print('uid:')
20 | print(uid)
21 |
22 | flasher.erase(0x800d400, 0x400)
23 |
24 | flasher.flashFile('/Users/alvaro/Desktop/test.bin', 0x800d400)
25 |
26 | print flasher.verifyFile('/Users/alvaro/Desktop/test.bin', 0x800d400)
27 | print flasher.verifyFile('/Users/alvaro/Desktop/flash.bin', 0x800d400)
28 |
29 | # flasher.dumpImage('/Users/alvaro/Desktop/flash.bin', 0x800d400, 0x400)
30 |
31 | flasher.kill()
32 |
33 |
--------------------------------------------------------------------------------