├── py ├── requirements.txt ├── README.md ├── pad_boot_binary.py ├── prepend_signatures_firmware_binary.py ├── pad_firmware_binary.py └── send_command.py ├── src ├── drivers │ ├── lib │ │ ├── libssp.a │ │ ├── libssp_nonshared.a │ │ ├── libarm_cortexM4l_math.a │ │ └── libsam4s-32qt-k-8rs-gnu.a │ ├── sam │ │ ├── utils │ │ │ ├── compiler.h │ │ │ ├── preprocessor │ │ │ │ └── preprocessor.h │ │ │ └── cmsis │ │ │ │ └── sam4s │ │ │ │ └── include │ │ │ │ ├── instance │ │ │ │ ├── instance_gpbr.h │ │ │ │ ├── instance_chipid.h │ │ │ │ ├── instance_wdt.h │ │ │ │ ├── instance_rstc.h │ │ │ │ └── instance_rtt.h │ │ │ │ └── system_sam4s.h │ │ └── drivers │ │ │ ├── pio │ │ │ └── pio_handler.h │ │ │ └── wdt │ │ │ └── wdt.h │ ├── thirdparty │ │ ├── fatfs │ │ │ ├── fatfs-r0.09 │ │ │ │ ├── doc │ │ │ │ │ ├── css_j.css │ │ │ │ │ ├── img │ │ │ │ │ │ ├── f1.png │ │ │ │ │ │ ├── f2.png │ │ │ │ │ │ ├── f3.png │ │ │ │ │ │ ├── f4.png │ │ │ │ │ │ ├── f5.png │ │ │ │ │ │ ├── f6.png │ │ │ │ │ │ ├── layers.png │ │ │ │ │ │ ├── layers3.png │ │ │ │ │ │ ├── rwtest.png │ │ │ │ │ │ ├── rwtest2.png │ │ │ │ │ │ └── rwtest3.png │ │ │ │ │ ├── 00index_j.html │ │ │ │ │ ├── en │ │ │ │ │ │ ├── fattime.html │ │ │ │ │ │ ├── size.html │ │ │ │ │ │ ├── error.html │ │ │ │ │ │ ├── tell.html │ │ │ │ │ │ ├── eof.html │ │ │ │ │ │ ├── dinit.html │ │ │ │ │ │ ├── dstat.html │ │ │ │ │ │ ├── chdrive.html │ │ │ │ │ │ ├── sdir.html │ │ │ │ │ │ ├── truncate.html │ │ │ │ │ │ ├── close.html │ │ │ │ │ │ ├── getcwd.html │ │ │ │ │ │ ├── putc.html │ │ │ │ │ │ ├── sync.html │ │ │ │ │ │ ├── mount.html │ │ │ │ │ │ ├── puts.html │ │ │ │ │ │ ├── mkdir.html │ │ │ │ │ │ ├── dread.html │ │ │ │ │ │ ├── opendir.html │ │ │ │ │ │ ├── stat.html │ │ │ │ │ │ ├── dwrite.html │ │ │ │ │ │ ├── sfile.html │ │ │ │ │ │ ├── chdir.html │ │ │ │ │ │ ├── read.html │ │ │ │ │ │ ├── unlink.html │ │ │ │ │ │ ├── gets.html │ │ │ │ │ │ └── rename.html │ │ │ │ │ └── css_e.css │ │ │ │ └── src │ │ │ │ │ ├── integer.h │ │ │ │ │ └── diskio.h │ │ │ └── ATMEL-disclaimer.txt │ │ └── CMSIS │ │ │ ├── CMSIS END USER LICENCE AGREEMENT.pdf │ │ │ └── README.txt │ ├── README.md │ ├── config │ │ ├── conf_sleepmgr.h │ │ ├── conf_sd_mmc.h │ │ ├── conf_uart_serial.h │ │ └── conf_spi_master.h │ └── common │ │ └── services │ │ ├── sleepmgr │ │ └── sam │ │ │ └── sleepmgr.c │ │ ├── delay │ │ └── sam │ │ │ └── cycle_counter.c │ │ ├── twi │ │ └── sam_twi │ │ │ ├── twi_slave.h │ │ │ └── twi_master.h │ │ └── serial │ │ └── usart_serial.c ├── hw_version.h ├── hw_version.c ├── json.h ├── systick.h ├── random.h ├── ripemd160.h ├── base58.h ├── pbkdf2.h ├── version.h.in ├── hmac.h ├── led.h ├── ecdh.h ├── commander.h ├── systick.c ├── u2f │ ├── genkeys.sh │ └── u2f_keys.h ├── asm │ └── platform-specific.inc ├── flags.c ├── secp256k1.c ├── ataes132.h ├── u2f_device.h ├── bip32.h ├── bootloader.h ├── cipher.h ├── utils.h ├── base64.h ├── touch.h ├── simulator.c ├── pbkdf2.c └── sha2.h ├── contrib ├── astyle_3.0_linux.tar.gz ├── contributors_gpg_keys │ ├── jonasschnelli-key.pgp │ ├── lucasbetschart-key.pgp │ └── djb-key.pgp ├── signature_check.sh ├── git │ └── pre-commit └── README.md ├── .gitignore ├── SECURITY.md ├── .gitmodules ├── .valgrind.supp ├── Vagrantfile ├── arm.cmake ├── LICENSE ├── tests ├── sd_files │ ├── test_backup_v2.2.3.pdf │ ├── test_backup_hww.pdf │ ├── test_backup_u2f.pdf │ └── test_backup.pdf ├── tests_yajl.c ├── generate_base64_testcases.py └── tests_secp256k1.c ├── Makefile ├── Dockerfile.dev ├── doc └── BB01_logo_github.svg └── dockerdev.sh /py/requirements.txt: -------------------------------------------------------------------------------- 1 | hidapi==0.13.1 2 | pyaes==1.6.1 3 | -------------------------------------------------------------------------------- /src/drivers/lib/libssp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/lib/libssp.a -------------------------------------------------------------------------------- /contrib/astyle_3.0_linux.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/contrib/astyle_3.0_linux.tar.gz -------------------------------------------------------------------------------- /src/drivers/sam/utils/compiler.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/sam/utils/compiler.h -------------------------------------------------------------------------------- /src/drivers/lib/libssp_nonshared.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/lib/libssp_nonshared.a -------------------------------------------------------------------------------- /src/drivers/lib/libarm_cortexM4l_math.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/lib/libarm_cortexM4l_math.a -------------------------------------------------------------------------------- /src/drivers/lib/libsam4s-32qt-k-8rs-gnu.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/lib/libsam4s-32qt-k-8rs-gnu.a -------------------------------------------------------------------------------- /contrib/contributors_gpg_keys/jonasschnelli-key.pgp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/contrib/contributors_gpg_keys/jonasschnelli-key.pgp -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | build-vagrant 3 | version.h 4 | .vagrant 5 | .DS_Store 6 | .ycm* 7 | *.o 8 | *.pyc 9 | *.sw* 10 | *.bak 11 | *.bin 12 | !*.c 13 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/css_j.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/css_j.css -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f1.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f2.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f3.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f4.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f5.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/f6.png -------------------------------------------------------------------------------- /src/drivers/README.md: -------------------------------------------------------------------------------- 1 | Digital Bitbox Firmware Drivers 2 | ============ 3 | 4 | 5 | Low level MCU drivers are available from the Atmel Software Framework. 6 | 7 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/00index_j.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/00index_j.html -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/layers.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/layers3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/layers3.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/rwtest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/rwtest.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/rwtest2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/rwtest2.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/rwtest3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/img/rwtest3.png -------------------------------------------------------------------------------- /src/drivers/thirdparty/CMSIS/CMSIS END USER LICENCE AGREEMENT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitBoxSwiss/mcu/HEAD/src/drivers/thirdparty/CMSIS/CMSIS END USER LICENCE AGREEMENT.pdf -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/ATMEL-disclaimer.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * The fatfs folder contains a modified image of the FatFS r0.09 to 3 | * fit with the Atmel Software Framework release. 4 | */ 5 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Security Policy 4 | 5 | ## Reporting a Vulnerability 6 | 7 | Please disclose any vulnurability responsibly through our [bug bounty program](https://shiftcrypto.ch/bug-bounty-program). 8 | -------------------------------------------------------------------------------- /src/hw_version.h: -------------------------------------------------------------------------------- 1 | #ifndef _HW_VERSION_H_ 2 | #define _HW_VERSION_H_ 3 | 4 | #include 5 | 6 | typedef enum HW_VERSION { 7 | HW_VERSION_V1 = 0xFF, 8 | HW_VERSION_V1_2 = 0x01, 9 | } HW_VERSION; 10 | 11 | 12 | uint8_t report_hw_version(void); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/hw_version.c: -------------------------------------------------------------------------------- 1 | #include "hw_version.h" 2 | #include "board_com.h" 3 | 4 | uint8_t report_hw_version(void) 5 | { 6 | BOARD_COM_ATAES_MODE ataes_mode = board_com_report_ataes_mode(); 7 | if (ataes_mode == BOARD_COM_ATAES_MODE_SPI) { 8 | return HW_VERSION_V1_2; 9 | } 10 | return HW_VERSION_V1; 11 | } 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/yajl"] 2 | path = src/yajl 3 | url = https://github.com/digitalbitbox/yajl.git 4 | [submodule "secp256k1"] 5 | path = src/secp256k1 6 | url = https://github.com/digitalbitbox/secp256k1_patch.git 7 | [submodule "hidapi"] 8 | path = tests/hidapi 9 | url = https://github.com/digitalbitbox/hidapi.git 10 | -------------------------------------------------------------------------------- /py/README.md: -------------------------------------------------------------------------------- 1 | Digital Bitbox Python 2 | ============ 3 | 4 | Python (v2 or v3) code supporting the [Digital Bitbox](https://digitalbitbox.com) hardware wallet. 5 | 6 | ### Developer interface 7 | 8 | Use `send_command.py` and `dbb_utils.py` to communicate with a Digital Bitbox. See the [API](https://digitalbitbox.com/api) for available commands. 9 | 10 | Dependencies: 11 | 12 | - [Python](http://python.org) 13 | 14 | The code uses the following additional Python libraries: `os`, `sys`, `struct`, `json`, `base64`, `pyaes`, `hashlib`, and `hidapi`. 15 | -------------------------------------------------------------------------------- /py/pad_boot_binary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import os 5 | import shutil 6 | 7 | binfile = sys.argv[1] 8 | padfile = sys.argv[2] 9 | binsize = os.stat(binfile).st_size 10 | 11 | max_binsize = 32768 12 | min_padsize = 32 # Reserved amount for 'factory' entropy 13 | 14 | if binsize > max_binsize - min_padsize: 15 | print '\nERROR: Bootloader must be less than {} bytes.\n'.format(max_binsize - min_padsize) 16 | sys.exit(1) 17 | else: 18 | shutil.copyfile(binfile, padfile) 19 | with open(padfile, 'ab') as f: 20 | f.write(os.urandom(max_binsize - binsize)) 21 | f.close() 22 | -------------------------------------------------------------------------------- /contrib/signature_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Validate signatures on each and every commit within the given range 4 | ## 5 | 6 | # if a ref is provided, append range spec to include all children 7 | chkafter="${1+$1..}" 8 | 9 | 10 | # Check every commit after chkafter (or all commits if chkafter was not 11 | # provided) for a trusted signature, listing invalid commits. %G? will output 12 | # "G" if the signature is trusted. 13 | git log --pretty="format:%H %aN %s %G?" "${chkafter:-HEAD}" \ 14 | | grep -v "${t} G$" 15 | 16 | # grep will exit with a non-zero status if no matches are found, which we 17 | # consider a success, so invert it 18 | [ $? -gt 0 ] 19 | -------------------------------------------------------------------------------- /.valgrind.supp: -------------------------------------------------------------------------------- 1 | # Valgrind suppression file 2 | # 3 | # Note: Could not figure out how to fix this error. Suppressed instead as it only affects unit testing (simulating the SD card). 4 | { 5 | SUPPRESS (travis): Conditional jump or move depends on uninitialised value(s)/sd.c[TESTING=true]>sd_list>opendir() 6 | Memcheck:Cond 7 | fun:vfprintf 8 | fun:vsnprintf 9 | fun:snprintf 10 | fun:tests_seed_xpub_backup 11 | fun:run_utests 12 | fun:main 13 | } 14 | { 15 | SUPPRESS (ubuntu): Conditional jump or move depends on uninitialised value(s)/sd.c[TESTING=true]>sd_list>opendir() 16 | Memcheck:Cond 17 | fun:vfprintf 18 | fun:__vsnprintf_chk 19 | fun:__snprintf_chk 20 | fun:tests_seed_xpub_backup 21 | fun:run_utests 22 | fun:main 23 | } 24 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure(2) do |config| 5 | config.vm.box = "ubuntu/trusty64" 6 | 7 | config.vm.provision "shell", privileged: false, inline: <<-SHELL 8 | sudo locale-gen UTF-8 9 | sudo apt update && sudo apt-get install -y cmake git 10 | wget -O gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2019q3/RC1.1/gcc-arm-none-eabi-8-2019-q3-update-linux.tar.bz2 11 | tar -xf gcc.tar.bz2 12 | sudo rsync -a gcc-arm-none-eabi-8-2019-q3-update/ /usr/local/ 13 | SHELL 14 | 15 | config.vm.provision "shell", run: "always", privileged: false, inline: <<-SHELL 16 | mkdir -p /vagrant/build-vagrant 17 | cd /vagrant/build-vagrant 18 | rm -rf * && cmake .. -DBUILD_TYPE=firmware && make 19 | SHELL 20 | end 21 | -------------------------------------------------------------------------------- /py/prepend_signatures_firmware_binary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import os 5 | import shutil 6 | 7 | try: 8 | binfile = sys.argv[1] 9 | padfile = sys.argv[2] 10 | signatures = sys.argv[3] 11 | 12 | if len(signatures) != 896: 13 | print '\n\nError: The signature blob must be an 896-character hexadecimal string.' 14 | sys.exit() 15 | 16 | sig = bytearray.fromhex(signatures) 17 | 18 | with file(binfile, 'r') as original: 19 | data = original.read() 20 | 21 | if len(data) != 225280: 22 | print '\n\nError: the binfile must be padded to 220kB' 23 | sys.exit() 24 | 25 | with file(padfile, 'w') as pf: 26 | pf.write(sig) 27 | pf.write(data) 28 | pf.close() 29 | 30 | except: 31 | print '\n\nUsage:\n ./prepend_signatures_firmware_binary.py \n\n\n' 32 | -------------------------------------------------------------------------------- /arm.cmake: -------------------------------------------------------------------------------- 1 | message("Loading arm.cmake") 2 | 3 | set(CMAKE_SYSTEM_NAME "Generic") 4 | 5 | include(CMakeForceCompiler) 6 | 7 | CMAKE_FORCE_C_COMPILER("arm-none-eabi-gcc" GNU) 8 | 9 | set(CMAKE_AR "arm-none-eabi-ar" CACHE PATH "" FORCE) 10 | set(CMAKE_RANLIB "arm-none-eabi-ranlib" CACHE PATH "" FORCE) 11 | set(CMAKE_LINKER "arm-none-eabi-ld" CACHE PATH "" FORCE) 12 | set(CMAKE_SIZE "arm-none-eabi-size") 13 | set(CMAKE_OBJCOPY "arm-none-eabi-objcopy") 14 | 15 | # Search for programs in the build host directories 16 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 17 | 18 | # For libraries and headers in the target directories 19 | #set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 20 | #set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 21 | 22 | # Avoid known bug in linux giving: 23 | # arm-none-eabi-gcc: error: unrecognized command line option '-rdynamic' 24 | set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") 25 | set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") 26 | 27 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/src/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /py/pad_firmware_binary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import os 5 | import shutil 6 | import struct 7 | 8 | binfile = sys.argv[1] 9 | padfile = sys.argv[2] 10 | try: 11 | version_monotonic = int(sys.argv[3]) 12 | if version_monotonic == 0xffffffff or version_monotonic <= 0: 13 | raise Exception() 14 | except: 15 | print "\nERROR: version needs to be between 1 and 0xffffffff-1" 16 | sys.exit(1) 17 | binsize = os.stat(binfile).st_size 18 | 19 | max_binsize = 225280 # 220kB 20 | min_padsize = 512 # Reserved amount for metadata 21 | 22 | if binsize > max_binsize - min_padsize: 23 | print '\nERROR: App binary must be less than {} bytes.\n'.format(max_binsize - min_padsize) 24 | sys.exit(1) 25 | else: 26 | shutil.copyfile(binfile, padfile) 27 | # firmware monotonic version is a 4 byte big endian unsigned integer. 28 | version_bytes = struct.pack('>I', version_monotonic) 29 | with open(padfile, 'ab') as f: 30 | f.write(b'\xff' * (max_binsize - binsize - len(version_bytes))) 31 | f.write(version_bytes) 32 | f.close() 33 | -------------------------------------------------------------------------------- /src/json.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef _JSON_H_ 5 | #define _JSON_H_ 6 | 7 | /** 8 | * Appends a "key"="value" and the closing bracket '}' where value will be correctly quoted. 9 | */ 10 | int json_append_kv_pair_quoted(char *out, size_t len, const char *key, 11 | const char *val); 12 | 13 | /** 14 | * Appends a "key"=value string where value should not be quoted, like if value 15 | * is a number or already a correctly quoted string, and the closing bracket '}'. 16 | */ 17 | int json_append_kv_pair_unquoted(char *out, size_t len, const char *key, 18 | const char *val); 19 | 20 | /** 21 | * Writes a complete valid json object for errors. 22 | */ 23 | int json_format_error(char *out, size_t len, const char *cmd, const char *msg, 24 | int flag); 25 | 26 | /** 27 | * Writes a complete valid json object. Will quote value[i] if type[i] == 28 | * DBB_JSON_STRING. 29 | */ 30 | int json_format_object(char *out, size_t len, const char **key, 31 | const char **value, int *type); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015-2016 Douglas J. Bakkum 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | */ 24 | 25 | -------------------------------------------------------------------------------- /tests/sd_files/test_backup_v2.2.3.pdf: -------------------------------------------------------------------------------- 1 | %PDF-1.1 2 | 1 0 obj 3 | <> 6 | endobj 7 | 2 0 obj 8 | <> 13 | endobj 14 | 3 0 obj 15 | <> 24 | >> 25 | >> 26 | /Contents 4 0 R 27 | >> 28 | endobj 29 | 4 0 obj 30 | << /Length 357 >> 31 | stream 32 | BT 33 | /F1 12 Tf 34 | 50 700 Td 35 | (Wallet backup:) Tj 36 | <20 2020202020> Tj 37 | 0 -24 Td 38 | (69794a18aef59bdd43b8e4e6831d5403ccd80f150a21b90c6d4499d879707bad) Tj 39 | 0 -16 Td 40 | () Tj 41 | 0 -16 Td 42 | %(-TESTTESTTESTTEST-) Tj 43 | <2020202020 20> Tj 44 | 0 -48 Td 45 | (Wallet name: TESTTESTTESTTEST-) Tj 46 | 0 -32 Td 47 | (Passphrase: ______________________) Tj 48 | /F1 10 Tf 49 | 0 -60 Td 50 | (digitalbitbox.com/backup) Tj 51 | ET 52 | 53 | endstream 54 | endobj 55 | xref 56 | 0 5 57 | 0000000000 65535 f 58 | 0000000009 00000 n 59 | 0000000057 00000 n 60 | 0000000137 00000 n 61 | 0000000284 00000 n 62 | trailer 63 | << 64 | /Size 5 65 | /Root 1 0 R 66 | >> 67 | startxref 68 | 691 69 | %%EOF 70 | -------------------------------------------------------------------------------- /py/send_command.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | from dbb_utils import * 5 | 6 | 7 | try: 8 | 9 | password = '0000' 10 | 11 | openHid() 12 | 13 | 14 | # Start up options - factory reset; initial password setting 15 | if 0: 16 | hid_send_encrypt('{"reset":"__ERASE__"}', password) 17 | hid_send_plain('{"password":"' + password + '"}') 18 | sys.exit() 19 | 20 | 21 | # Example JSON commands - refer to digitalbitbox.com/api 22 | message = '{"backup":"list"}' 23 | message = '{"device":"info"}' 24 | message = '{"random":"pseudo"}' 25 | message = '{"bootloader":"lock"}' 26 | message = '{"bootloader":"unlock"}' 27 | message = '{"feature_set":{"U2F":false}}' 28 | message = '{"seed":{"source":"create", "filename":"testing.pdf", "key":"password"}}' 29 | message = '{"sign":{"meta":"hash", "data":[{"keypath":"m/1p/1/1/0", "hash":"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"},{"keypath":"m/1p/1/1/1", "hash":"123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0"}]}}' 30 | message = '{"led":"blink"}' 31 | 32 | 33 | # Send a JSON command 34 | hid_send_encrypt(message, password) 35 | 36 | 37 | except IOError as ex: 38 | print(ex) 39 | except(KeyboardInterrupt, SystemExit): 40 | print("Exiting code") 41 | 42 | dbb_hid.close() 43 | 44 | -------------------------------------------------------------------------------- /src/systick.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _SYSTICK_H_ 29 | #define _SYSTICK_H_ 30 | 31 | 32 | void systick_update_time(void); 33 | void systick_init(void); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _RANDOM_H_ 29 | #define _RANDOM_H_ 30 | 31 | #include 32 | 33 | uint32_t random_uint32(uint8_t update_seed); 34 | int random_bytes(uint8_t *buf, uint32_t len, uint8_t update_seed); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/ripemd160.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-2014 Tomas Dzetkulic 3 | * Copyright (c) 2013-2014 Pavol Rusnak 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | * OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | #ifndef __RIPEMD160_H__ 26 | #define __RIPEMD160_H__ 27 | 28 | #include 29 | 30 | void ripemd160(const uint8_t *msg, uint32_t msg_len, uint8_t *hash); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /contrib/git/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | hasFormattingIssues=0 4 | 5 | if ! command -v astyle >/dev/null ; then 6 | echo -n "error: please install astyle in order to be able" 7 | echo " to use this pre-commit git-hook" 8 | exit 1 9 | fi 10 | 11 | if git rev-parse --verify HEAD >/dev/null 2>&1; then 12 | against=HEAD 13 | else 14 | # Initial commit: diff against an empty tree object 15 | against=2caab4551b305ab1e9e4b05145a4da5f51331e0d 16 | fi 17 | 18 | # Redirect output to stderr. 19 | exec 1>&2 20 | 21 | files=$(git diff --cached --name-only --diff-filter=AM $against | \ 22 | grep -E '^(src|tests)' | grep -E '(c|h)$' | grep -v 'src/drivers/' | grep -v '.inc' | grep -v '.sh') 23 | 24 | for file in $files; do 25 | astyle --style=kr --indent-switches --indent-labels --pad-oper --pad-header --align-pointer=name --add-braces --convert-tabs --max-code-length=90 --break-after-logical -Q $file 26 | if [ -e "$file.orig" ]; then 27 | mv $file "$file.formated" 28 | mv "$file.orig" $file 29 | git diff --no-index "$file" "$file.formated" | cat 30 | 31 | isDiff=$(diff --brief "$file.formated" $file) 32 | if [ "$isDiff" != "" ] ; then 33 | hasFormattingIssues=1 34 | fi 35 | rm "$file.formated" 36 | fi 37 | done 38 | 39 | 40 | if [ $hasFormattingIssues -eq 1 ] ; then 41 | echo Found code style formatting issues. 42 | exit 1 43 | fi 44 | 45 | -------------------------------------------------------------------------------- /tests/sd_files/test_backup_hww.pdf: -------------------------------------------------------------------------------- 1 | %PDF-1.1 2 | 1 0 obj 3 | <> 6 | endobj 7 | 2 0 obj 8 | <> 13 | endobj 14 | 3 0 obj 15 | <> 24 | >> 25 | >> 26 | /Contents 4 0 R 27 | >> 28 | endobj 29 | 4 0 obj 30 | << /Length 608 >> 31 | stream 32 | BT 33 | /F1 12 Tf 34 | 50 700 Td 35 | (Wallet name: My Digital Bitbox) Tj 36 | 0 -48 Td 37 | (Wallet backup:) Tj 38 | 0 -24 Td 39 | (69794a18aef59bdd43b8e4e6831d5403ccd80f150a21b90c6d4499d879707bad) Tj 40 | 0 -48 Td 41 | (U2F backup:) Tj 42 | 0 -24 Td 43 | () Tj 44 | 0 -48 Td 45 | (Passphrase: ______________________) Tj 46 | /F1 10 Tf 47 | 0 -96 Td 48 | (For instructions, see digitalbitbox.com/backup.) Tj 49 | <20 2020202020> Tj 50 | %(69794a18aef59bdd43b8e4e6831d5403ccd80f150a21b90c6d4499d879707bad) Tj 51 | %(-My Digital Bitbox) Tj 52 | <2020202020 20> Tj 53 | %(REDUNDANCY_START) Tj 54 | %(69794a18aef59bdd43b8e4e6831d5403ccd80f150a21b90c6d4499d879707bad) Tj 55 | %(=My Digital Bitbox) Tj 56 | %(REDUNCANCY_END) Tj 57 | 58 | ET 59 | endstream 60 | endobj 61 | xref 62 | 0 5 63 | 0000000000 65535 f 64 | 0000000009 00000 n 65 | 0000000057 00000 n 66 | 0000000137 00000 n 67 | 0000000284 00000 n 68 | trailer 69 | << 70 | /Size 5 71 | /Root 1 0 R 72 | >> 73 | startxref 74 | 942 75 | %%EOF 76 | -------------------------------------------------------------------------------- /tests/sd_files/test_backup_u2f.pdf: -------------------------------------------------------------------------------- 1 | %PDF-1.1 2 | 1 0 obj 3 | <> 6 | endobj 7 | 2 0 obj 8 | <> 13 | endobj 14 | 3 0 obj 15 | <> 24 | >> 25 | >> 26 | /Contents 4 0 R 27 | >> 28 | endobj 29 | 4 0 obj 30 | << /Length 624 >> 31 | stream 32 | BT 33 | /F1 12 Tf 34 | 50 700 Td 35 | (Wallet name: My Digital Bitbox) Tj 36 | 0 -48 Td 37 | (Wallet backup:) Tj 38 | 0 -24 Td 39 | () Tj 40 | 0 -48 Td 41 | (U2F backup:) Tj 42 | 0 -24 Td 43 | (bcb11d5d22f16b323f64c50b8e6ce7ece69d9a4de45eee6d7c9d000436264ae6) Tj 44 | 0 -48 Td 45 | (Passphrase: ______________________) Tj 46 | /F1 10 Tf 47 | 0 -96 Td 48 | (For instructions, see digitalbitbox.com/backup.) Tj 49 | <20 2020202020> Tj 50 | %() Tj 51 | %(=bcb11d5d22f16b323f64c50b8e6ce7ece69d9a4de45eee6d7c9d000436264ae6) Tj 52 | %(-My Digital Bitbox) Tj 53 | <2020202020 20> Tj 54 | %(REDUNDANCY_START) Tj 55 | %() Tj 56 | %(=bcb11d5d22f16b323f64c50b8e6ce7ece69d9a4de45eee6d7c9d000436264ae6) Tj 57 | %(=My Digital Bitbox) Tj 58 | %(REDUNCANCY_END) Tj 59 | 60 | ET 61 | endstream 62 | endobj 63 | xref 64 | 0 5 65 | 0000000000 65535 f 66 | 0000000009 00000 n 67 | 0000000057 00000 n 68 | 0000000137 00000 n 69 | 0000000284 00000 n 70 | trailer 71 | << 72 | /Size 5 73 | /Root 1 0 R 74 | >> 75 | startxref 76 | 958 77 | %%EOF 78 | -------------------------------------------------------------------------------- /src/base58.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-2014 Tomas Dzetkulic 3 | * Copyright (c) 2013-2014 Pavol Rusnak 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | * OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef __BASE58_H__ 25 | #define __BASE58_H__ 26 | 27 | #include 28 | 29 | int base58_encode_check(const uint8_t *data, int len, char *str, int strsize); 30 | int base58_decode_check(const char *str, uint8_t *data, int datalen); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/pbkdf2.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _PBKDF2_H_ 29 | #define _PBKDF2_H_ 30 | 31 | 32 | #include 33 | 34 | 35 | #define PBKDF2_ROUNDS 2048 36 | #define PBKDF2_HMACLEN 64 37 | 38 | 39 | void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const char *salt, uint8_t *key, 40 | int keylen); 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /tests/tests_yajl.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | int main(void) 33 | { 34 | // The submodule must be built in order to run the yajl tests. See: 35 | // https://github.com/digitalbitbox/yajl/blob/master/BUILDING 36 | const char command[] = "cd ../src/yajl/test/parsing/; ./run_tests.sh"; 37 | return system(command); 38 | } 39 | -------------------------------------------------------------------------------- /src/version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef VERSION_H 29 | #define VERSION_H 30 | 31 | #define DIGITAL_BITBOX_VERSION "@VERSION_STRING@" 32 | #define DIGITAL_BITBOX_VERSION_SHORT "@VERSION_STRING_SHORT@" 33 | #define DIGITAL_BITBOX_VERSION_MAJOR @VERSION_STRING_MAJOR@ 34 | #define DIGITAL_BITBOX_VERSION_MINOR @VERSION_STRING_MINOR@ 35 | #define DIGITAL_BITBOX_VERSION_PATCH @VERSION_STRING_PATCH@ 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /contrib/README.md: -------------------------------------------------------------------------------- 1 | github-merge.sh 2 | ================== 3 | 4 | A small script to automate merging pull-requests securely and sign them with GPG. 5 | 6 | For example: 7 | 8 | ./github-merge.sh digitalbitbox/mcu 3077 9 | 10 | (in any git repository) will help you merge pull request #3077 for the 11 | digitalbitbox/mcu repository. 12 | 13 | What it does: 14 | * Fetch master and the pull request. 15 | * Locally construct a merge commit. 16 | * Show the diff that merge results in. 17 | * Ask you to verify the resulting source tree (so you can do a make 18 | check or whatever). 19 | * Ask you whether to GPG sign the merge commit. 20 | * Ask you whether to push the result upstream. 21 | 22 | This means that there are no potential race conditions (where a 23 | pullreq gets updated while you're reviewing it, but before you click 24 | merge), and when using GPG signatures, that even a compromised github 25 | couldn't mess with the sources. 26 | 27 | Setup 28 | --------- 29 | Configuring the github-merge tool for the digitalbitbox/mcu repository is done in the following way: 30 | 31 | git config githubmerge.repository digitalbitbox/mcu 32 | git config githubmerge.testcmd "make -j4 check" (adapt to whatever you want to use for testing) 33 | git config --global user.signingkey mykeyid (if you want to GPG sign) 34 | 35 | 36 | signature_check.sh 37 | ================== 38 | 39 | Validate signatures on each and every commit within the given range. 40 | 41 | For example: 42 | 43 | ./signature_check.sh f0a012e224fedac87b0393a161d4af1473fea74a 44 | 45 | Returns commits with unsigned or untrusted signature. 46 | -------------------------------------------------------------------------------- /src/hmac.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-2014 Tomas Dzetkulic 3 | * Copyright (c) 2013-2014 Pavol Rusnak 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | * OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | #ifndef __HMAC_H__ 26 | #define __HMAC_H__ 27 | 28 | #include 29 | 30 | void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, 31 | const uint32_t msglen, uint8_t *hmac); 32 | void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, 33 | const uint32_t msglen, uint8_t *hmac); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /tests/sd_files/test_backup.pdf: -------------------------------------------------------------------------------- 1 | %PDF-1.1 2 | 1 0 obj 3 | <> 6 | endobj 7 | 2 0 obj 8 | <> 13 | endobj 14 | 3 0 obj 15 | <> 24 | >> 25 | >> 26 | /Contents 4 0 R 27 | >> 28 | endobj 29 | 4 0 obj 30 | << /Length 816 >> 31 | stream 32 | BT 33 | /F1 12 Tf 34 | 50 700 Td 35 | (Wallet name: My Digital Bitbox) Tj 36 | 0 -48 Td 37 | (Wallet backup:) Tj 38 | 0 -24 Td 39 | (69794a18aef59bdd43b8e4e6831d5403ccd80f150a21b90c6d4499d879707bad) Tj 40 | 0 -48 Td 41 | (U2F backup:) Tj 42 | 0 -24 Td 43 | (bcb11d5d22f16b323f64c50b8e6ce7ece69d9a4de45eee6d7c9d000436264ae6) Tj 44 | 0 -48 Td 45 | (Passphrase: ______________________) Tj 46 | /F1 10 Tf 47 | 0 -96 Td 48 | (For instructions, see digitalbitbox.com/backup.) Tj 49 | <20 2020202020> Tj 50 | %(69794a18aef59bdd43b8e4e6831d5403ccd80f150a21b90c6d4499d879707bad) Tj 51 | %(=bcb11d5d22f16b323f64c50b8e6ce7ece69d9a4de45eee6d7c9d000436264ae6) Tj 52 | %(-My Digital Bitbox) Tj 53 | <2020202020 20> Tj 54 | %(REDUNDANCY_START) Tj 55 | %(69794a18aef59bdd43b8e4e6831d5403ccd80f150a21b90c6d4499d879707bad) Tj 56 | %(=bcb11d5d22f16b323f64c50b8e6ce7ece69d9a4de45eee6d7c9d000436264ae6) Tj 57 | %(=My Digital Bitbox) Tj 58 | %(REDUNCANCY_END) Tj 59 | 60 | ET 61 | endstream 62 | endobj 63 | xref 64 | 0 5 65 | 0000000000 65535 f 66 | 0000000009 00000 n 67 | 0000000057 00000 n 68 | 0000000137 00000 n 69 | 0000000284 00000 n 70 | trailer 71 | << 72 | /Size 5 73 | /Root 1 0 R 74 | >> 75 | startxref 76 | 1150 77 | %%EOF 78 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/CMSIS/README.txt: -------------------------------------------------------------------------------- 1 | * ------------------------------------------------------------------- 2 | * Copyright (C) 2011 ARM Limited. All rights reserved. 3 | * 4 | * Date: 11 October 2011 5 | * Revision: V3.00 6 | * 7 | * Project: Cortex Microcontroller Software Interface Standard (CMSIS) 8 | * Title: Release Note for CMSIS 9 | * 10 | * ------------------------------------------------------------------- 11 | 12 | 13 | NOTE - Open the index.html file to access CMSIS documentation 14 | 15 | 16 | The Cortex Microcontroller Software Interface Standard (CMSIS) provides a single standard across all 17 | Cortex-Mx processor series vendors. It enables code re-use and code sharing across software projects 18 | and reduces time-to-market for new embedded applications. 19 | 20 | CMSIS is released under the terms of the end user license agreement ("CMSIS END USER LICENCE AGREEMENT.pdf"). 21 | Any user of the software package is bound to the terms and conditions of the end user license agreement. 22 | 23 | 24 | You will find the following sub-directories: 25 | 26 | Documentation - Contains CMSIS documentation. 27 | 28 | DSP_Lib - MDK project files, Examples and source files etc.. to build the 29 | CMSIS DSP Software Library for Cortex-M0, Cortex-M3, Cortex-M4 processors. 30 | 31 | Include - CMSIS Core Support and CMSIS DSP Include Files. 32 | 33 | Lib - CMSIS DSP Libraries. 34 | 35 | RTOS - CMSIS RTOS API template header file. 36 | 37 | SVD - CMSIS SVD Schema files and Conversion Utility. 38 | -------------------------------------------------------------------------------- /src/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2019 Douglas J. Bakkum, Shift Cryptosecurity 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _LED_H_ 29 | #define _LED_H_ 30 | 31 | 32 | #include 33 | 34 | 35 | #define LED_MAX_CODE_BLINKS 4 36 | 37 | 38 | void led_on(void); 39 | void led_off(void); 40 | void led_warn(void); 41 | void led_pair(void); 42 | void led_success(void); 43 | void led_wink(void); 44 | void led_password(void); 45 | void led_sign(void); 46 | void led_boot_unlock(void); 47 | void led_toggle(void); 48 | void led_abort(void); 49 | void led_2FA_pairing_code(uint8_t code); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright 2019 Shift Cryptosecurity AG 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the "Software"), 7 | # to deal in the Software without restriction, including without limitation 8 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | # and/or sell copies of the Software, and to permit persons to whom the 10 | # Software is furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included 13 | # in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | # OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | firmware: 24 | mkdir -p build; cd build; cmake .. -DBUILD_TYPE=firmware && make -j4 25 | bootloader: 26 | mkdir -p build; cd build; cmake .. -DBUILD_TYPE=bootloader && make -j4 27 | docs: 28 | mkdir -p build; cd build; cmake .. -DBUILD_TYPE=firmware -DBUILD_DOCUMENTATION=ON && make doc 29 | test: 30 | mkdir -p build; cd build; cmake .. -DBUILD_TYPE=test && make -j4 31 | run-test: 32 | mkdir -p build; cd build; make test 33 | flash-dev-firmware: 34 | ./py/load_firmware.py build/bin/firmware.bin debug 35 | clean: 36 | rm -rf build/* 37 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/fattime.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - get_fattime 10 | 11 | 12 | 13 | 14 |
15 |

get_fattime

16 |

The get_fattime function gets current time.

17 |
18 | DWORD get_fattime (void);
19 | 
20 |
21 | 22 | 23 |
24 |

Return Value

25 |

Currnet time is returned with packed into a DWORD value. The bit field is as follows:

26 |
27 |
bit31:25
28 |
Year from 1980 (0..127)
29 |
bit24:21
30 |
Month (1..12)
31 |
bit20:16
32 |
Day in month(1..31)
33 |
bit15:11
34 |
Hour (0..23)
35 |
bit10:5
36 |
Minute (0..59)
37 |
bit4:0
38 |
Second / 2 (0..29)
39 |
40 |
41 | 42 | 43 |
44 |

Description

45 |

The get_fattime function must return any valid time even if the system does not support a real time clock. If a zero is returned, the file will not have a valid time. This fucntion is not required in read only configuration.

46 |
47 | 48 | 49 |

Return

50 | 51 | 52 | -------------------------------------------------------------------------------- /src/ecdh.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2018 Douglas J. Bakkum, Stephanie Stroka, Shift Cryptosecurity 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef _ECDH_H_ 28 | #define _ECDH_H_ 29 | 30 | #include 31 | 32 | #include "yajl/src/api/yajl_tree.h" 33 | 34 | 35 | #define CHALLENGE_MIN_BLINK_SETS 12// Minimum sets of blinks required before the shared secret is saved to eeprom 36 | #define SIZE_ECDH_SHARED_SECRET SHA256_DIGEST_LENGTH 37 | 38 | 39 | #ifdef TESTING 40 | uint8_t *test_shared_secret_report(void); 41 | void test_shared_secret_write(const uint8_t *data); 42 | #endif 43 | void ecdh_dispatch_command(yajl_val json_node); 44 | 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /contrib/contributors_gpg_keys/lucasbetschart-key.pgp: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | Version: GnuPG v2 3 | 4 | mQGiBFNST6URBADEWX94RRkG1Lm7tCGyZ4Ezwbw5x2MqPpguwsUUwUXMHv3Z6vjc 5 | 26cZrgcPzzcT2br7Vm10c1ywcl275l1+mGNNjl1hdwJhrlwU4ZbuxJDE36IfaM4K 6 | tY/3CxqPRZmyzHxrcU5DuRYO6cYHU69scH8ZYx3fSwNQLrwlnSvpsMs+cwCgmZoM 7 | zrVLMf5mBofMNAqR1PJBPE8EAItgYmzZFdGN94bauEwKrHHqbRHCwxx25gbdqR/7 8 | swf5y/a0CRv/MwNn54OYwPVZC+pOI0k0z0Dihzcpgklzc6hS18tK57r+IMta31nJ 9 | qIjZNAbedjZR3Ne9EcfGh3V1pVeuUcnm7YG4a36mwlKznshtArJ5KR+Uensf4p4R 10 | d5PTA/9ufIwu0W4S8vVEaUD5AUdm848cCj0D9o1S7sap6enJsR6UhA5oRfMTxWk7 11 | v2ACcvXrzcV4nOOKjNuXyQu2I+k2oOF9ikL8d5qLbbHbPUOwhKe2onDpEZHNGv2P 12 | VMCf8ASbzNX4DOofT3bEkL1NRUqQSdMPzRn4Yt4XnZu2J0WkX7QqTHVjYXMgQmV0 13 | c2NoYXJ0IDxsdWNhc2JldHNjaGFydEBnbWFpbC5jb20+iGYEExECACYCGyMHCwkI 14 | BwMCAQYVCAIJCgsEFgIDAQIeAQIXgAUCVcntygIZAQAKCRCyZeK7UNsUlHv1AJ4s 15 | 1P4yW4Avvfs378kQ9bOL3ZBcOQCfdupswvYkWLzXEZA++0YadvOvGcu5Ag0EU1JP 16 | pRAIAJfKZzEzCWD5Ffk/thMZilGON1GHxukvhGMSnT4anbOZGJ9jgpHQOejjhbxX 17 | bwftTlctatI1ejKIJjMwi857pQyWjbFU3WvRmB9TI0yE6wpkAYzzKx8QZmeefamX 18 | f6BDRAUC/sXJdH/Gzxsl6JqbPSeuxVMcnAoCvC0e8dX1fQQhhwbHiF5pp8fjVPpv 19 | BXKhEURJzdQ75CuB2fp6h3gMtLoZGZYGt46G7TWcRkmpQzBMrkKJp0KED8ReAIbI 20 | WLAs9uuna5JQGJTTZJhxt/x0Ua3FGBJs0Xi6pERlCD0AlwpnsKYgO8DCKNb2giG7 21 | PlpRWIO/nuEJipS895UpCPsXh+8AAwUH/0lyZrTH4phDnTtNmp2m7NjKGsSSbyR1 22 | ZYOYwjcVgj0padXgez8DqHUogY2OVDjFpLiYBBeFOSjLo/Aen9d8IGHPG8/iIg4P 23 | X5VtcN57d/XY6LgoTs/okiZe/6+WqA8pjWUNnb1OjRvlHblzbgd6TUiI0sZVSUzP 24 | X/dudAx74xo/f1g7lS0R0yYQBfV3Rnp6gzLoZexgm1H+uHTGFzkgWPE3oP7GCCF4 25 | kus5O+IUAvHd10QFJOAPeUHiqsO1hRJrSjLGQUK8FChGBHn6SegVNSmz7UyhUc2w 26 | smayY19unYzLFAHjHYDITZsAam9n7IUyRgkWbo5zV8UA4M8Lz+LsXQ+ISQQYEQIA 27 | CQUCU1JPpQIbDAAKCRCyZeK7UNsUlFORAJ9WbS6RML06T85Z+LPg3/UV1bX94wCg 28 | k1JL/H1Rpj+tccx75ADBGzDlvvE= 29 | =ZgAe 30 | -----END PGP PUBLIC KEY BLOCK----- 31 | -------------------------------------------------------------------------------- /contrib/contributors_gpg_keys/djb-key.pgp: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | Version: GnuPG v2 3 | 4 | mQENBFYNaeoBCADCO++Gs5n4KUlofpGfEw2qI2Mv0tDKL7KLNauan6KGyHaKqINl 5 | lYW9njCJWyoXFCd5hCryzKx+gVfmckpS9Jo3SZBVZq3f2rPolxgMNlDH4YYVezcB 6 | SwBniVrUdawOnQxE6EAwDdp8jPjeUZ9WIde4kcWoJUXljzMId6ey8piNB/Rz6MjS 7 | jN0nFMF9QtqaB64mWkyeWyKfVnNFzC4N4TqlDThFCIpxilgGK9OclyUhHqCCtv/p 8 | RKBvsgaiOG2Vw2Uflmvg5SRrzaUXrPmjGuFnGxJh4T7nsl5w6QpRWRcanpgb+GrD 9 | r9h+uXK9u4zuGyNR8Q2TCaOf+LLx1rB6WYHZABEBAAG0J0RvdWdsYXMgSiBCYWtr 10 | dW0gPGRqYkBzaGlmdGRldmljZXMuY29tPokBOQQTAQgAIwUCVg1p6gIbAwcLCQgH 11 | AwIBBhUIAgkKCwQWAgMBAh4BAheAAAoJEIpRLGtZRMEMNRAH/iZp5k2GR4NnDvcB 12 | BlM6/1P92Ws/3cU0DemdJm9sOrwVRgM8Cq4eFKDAB/UK6sJ8PCAYo9VZS8aifscb 13 | NPTicj5naB8OL7swTJGm4St+XMRn7oE8wYVfo24W34PsGmQOzJIceciUhyVrJjPa 14 | /KG4ndY8M9zUVxFZlBcOsQIVQ71B79WoS0GLk0j7vRYqhrukoCT/rVTnS1UsaJmd 15 | nKBI0MCuTc/VDVPrkK8PWt1H1JtncPajCWnDAs+YZX9/HSBTpHng7hFOnEXUma+K 16 | yFU4har6KrF95m++Hs2l1NxtZcrLLD0zvpz8ZR1AFBO0+sjEV95monIhLFa/9a1Q 17 | 92IPY/i5AQ0EVg1p6gEIAL/zU5m1gddSteuRQP05w5/g/O2bwQauUHk9b+B82R0r 18 | 3zlGs2FbhxpL1CfAqD2imUW4Sp+QbKtQotyTWLXWseODonjjwBsYe+C0GFpkm6cN 19 | A/WWqjXiOTUEIKxhIknfwaceiEx3rdLhsq7faKjc0wFpgYKpN2Nlz80agh3wA2MV 20 | zoIM86exZMtXcZ8ox/gPEUAASfD/URylfAJiqGewkrq3CVqRAch9EclRNZe/NtUI 21 | ikB6MmI1tSja/eWSiTOo+RafvhAyORltxg/1zYhtor7WWR1YUga8INDIBoT4IF/8 22 | KWeT8sqkcViy00cAMZn0AxnZAxm2kLGj/gLIKRCcrrsAEQEAAYkBHgQYAQgACQUC 23 | Vg1p6gIbDAAKCRCKUSxrWUTBDOojB/d2q7tPLcT5ul+PsZD+MIMCvCVYRJ61BWyR 24 | paryecuAzKruA6X9yL7alXO8E97C71uaIvWXSkAQCwmN30ZVfoyzAiY6XWELBlB2 25 | IQDaCccE++Q8FdfgS1XAOjrX3mEWkhU/3wXieKYCby0+fMs47pqg3UZleIjPlAD9 26 | GPjMY1OYSQQT9WQA1YMvN2Y7xgN29UUBgJmHTe6ZVLqd65gOPwxITXtbemTItKR6 27 | jVhojmOnfGw2Pcw8VRgHuJ+c1Co8Ujc3tHqX9n/FwynGAjoDiL6GM0tUdNnY/AD3 28 | xnK68BFl76Wo14u6cHGBb5c4JzE60/eEoaE1rMNDvxvuGmiXb7Q= 29 | =aRr/ 30 | -----END PGP PUBLIC KEY BLOCK----- 31 | -------------------------------------------------------------------------------- /src/commander.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2018 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _COMMANDER_H_ 29 | #define _COMMANDER_H_ 30 | 31 | 32 | #include 33 | #include "memory.h" 34 | 35 | 36 | void commander_clear_report(void); 37 | const char *commander_read_report(void); 38 | const char *commander_read_array(void); 39 | void commander_fill_report(const char *attr, const char *val, int err); 40 | int commander_fill_signature_array(const uint8_t *sig, uint8_t recid); 41 | int commander_fill_json_array(const char **key, const char **value, int *type, 42 | int cmd); 43 | void commander_force_reset(void); 44 | char *commander(const char *command); 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/size.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_size 10 | 11 | 12 | 13 | 14 |
15 |

f_size

16 |

The f_size function gets the size of a file.

17 |
18 | DWORD f_size (
19 |   FIL* FileObject   /* File object */
20 | );
21 | 
22 |
23 | 24 | 25 |
26 |

Parameters

27 |
28 |
FileObject
29 |
Pointer to the open file object structure.
30 |
31 |
32 | 33 | 34 |
35 |

Return Values

36 |

Returns the size of the file in unit of byte.

37 |
38 | 39 | 40 |
41 |

Description

42 |

In this revision, the f_size function is implemented as a macro.

43 |
44 | #define f_size(fp) ((fp)->fsize)
45 | 
46 |
47 | 48 | 49 |
50 |

QuickInfo

51 |

Always available.

52 |
53 | 54 | 55 |
56 |

See Also

57 |

f_open, f_lseek, FIL

58 |
59 | 60 |

Return

61 | 62 | 63 | -------------------------------------------------------------------------------- /src/systick.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #include 29 | #include 30 | #include "systick.h" 31 | #include "drivers/config/mcu.h" 32 | 33 | volatile uint16_t systick_current_time_ms = 0u; 34 | volatile uint8_t systick_time_updated = 0u; 35 | uint16_t systick_measurement_period_msec = 25u; 36 | 37 | 38 | void systick_update_time(void) 39 | { 40 | systick_time_updated = 1u; 41 | systick_current_time_ms += systick_measurement_period_msec; 42 | } 43 | 44 | 45 | // Configure timer ISR to fire regularly 46 | void systick_init(void) 47 | { 48 | SysTick_Config((sysclk_get_cpu_hz() / 1000) * systick_measurement_period_msec); 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_error 10 | 11 | 12 | 13 | 14 |
15 |

f_error

16 |

The f_error tests for an error on a file.

17 |
18 | int f_error (
19 |   FIL* FileObject   /* File object */
20 | );
21 | 
22 |
23 | 24 | 25 |
26 |

Parameters

27 |
28 |
FileObject
29 |
Pointer to the open file object structure.
30 |
31 |
32 | 33 | 34 |
35 |

Return Values

36 |

Returns a non-zero value if an error has occured; otherwise it returns a zero.

37 |
38 | 39 | 40 |
41 |

Description

42 |

In this revision, the f_error function is implemented as a macro.

43 |
44 | #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
45 | 
46 |
47 | 48 | 49 |
50 |

QuickInfo

51 |

Always available.

52 |
53 | 54 | 55 |
56 |

See Also

57 |

f_open, FIL

58 |
59 | 60 |

Return

61 | 62 | 63 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/tell.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_tell 10 | 11 | 12 | 13 | 14 |
15 |

f_tell

16 |

The f_tell function gets the current read/write pointer of a file.

17 |
18 | DWORD f_tell (
19 |   FIL* FileObject   /* File object */
20 | );
21 | 
22 |
23 | 24 | 25 |
26 |

Parameters

27 |
28 |
FileObject
29 |
Pointer to the open file object structure.
30 |
31 |
32 | 33 | 34 |
35 |

Return Values

36 |

Returns current read/write pointer of the file.

37 |
38 | 39 | 40 |
41 |

Description

42 |

In this revision, the f_tell function is implemented as a macro.

43 |
44 | #define f_tell(fp) ((fp)->fptr)
45 | 
46 |
47 | 48 | 49 |
50 |

QuickInfo

51 |

Always available.

52 |
53 | 54 | 55 |
56 |

See Also

57 |

f_open, f_lseek, FIL

58 |
59 | 60 |

Return

61 | 62 | 63 | -------------------------------------------------------------------------------- /src/u2f/genkeys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | err_report() { 4 | printf "\n** ERROR on line $1 due to known bug.\n** Remove 'dbbdev.key' and run the script again.\n\n" 5 | exit 6 | } 7 | 8 | trap 'err_report $LINENO' ERR 9 | 10 | 11 | cat > u2f_keys.h < 16 | 17 | const uint8_t U2F_ATT_PRIV_KEY[] = { 18 | EOF 19 | 20 | if [ \! -e dbbdev.key ]; then 21 | openssl ecparam -genkey -out dbbdev.key -name prime256v1 22 | fi 23 | 24 | # This command sometimes appends 0x00 to the private key, 25 | # giving an incorrect length of 33 bytes. 26 | # The script will abort if this occurs. Just rerun. 27 | openssl ec -in dbbdev.key -text | 28 | perl -e '$key = "\t"; while (<>) { 29 | if (/priv:/) { $priv = 1 } 30 | elsif (/pub:/) { $priv = 0 } 31 | elsif ($priv) { 32 | while ($_ =~ s/.*?([0-9a-f]{2})//) { 33 | $key .= "0x$1,"; 34 | if ($num++ % 8 == 7) { $key .= "\n\t"; } 35 | else {$key .= " ";} 36 | if ($num == 33) { exit 1;} 37 | } 38 | } 39 | } 40 | $key =~ s/,\s*$/\n/s; 41 | print $key;' >> u2f_keys.h 42 | 43 | cat >> u2f_keys.h <> u2f_keys.h 53 | 54 | cat >> u2f_keys.h < 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 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/eof.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_eof 10 | 11 | 12 | 13 | 14 |
15 |

f_eof

16 |

The f_eof function tests for end-of-file on a file.

17 |
18 | int f_eof (
19 |   FIL* FileObject   /* File object */
20 | );
21 | 
22 |
23 | 24 | 25 |
26 |

Parameters

27 |
28 |
FileObject
29 |
Pointer to the open file object structure.
30 |
31 |
32 | 33 | 34 |
35 |

Return Values

36 |

The f_eof function returns a non-zero value if the read/write pointer has reached end of the file; otherwise it returns a zero.

37 |
38 | 39 | 40 |
41 |

Description

42 |

In this revision, the f_eof function is implemented as a macro.

43 |
44 | #define f_eof(fp) (((fp)->fptr) == ((fp)->fsize) ? 1 : 0)
45 | 
46 |
47 | 48 | 49 |
50 |

QuickInfo

51 |

Always available.

52 |
53 | 54 | 55 |
56 |

See Also

57 |

f_open, f_lseek, FIL

58 |
59 | 60 |

Return

61 | 62 | 63 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/dinit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - disk_initialize 10 | 11 | 12 | 13 | 14 |
15 |

disk_initialize

16 |

The disk_initialize function initializes the disk drive.

17 |
18 | DSTATUS disk_initialize (
19 |   BYTE Drive           /* Physical drive number */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameter

26 |
27 |
Drive
28 |
Specifies the physical drive number to initialize.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

This function returns a disk status as the result. For details of the disk status, refer to the disk_status function.

36 |
37 | 38 |
39 |

Description

40 |

The disk_initialize function initializes a physical drive and put it ready to read/write. When the function succeeded, STA_NOINIT flag in the return value is cleard.

41 |

Application program MUST NOT call this function, or FAT structure on the volume can be corrapted. To re-initialize the file system, use f_mount function.This function is called on volume mount process in the FatFs module to manage the media change.

42 |
43 | 44 |

Return

45 | 46 | 47 | -------------------------------------------------------------------------------- /src/flags.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #include "flags.h" 29 | 30 | 31 | #define X(a) #a, 32 | const char *const CMD_STR[] = { CMD_TABLE }; 33 | #undef X 34 | 35 | #define X(a) #a, 36 | const char *const ATTR_STR[] = { ATTR_TABLE }; 37 | #undef X 38 | 39 | #define X(a, b, c) #b, 40 | const char *const FLAG_CODE[] = { FLAG_TABLE }; 41 | #undef X 42 | 43 | #define X(a, b, c) c, 44 | const char *const FLAG_MSG[] = { FLAG_TABLE }; 45 | #undef X 46 | 47 | const char *cmd_str(int cmd) 48 | { 49 | return CMD_STR[cmd]; 50 | } 51 | 52 | 53 | const char *attr_str(int attr) 54 | { 55 | return ATTR_STR[attr]; 56 | } 57 | 58 | 59 | const char *flag_code(int flag) 60 | { 61 | return FLAG_CODE[flag]; 62 | } 63 | 64 | 65 | const char *flag_msg(int flag) 66 | { 67 | return FLAG_MSG[flag]; 68 | } 69 | -------------------------------------------------------------------------------- /tests/generate_base64_testcases.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import argparse 3 | import base64 4 | import os 5 | import random 6 | import struct 7 | import sys 8 | 9 | def main(): 10 | parser = argparse.ArgumentParser(description='Generate random test cases for the base64 unit test.') 11 | parser.add_argument('--count', default=1000, type=int, help='Number of test cases to generate') 12 | parser.add_argument('--maxSize', default=1000, type=int, help='Maximum (binary) size of each test case') 13 | parser.add_argument('--seed', default=1234, type=int, help='Seed for the RNG.') 14 | parser.add_argument('--output', required=True, type=str, help='Output file') 15 | args = parser.parse_args() 16 | print("Generating {} test cases".format(args.count)) 17 | print("Setting the random seed to {}".format(args.seed)) 18 | random.seed(args.seed) 19 | testCases = [] 20 | for i in range(args.count): 21 | testCaseSize = random.randrange(0, args.maxSize) 22 | testCaseBinary = os.urandom(testCaseSize) 23 | assert(len(testCaseBinary) == testCaseSize) 24 | testCases.append((testCaseBinary, base64.b64encode(testCaseBinary))) 25 | assert(len(testCases) == args.count) 26 | # Now dump the test data to file. 27 | # File format: 28 | # - Two bytes length of the binary string (little endian) 29 | # - Binary string 30 | # - Two bytes length of the encoded string (little endian, no null terminator) 31 | # - Encoded string (no null terminator) 32 | with open(args.output, 'wb') as f: 33 | f.write(struct.pack(' 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - disk_status 10 | 11 | 12 | 13 | 14 |
15 |

disk_status

16 |

The disk_status function returns the current disk status.

17 |
18 | DSTATUS disk_status (
19 |   BYTE Drive     /* Physical drive number */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameter

26 |
27 |
Drive
28 |
Specifies the physical drive number to be confirmed.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

The disk status is returned in combination of following flags. FatFs refers only STA_NOINIT and STA_PROTECTED.

36 |
37 |
STA_NOINIT
38 |
Indicates that the disk drive has not been initialized. This flag is set on: system reset, disk removal and disk_initialize function failed, and cleared on: disk_initialize function succeeded.
39 |
STA_NODISK
40 |
Indicates that no medium in the drive. This is always cleared on fixed disk drive.
41 |
STA_PROTECTED
42 |
Indicates that the medium is write protected. This is always cleared on the drive that does not support write protect notch. Not valid when STA_NODISK is set.
43 |
44 |
45 | 46 |

Return

47 | 48 | 49 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/chdrive.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_chdrive 10 | 11 | 12 | 13 | 14 |
15 |

f_chdrive

16 |

The f_chdrive function changes the current drive.

17 |
18 | FRESULT f_chdrive (
19 |   BYTE Drive /* Logical drive number */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameters

26 |
27 |
Drive
28 |
Specifies the logical drive number to be set as the current drive.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

36 | FR_OK, 37 | FR_INVALID_DRIVE 38 |

39 |
40 | 41 | 42 |
43 |

Description

44 |

The f_chdrive function changes the current drive. The initial value of the current drive number is 0. Note that the current drive is retained in a static variable so that it also affects other tasks that using the file functions.

45 |
46 | 47 |
48 |

QuickInfo

49 |

Available when _FS_RPATH >= 1.

50 |
51 | 52 | 53 |
54 |

See Also

55 |

f_chdir, f_getcwd

56 |
57 | 58 |

Return

59 | 60 | 61 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/sdir.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - DIR 10 | 11 | 12 | 13 | 14 |
15 |

DIR

16 |

The DIR structure is used for the work area to read a directory by f_oepndir, f_readdir function. There is no member that can be changed by application.

17 |
18 | typedef struct {
19 |     FATFS*  fs;         /* Pointer to the owner file system object */
20 |     WORD    id;         /* Owner file system mount ID */
21 |     WORD    index;      /* Directory index number to be read/write next */
22 |     DWORD   sclust;     /* Table start cluster (0:Root dir) */
23 |     DWORD   clust;      /* Current cluster */
24 |     DWORD   sect;       /* Current sector */
25 |     BYTE*   dir;        /* Pointer to the current SFN entry in the win[] */
26 |     BYTE*   fn;         /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
27 | #if _USE_LFN
28 |     WCHAR*  lfn;        /* Pointer to the LFN working buffer */
29 |     WORD    lfn_idx;    /* Last matched LFN index (0xFFFF:No LFN) */
30 | #endif
31 | } DIR;
32 | 
33 |
34 | 35 |

Return

36 | 37 | 38 | -------------------------------------------------------------------------------- /src/secp256k1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | // Provides secp256k1 access in libbitbox.a, as required by the test 29 | // functions. Then, the secp256k1/ submodule code is left 'as is'. 30 | 31 | 32 | #ifdef __GNUC__ 33 | #pragma GCC diagnostic push 34 | #pragma GCC diagnostic ignored "-Wcast-qual" 35 | #pragma GCC diagnostic ignored "-Wswitch-default" 36 | #endif 37 | #ifdef __clang__ 38 | #pragma clang diagnostic push 39 | #pragma clang diagnostic ignored "-Wswitch-default" 40 | #endif 41 | 42 | 43 | #define USE_ECMULT_STATIC_PRECOMPUTATION 1 44 | #define ENABLE_MODULE_ECDH 1 45 | #define USE_BASIC_CONFIG 1 46 | #define ENABLE_MODULE_RECOVERY 1 47 | 48 | #include "secp256k1/src/basic-config.h" 49 | #include "secp256k1/src/secp256k1.c" 50 | 51 | #ifdef __GNUC__ 52 | #pragma GCC diagnostic pop 53 | #endif 54 | #ifdef __clang__ 55 | #pragma clang diagnostic pop 56 | #endif 57 | -------------------------------------------------------------------------------- /src/ataes132.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2017 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _AES132_H_ 29 | #define _AES132_H_ 30 | 31 | 32 | #include 33 | 34 | 35 | #define ATAES_RAND_LEN 0x10 36 | #define ATAES_CMD_RAND 0x02 37 | #define ATAES_CMD_LOCK 0x0D 38 | 39 | #ifdef TESTING 40 | #define ATAES_EEPROM_LEN 0x1000 41 | #define ATAES_EEPROM_ZONE_LEN 0x100 42 | #define ATAES_EEPROM_ZONE_NUM (ATAES_EEPROM_LEN / ATAES_EEPROM_ZONE_LEN) 43 | uint8_t *ataes_eeprom_simulation_report(void); 44 | void ataes_eeprom_simulation_clear(void); 45 | void ataes_eeprom_simulation_write(const uint8_t *data, uint16_t start, uint16_t len); 46 | #endif 47 | int ataes_process(uint8_t const *command, uint16_t cmd_len, uint8_t *response_block, 48 | uint16_t response_len); 49 | int ataes_eeprom(uint16_t LEN, uint32_t ADDR, uint8_t *userdata_read, 50 | const uint8_t *userdata_write); 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Dockerfile.dev: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright 2019 Shift Cryptosecurity AG 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the "Software"), 7 | # to deal in the Software without restriction, including without limitation 8 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | # and/or sell copies of the Software, and to permit persons to whom the 10 | # Software is furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included 13 | # in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 19 | # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | # OTHER DEALINGS IN THE SOFTWARE. 22 | # 23 | # Run with Docker: 24 | # docker build --tag shift/mcu-base -f Dockerfile.dev . 25 | # 26 | 27 | FROM debian:stretch 28 | 29 | RUN apt update && apt-get install -y cmake git wget locales python python-pip 30 | RUN mkdir ~/Downloads && cd ~/Downloads && wget -O gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2019q3/RC1.1/gcc-arm-none-eabi-8-2019-q3-update-linux.tar.bz2 31 | RUN cd ~/Downloads && tar -xjvf gcc.tar.bz2 32 | RUN cd ~/Downloads && rsync -a gcc-arm-none-eabi-8-2019-q3-update/ /usr/local/ 33 | RUN apt install -y libbz2-1.0 libncurses5 libz1 valgrind astyle clang libudev-dev python-urllib3 libssl1.0-dev 34 | RUN apt install -y libbz2-dev libbz2-dev libbz2-1.0 libncurses5 libz1 valgrind astyle clang libudev-dev python-urllib3 35 | RUN pip install --prefix /usr/local cpp-coveralls 36 | RUN locale-gen UTF-8 37 | ENV CC gcc 38 | 39 | CMD ["bash"] 40 | -------------------------------------------------------------------------------- /src/u2f_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016-2017 Douglas J. Bakkum, Shift Devices AG 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef __U2F_DEVICE_H__ 29 | #define __U2F_DEVICE_H__ 30 | 31 | 32 | #include 33 | #include 34 | #include "usb.h" 35 | #include "u2f/u2f.h" 36 | 37 | 38 | #define U2F_HIJACK_ORIGIN_TOTAL 4 39 | 40 | 41 | extern const uint8_t U2F_HIJACK_CODE[U2F_HIJACK_ORIGIN_TOTAL][U2F_APPID_SIZE]; 42 | 43 | typedef enum HIJACK_STATE { 44 | // Do not change the order! 45 | // Order affects third party integrations that make use of the hijack mode 46 | HIJACK_STATE_RESPONSE_READY, 47 | HIJACK_STATE_PROCESSING_COMMAND, 48 | HIJACK_STATE_INCOMPLETE_COMMAND, 49 | HIJACK_STATE_IDLE, 50 | } HIJACK_STATE; 51 | 52 | 53 | void u2f_queue_message(const uint8_t *data, const uint32_t len); 54 | void u2f_queue_error_hid(uint32_t fcid, uint8_t err); 55 | void u2f_device_run(const USB_FRAME *f); 56 | void u2f_device_timeout(void); 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/bip32.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013-2014 Tomas Dzetkulic 3 | * Copyright (c) 2013-2014 Pavol Rusnak 4 | * Copyright (c) 2015-2016 Douglas J. Bakkum 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 20 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | * OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | 26 | #ifndef _BIP32_H_ 27 | #define _BIP32_H_ 28 | 29 | 30 | #include 31 | 32 | 33 | typedef struct { 34 | uint32_t depth; 35 | uint32_t fingerprint; 36 | uint32_t child_num; 37 | uint8_t chain_code[32]; 38 | uint8_t private_key[32]; 39 | uint8_t public_key[33]; 40 | } HDNode; 41 | 42 | 43 | #define hdnode_private_ckd_prime(X, I) hdnode_private_ckd((X), ((I) | 0x80000000)) 44 | 45 | 46 | int hdnode_from_seed(const uint8_t *seed, int seed_len, HDNode *out); 47 | int hdnode_private_ckd(HDNode *inout, uint32_t i); 48 | void hdnode_fill_public_key(HDNode *node); 49 | void hdnode_serialize_public(const HDNode *node, char *str, int strsize); 50 | void hdnode_serialize_private(const HDNode *node, char *str, int strsize); 51 | int hdnode_deserialize(const char *str, HDNode *node); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/drivers/config/conf_sleepmgr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Chip-specific sleep manager configuration 5 | * 6 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | #ifndef CONF_SLEEPMGR_H 44 | #define CONF_SLEEPMGR_H 45 | 46 | // Sleep manager options 47 | #define CONFIG_SLEEPMGR_ENABLE 48 | 49 | #endif /* CONF_SLEEPMGR_H */ 50 | -------------------------------------------------------------------------------- /src/drivers/sam/utils/preprocessor/preprocessor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Preprocessor utils. 5 | * 6 | * Copyright (c) 2010-2012 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef _PREPROCESSOR_H_ 45 | #define _PREPROCESSOR_H_ 46 | 47 | #include "tpaste.h" 48 | #include "stringz.h" 49 | #include "mrepeat.h" 50 | 51 | 52 | #endif // _PREPROCESSOR_H_ 53 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/truncate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_truncate 10 | 11 | 12 | 13 | 14 |
15 |

f_truncate

16 |

The f_truncate function truncates the file size.

17 |
18 | FRESULT f_truncate (
19 |   FIL* FileObject     /* Pointer to the file object */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameter

26 |
27 |
FileObject
28 |
Pointer to the open file object to be truncated.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

36 | FR_OK, 37 | FR_DISK_ERR, 38 | FR_INT_ERR, 39 | FR_NOT_READY, 40 | FR_INVALID_OBJECT, 41 | FR_TIMEOUT 42 |

43 |
44 | 45 | 46 |
47 |

Description

48 |

The f_truncate function truncates the file size to the current file read/write point. This function has no effect if the file read/write pointer is already pointing end of the file.

49 |
50 | 51 | 52 |
53 |

QuickInfo

54 |

Available when _FS_READONLY == 0 and _FS_MINIMIZE == 0.

55 |
56 | 57 | 58 |
59 |

See Also

60 |

f_open, f_lseek, FIL

61 |
62 | 63 | 64 |

Return

65 | 66 | 67 | -------------------------------------------------------------------------------- /src/bootloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _BOOTLOADER_H_ 29 | #define _BOOTLOADER_H_ 30 | 31 | 32 | #include 33 | 34 | 35 | #define BOOT_SIG_M 4 36 | 37 | 38 | typedef enum BOOT_OP_CODES { 39 | OP_WRITE = 'w',/* 0x77 */ 40 | OP_ERASE = 'e',/* 0x65 */ 41 | OP_BLINK = 'b',/* 0x62 */ 42 | OP_REBOOT = 'r',/* 0x72 */ 43 | OP_VERIFY = 's',/* 0x73 */ 44 | OP_VERSION = 'v', /* 0x76 */ 45 | OP_LOCK = 'l' /* 0x108 */ 46 | } BOOT_OP_CODES; 47 | 48 | typedef enum BOOT_STATUS { 49 | OP_STATUS_ERR = 'Z', 50 | OP_STATUS_ERR_VERSION = 'V', 51 | OP_STATUS_ERR_LEN = 'N', 52 | OP_STATUS_ERR_MACRO = 'M', 53 | OP_STATUS_ERR_WRITE = 'W', 54 | OP_STATUS_ERR_CHECK = 'C', 55 | OP_STATUS_ERR_ABORT = 'A', 56 | OP_STATUS_ERR_ERASE = 'E', 57 | OP_STATUS_ERR_LOAD_FLAG = 'L', 58 | OP_STATUS_ERR_INVALID_CMD = 'I', 59 | OP_STATUS_OK = '0' 60 | } BOOT_STATUS; 61 | 62 | 63 | void bootloader_jump(void); 64 | void bootloader_command(const char *command); 65 | 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/cipher.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2018 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _CIPHER_H_ 29 | #define _CIPHER_H_ 30 | 31 | 32 | #include 33 | 34 | 35 | char *cipher_aes_b64_hmac_encrypt(const unsigned char *in, int inlen, 36 | int *out_b64len, const uint8_t *secret); 37 | 38 | uint8_t *cipher_aes_hmac_encrypt(const unsigned char *in, int inlen, 39 | int *out_b64len, const uint8_t *secret); 40 | 41 | char *cipher_aes_b64_encrypt(const unsigned char *in, int inlen, 42 | int *out_b64len, const uint8_t *key); 43 | 44 | char *cipher_aes_b64_hmac_decrypt(const unsigned char *in, int inlen, int *out_msg_len, 45 | const uint8_t *secret); 46 | 47 | char *cipher_aes_b64_decrypt(const unsigned char *in, int inlen, 48 | int *outlen, const uint8_t *key); 49 | 50 | char *cipher_aes_hmac_decrypt(const uint8_t *in, int inlen, 51 | int *outlen, const uint8_t *key); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/drivers/common/services/sleepmgr/sam/sleepmgr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief SAM3/SAM4 Sleep manager implementation. 5 | * 6 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | 47 | #if defined(CONFIG_SLEEPMGR_ENABLE) || defined(__DOXYGEN__) 48 | 49 | uint8_t sleepmgr_locks[SLEEPMGR_NR_OF_MODES]; 50 | 51 | #endif /* CONFIG_SLEEPMGR_ENABLE */ 52 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/close.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_close 10 | 11 | 12 | 13 | 14 |
15 |

f_close

16 |

The f_close function closes an open file.

17 |
18 | FRESULT f_close (
19 |   FIL* FileObject     /* Pointer to the file object structure */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameter

26 |
27 |
FileObject
28 |
Pointer to the open file object structure to be closed.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

36 | FR_OK, 37 | FR_DISK_ERR, 38 | FR_INT_ERR, 39 | FR_NOT_READY, 40 | FR_INVALID_OBJECT, 41 | FR_TIMEOUT 42 |

43 |
44 | 45 | 46 |
47 |

Description

48 |

The f_close function closes an open file object. If any data has been written to the file, the cached information of the file is written back to the disk. After the function succeeded, the file object is no longer valid and it can be discarded.

49 |
50 | 51 | 52 |
53 |

QuickInfo

54 |

Always available.

55 |
56 | 57 | 58 |
59 |

See Also

60 |

f_open, f_read, f_write, f_sync, FIL, FATFS

61 |
62 | 63 |

Return

64 | 65 | 66 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2018 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _UTILS_H_ 29 | #define _UTILS_H_ 30 | 31 | 32 | #include 33 | #include 34 | #include 35 | #include "memory.h" 36 | 37 | 38 | #define UTILS_BUFFER_LEN COMMANDER_REPORT_SIZE 39 | #define VARINT_LEN 20 40 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 41 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 42 | #define strlens(s) (s == NULL ? 0 : strlen(s)) 43 | #define STREQ(a, b) (strcmp((a), (b)) == 0) 44 | #define MEMEQ(a, b, c) (memcmp((a), (b), (c)) == 0) 45 | 46 | 47 | volatile void *utils_zero(volatile void *dst, size_t len); 48 | void utils_clear_buffers(void); 49 | uint8_t utils_is_hex(const char *str); 50 | uint8_t utils_limit_alphanumeric_hyphen_underscore_period(const char *str); 51 | uint8_t *utils_hex_to_uint8(const char *str); 52 | char *utils_uint8_to_hex(const uint8_t *bin, size_t l); 53 | void utils_reverse_hex(char *h, int len); 54 | void utils_reverse_bin(uint8_t *b, int len); 55 | void utils_uint64_to_varint(char *vi, int *l, uint64_t i); 56 | int utils_varint_to_uint64(const char *vi, uint64_t *i); 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /tests/tests_secp256k1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifdef __GNUC__ 29 | #pragma GCC diagnostic push 30 | #pragma GCC diagnostic ignored "-Wcast-qual" 31 | #pragma GCC diagnostic ignored "-Wswitch-default" 32 | #pragma GCC diagnostic ignored "-Wmissing-prototypes" 33 | 34 | #ifndef __has_warning // not defined in GCC 35 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 36 | #else 37 | #if __has_warning("-Wmaybe-uninitialized") 38 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 39 | #endif 40 | #endif 41 | 42 | #endif 43 | #ifdef __clang__ 44 | #pragma clang diagnostic push 45 | #pragma clang diagnostic ignored "-Wcast-qual" 46 | #pragma clang diagnostic ignored "-Wmissing-prototypes" 47 | #endif 48 | 49 | 50 | #define USE_ECMULT_STATIC_PRECOMPUTATION 1 51 | #define ENABLE_MODULE_RECOVERY 1 52 | #define ENABLE_MODULE_ECDH 1 53 | #define USE_BASIC_CONFIG 1 54 | #define VERIFY 1 55 | 56 | 57 | #include "../src/secp256k1/src/basic-config.h" 58 | #include "../src/secp256k1/src/tests.c" 59 | 60 | 61 | #ifdef __GNUC__ 62 | #pragma GCC diagnostic pop 63 | #endif 64 | #ifdef __clang__ 65 | #pragma clang diagnostic pop 66 | #endif 67 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/getcwd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_getcwd 10 | 11 | 12 | 13 | 14 |
15 |

f_getcwd

16 |

The f_getcwd function retrieves the current directory.

17 |
18 | FRESULT f_getcwd (
19 |   TCHAR* Buffer,  /* Pointer to the buffer */
20 |   UINT BufferLen  /* The length of the buffer */
21 | );
22 | 
23 |
24 | 25 |
26 |

Parameters

27 |
28 |
Buffer
29 |
Pointer to the buffer to receive the current directory string.
30 |
BufferLen
31 |
Size of the buffer in unit of TCHAR.
32 |
33 |
34 | 35 | 36 |
37 |

Return Values

38 |

39 | FR_OK, 40 | FR_DISK_ERR, 41 | FR_INT_ERR, 42 | FR_NOT_READY, 43 | FR_NOT_ENABLED, 44 | FR_NO_FILESYSTEM, 45 | FR_TIMEOUT, 46 | FR_NOT_ENOUGH_CORE 47 |

48 |
49 | 50 | 51 |
52 |

Description

53 |

The f_getcwd function retrieves the current directory of the current drive in full path string including drive number.

54 |
55 | 56 | 57 |
58 |

QuickInfo

59 |

Available when _FS_RPATH == 2.

60 |
61 | 62 | 63 |
64 |

See Also

65 |

f_chdrive, f_chdir

66 |
67 | 68 |

Return

69 | 70 | 71 | -------------------------------------------------------------------------------- /src/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 2014 Douglas J Bakkum 3 | * Split into .h and .c files. 4 | */ 5 | 6 | /* 7 | 8 | https://github.com/superwills/NibbleAndAHalf 9 | base64.h -- Fast base64 encoding and decoding. 10 | version 1.0.0, April 17, 2013 143a 11 | 12 | Copyright (C) 2013 William Sherif 13 | 14 | This software is provided 'as-is', without any express or implied 15 | warranty. In no event will the authors be held liable for any damages 16 | arising from the use of this software. 17 | 18 | Permission is granted to anyone to use this software for any purpose, 19 | including commercial applications, and to alter it and redistribute it 20 | freely, subject to the following restrictions: 21 | 22 | 1. The origin of this software must not be misrepresented; you must not 23 | claim that you wrote the original software. If you use this software 24 | in a product, an acknowledgment in the product documentation would be 25 | appreciated but is not required. 26 | 2. Altered source versions must be plainly marked as such, and must not be 27 | misrepresented as being the original software. 28 | 3. This notice may not be removed or altered from any source distribution. 29 | 30 | William Sherif 31 | will.sherif@gmail.com 32 | 33 | YWxsIHlvdXIgYmFzZSBhcmUgYmVsb25nIHRvIHVz 34 | 35 | */ 36 | #ifndef _BASE64_H_ 37 | #define _BASE64_H_ 38 | 39 | /** 40 | * Converts binary data of length=len to base64 characters. 41 | * 42 | * @param[in] binaryData Binary buffer to encode. Must be len bytes long. 43 | * @paramm[in] len Length of the binaryData buffer. 44 | * @param[out] flen Resulting length of the encoded buffer. 45 | * @return Decoded buffer, or NULL if an error occurred. Must be free()'d by the 46 | * caller. 47 | */ 48 | char *base64(const void *binaryData, int len, int *flen); 49 | 50 | /** 51 | * Decodes the provided base64 string. 52 | * 53 | * @param[in] ascii Base64-encoded buffer to decoded. Must contain a 54 | * zero-terminated string. 55 | * @param[in] len Length of the string to decode (excluding the terminating 56 | * character). 57 | * @param[out] flen Resulting length of the decoded buffer. 58 | * @return Decoded buffer, or NULL if an error occurred. Must be free()'d by the 59 | * caller. 60 | */ 61 | unsigned char *unbase64( const char *ascii, int len, int *flen ); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/drivers/common/services/delay/sam/cycle_counter.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief ARM functions for busy-wait delay loops 5 | * 6 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #include "cycle_counter.h" 45 | 46 | // Delay loop is put to SRAM so that FWS will not affect delay time 47 | OPTIMIZE_HIGH 48 | RAMFUNC 49 | void portable_delay_cycles(unsigned long n) 50 | { 51 | UNUSED(n); 52 | 53 | __asm ( 54 | "loop: DMB \n" 55 | "SUBS R0, R0, #1 \n" 56 | "BNE.N loop " 57 | ); 58 | } 59 | -------------------------------------------------------------------------------- /src/u2f/u2f_keys.h: -------------------------------------------------------------------------------- 1 | #ifndef __U2F_KEYS_H_INCLUDED__ 2 | #define __U2F_KEYS_H_INCLUDED__ 3 | 4 | #include 5 | 6 | const uint8_t U2F_ATT_PRIV_KEY[] = { 7 | 0x74, 0xa4, 0x04, 0x25, 0xcc, 0x7b, 0x8c, 0xcd, 8 | 0x48, 0x3d, 0xe2, 0xff, 0xd8, 0xc6, 0xa5, 0xc7, 9 | 0xdb, 0x4e, 0x6f, 0x56, 0xe1, 0xdb, 0x9a, 0xcb, 10 | 0x5a, 0x43, 0xda, 0x12, 0x42, 0xa8, 0xf4, 0xcf 11 | }; 12 | 13 | const uint8_t U2F_ATT_CERT[] = { 14 | 0x30, 0x82, 0x01, 0x28, 0x30, 0x81, 0xcf, 0x02, 0x09, 0x00, 0xb8, 0x9e, 0xe4, 0x7e, 0x99, 0x53, 15 | 0x83, 0x34, 0x30, 0x09, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x01, 0x30, 0x1d, 0x31, 16 | 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x12, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 17 | 0x6c, 0x20, 0x42, 0x69, 0x74, 0x62, 0x6f, 0x78, 0x20, 0x55, 0x32, 0x46, 0x30, 0x1e, 0x17, 0x0d, 18 | 0x31, 0x37, 0x30, 0x32, 0x31, 0x38, 0x31, 0x35, 0x34, 0x30, 0x30, 0x35, 0x5a, 0x17, 0x0d, 0x33, 19 | 0x37, 0x30, 0x32, 0x31, 0x33, 0x31, 0x35, 0x34, 0x30, 0x30, 0x35, 0x5a, 0x30, 0x1d, 0x31, 0x1b, 20 | 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x12, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 21 | 0x20, 0x42, 0x69, 0x74, 0x62, 0x6f, 0x78, 0x20, 0x55, 0x32, 0x46, 0x30, 0x59, 0x30, 0x13, 0x06, 22 | 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 23 | 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x37, 0x71, 0xa1, 0xa7, 0x23, 0x7e, 0x69, 0x0a, 0x72, 0x77, 24 | 0x17, 0x7d, 0x71, 0x60, 0x41, 0x2a, 0x55, 0x90, 0xfc, 0xb9, 0xd6, 0xbf, 0x93, 0x8a, 0x6e, 0x8e, 25 | 0xa9, 0x3f, 0xe6, 0x17, 0xb4, 0x1e, 0xc0, 0xc7, 0x6a, 0xad, 0x35, 0xe8, 0x10, 0x89, 0x1f, 0x48, 26 | 0xdf, 0x19, 0x35, 0xe1, 0xef, 0x74, 0x4f, 0xb7, 0xba, 0xf6, 0x6f, 0x5e, 0xad, 0x93, 0x01, 0xaf, 27 | 0xf4, 0x57, 0x0d, 0x6b, 0x11, 0x18, 0x30, 0x09, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 28 | 0x01, 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xc1, 0x4e, 0x00, 0x66, 0x7a, 0x0f, 0xbf, 29 | 0xd1, 0x1e, 0x1e, 0xa3, 0xca, 0xb1, 0x9e, 0x31, 0x3f, 0xb1, 0x6a, 0x04, 0xc3, 0xd9, 0x96, 0x58, 30 | 0x71, 0xda, 0x0b, 0x14, 0x84, 0x94, 0x05, 0xdd, 0x28, 0x02, 0x21, 0x00, 0xe6, 0xff, 0x72, 0x7c, 31 | 0xcc, 0xf5, 0x21, 0x63, 0x71, 0x78, 0x51, 0xa7, 0x16, 0x46, 0x10, 0xda, 0x63, 0xaa, 0xb9, 0x30, 32 | 0xe9, 0xc1, 0x1b, 0xff, 0x27, 0xc9, 0xbf, 0x2f, 0x4b, 0x6f, 0xc2, 0x0d, 33 | 34 | }; 35 | 36 | #endif // __U2F_KEYS_H_INCLUDED__ 37 | -------------------------------------------------------------------------------- /doc/BB01_logo_github.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 25 | 28 | 31 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/drivers/config/conf_sd_mmc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief SD/MMC stack configuration file. 5 | * 6 | * Copyright (c) 2012 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef CONF_SD_MMC_H_INCLUDED 45 | #define CONF_SD_MMC_H_INCLUDED 46 | 47 | // Define to enable the SPI mode instead of Multimedia Card interface mode 48 | #define SD_MMC_SPI_MODE 49 | 50 | // Define to enable the SDIO support 51 | #define SDIO_SUPPORT_ENABLE 52 | 53 | // Define to enable the debug trace to the current standard output (stdio) 54 | //#define SD_MMC_DEBUG 55 | 56 | #endif /* CONF_SD_MMC_H_INCLUDED */ 57 | 58 | -------------------------------------------------------------------------------- /src/touch.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #ifndef _TOUCH_H_ 29 | #define _TOUCH_H_ 30 | 31 | #include 32 | 33 | #define QTOUCH_TOUCH_TIMEOUT 3000// msec 34 | #define QTOUCH_TOUCH_TIMEOUT_U2F 1900// msec 35 | #define QTOUCH_TOUCH_TIMEOUT_HARD 30000 36 | #define QTOUCH_TOUCH_BLINK_ON 4000 37 | #define QTOUCH_TOUCH_BLINK_OFF 300 38 | #define QTOUCH_TOUCH_THRESH_HW_V1_2 18 39 | #define QTOUCH_TOUCH_THRESH 15 // hw version 1 / unknown 40 | #ifndef TESTING 41 | #define QTOUCH_TOUCH_CHANNEL CHANNEL_9 42 | #define QTOUCH_LIB_TYPE_MASK 0x01 43 | #define QTOUCH_LIB_COMPILER_OFFSET 2 44 | #define QTOUCH_LIB_COMPILER_MASK 0x01 45 | #define QTOUCH_LIB_MAX_CHANNEL_OFFSET 3 46 | #define QTOUCH_LIB_MAX_CHANNEL_MASK 0x7F 47 | #define QTOUCH_LIB_KEY_ONLY_OFFSET 10 48 | #define QTOUCH_LIB_KEY_ONLY_MASK 0x01 49 | #define QTOUCH_LIB_ROTOR_NUM_OFFSET 11 50 | #define QTOUCH_LIB_ROTOR_NUM_MASK 0x1F 51 | #define GET_SENSOR_STATE(SENSOR_NUMBER) (qt_measure_data.qt_touch_status.sensor_states[(SENSOR_NUMBER/8)] & (1 << (SENSOR_NUMBER % 8))) 52 | #endif 53 | 54 | 55 | void touch_init(void); 56 | uint8_t touch_button_press(uint8_t touch_type); 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/putc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_putc 10 | 11 | 12 | 13 | 14 |
15 |

f_putc

16 |

The f_putc funciton puts a character to the file.

17 |
18 | int f_putc (
19 |   TCHAR Chr,        /* A character to put */
20 |   FIL* FileObject   /* File object */
21 | );
22 | 
23 |
24 | 25 |
26 |

Parameters

27 |
28 |
Chr
29 |
A character to be put.
30 |
FileObject
31 |
Pointer to the open file object structuer.
32 |
33 |
34 | 35 | 36 |
37 |

Return Values

38 |

When the character was written successfuly, the function returns 1. When the function failed due to disk full or any error, an EOF (-1) will be returned.

39 |

When the FatFs is configured to Unicode API (_LFN_UNICODE == 1), the UTF-16 character is written to the file in UTF-8 encoding. If not the case, the byte will be written directly.

40 |
41 | 42 | 43 |
44 |

Description

45 |

The f_putc() is a wrapper function of f_write().

46 |
47 | 48 | 49 |
50 |

QuickInfo

51 |

Available when _FS_READONLY == 0 and _USE_STRFUNC is 1 or 2. When it is set to 2, a '\n' is converted to "\r\n".

52 |
53 | 54 | 55 |
56 |

See Also

57 |

f_open, f_puts, f_printf, f_gets, f_close, FIL

58 |
59 | 60 |

Return

61 | 62 | 63 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/sync.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_sync 10 | 11 | 12 | 13 | 14 |
15 |

f_sync

16 |

The f_sync function flushes the cached information of a writing file.

17 |
18 | FRESULT f_sync (
19 |   FIL* FileObject     /* Pointer to the file object */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameter

26 |
27 |
FileObject
28 |
Pointer to the open file object to be flushed.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

36 | FR_OK, 37 | FR_DISK_ERR, 38 | FR_INT_ERR, 39 | FR_NOT_READY, 40 | FR_INVALID_OBJECT, 41 | FR_TIMEOUT 42 |

43 |
44 | 45 | 46 |
47 |

Description

48 |

The f_sync function performs the same process as f_close function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing f_sync of periodic or immediataly after f_write can minimize the risk of data loss due to a sudden blackout or an unintentional disk removal. However f_sync immediataly before f_close has no advantage because f_close performs f_sync in it. In other words, the differnce between those functions is that the file object is invalidated or not.

49 |
50 | 51 | 52 |
53 |

QuickInfo

54 |

Available when _FS_READONLY == 0.

55 |
56 | 57 | 58 |
59 |

See Also

60 |

f_close

61 |
62 | 63 |

Return

64 | 65 | 66 | -------------------------------------------------------------------------------- /src/drivers/sam/utils/cmsis/sam4s/include/instance/instance_gpbr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 5 | * 6 | * \asf_license_start 7 | * 8 | * \page License 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 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 | * 20 | * 3. The name of Atmel may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with an 24 | * Atmel microcontroller product. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _SAM4S_GPBR_INSTANCE_ 43 | #define _SAM4S_GPBR_INSTANCE_ 44 | 45 | /* ========== Register definition for GPBR peripheral ========== */ 46 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 47 | #define REG_GPBR_GPBR (0x400E1490U) /**< \brief (GPBR) General Purpose Backup Register */ 48 | #else 49 | #define REG_GPBR_GPBR (*(__IO uint32_t*)0x400E1490U) /**< \brief (GPBR) General Purpose Backup Register */ 50 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 51 | 52 | #endif /* _SAM4S_GPBR_INSTANCE_ */ 53 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/mount.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_mount 10 | 11 | 12 | 13 | 14 |
15 |

f_mount

16 |

The f_mount fucntion registers/unregisters a work area to the FatFs module.

17 |
18 | FRESULT f_mount (
19 |   BYTE  Drive,              /* Logical drive number */
20 |   FATFS*  FileSystemObject  /* Pointer to the work area */
21 | );
22 | 
23 |
24 | 25 |
26 |

Parameters

27 |
28 |
Drive
29 |
Logical drive number (0-9) to register/unregister the work area.
30 |
FileSystemObject
31 |
Pointer to the work area (file system object) to be registered.
32 |
33 |
34 | 35 |
36 |

Return Values

37 |

38 | FR_OK, 39 | FR_INVALID_DRIVE 40 |

41 |
42 | 43 | 44 |
45 |

Description

46 |

The f_mount function registers/unregisters a work area to the FatFs module. The work area must be given to the each volume with this function prior to use any other file function. To unregister a work area, specify a NULL to the FileSystemObject, and then the work area can be discarded.

47 |

This function always succeeds regardless of the drive status. No media access is occured in this function. It only initializes the given work area and registers its address to the internal table. The volume mount process is performed on first file access after f_mount function or media change.

48 |
49 | 50 | 51 |
52 |

QuickInfo

53 |

Always available.

54 |
55 | 56 | 57 |
58 |

See Also

59 |

FATFS

60 |
61 | 62 |

Return

63 | 64 | 65 | -------------------------------------------------------------------------------- /src/simulator.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "commander.h" 3 | #include "ecc.h" 4 | #include "flags.h" 5 | #include "memory.h" 6 | #include "sd.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define PORT 35345 13 | #define BUF_SIZE COMMANDER_REPORT_SIZE 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | // Get and set the root directory 18 | if (argc < 2) { 19 | fprintf(stderr, "The directory to be used for the sd card files must be specified\n"); 20 | exit(1); 21 | } else if (argc > 2) { 22 | fprintf(stderr, "Too many arguments\n"); 23 | exit(1); 24 | } 25 | set_root_dir(argv[1]); 26 | 27 | // Init device 28 | ecc_context_init(); 29 | #ifdef ECC_USE_SECP256K1_LIB 30 | bitcoin_ecc.ecc_context_init(); 31 | #endif 32 | memory_setup(); 33 | memory_setup(); 34 | 35 | // Create socket 36 | int s; 37 | if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { 38 | fprintf(stderr, "Socket could not be created\n"); 39 | exit(1); 40 | } 41 | 42 | // Make socket struct 43 | struct sockaddr_in sock; 44 | memset(&sock, 0, sizeof(sock)); 45 | sock.sin_family = AF_INET; 46 | sock.sin_addr.s_addr = htonl(INADDR_ANY); 47 | sock.sin_port = htons(PORT); 48 | 49 | // Bind socket 50 | if (bind(s, (struct sockaddr *)&sock, sizeof(sock)) == -1) { 51 | fprintf(stderr, "Could not bind socket\n"); 52 | exit(1); 53 | } 54 | fprintf(stderr, "Digital Bitbox simulator started\n"); 55 | 56 | // Wait for connections and handle 57 | char buf[BUF_SIZE]; 58 | char *result; 59 | struct sockaddr_in in_sock; 60 | int recv_len; 61 | socklen_t in_sock_len = sizeof(in_sock); 62 | while (1) { 63 | int rc; 64 | // Receive 65 | memset(buf, 0, BUF_SIZE); 66 | if ((recv_len = recvfrom(s, buf, BUF_SIZE, 0, (struct sockaddr *)&in_sock, 67 | &in_sock_len)) < 0) { 68 | fprintf(stderr, "Failed to receive udp data, error %d\n", recv_len); 69 | exit(1); 70 | } 71 | 72 | // Execute the command 73 | result = commander(buf); 74 | 75 | // Send result to socket 76 | if ((rc = sendto(s, result, strlen(result), 0, (struct sockaddr *)&in_sock, 77 | in_sock_len)) < 0) { 78 | fprintf(stderr, "Failed to send udp data, error %d\n", rc); 79 | exit(1); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/puts.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_puts 10 | 11 | 12 | 13 | 14 |
15 |

f_puts

16 |

The f_puts function writes a string to the file.

17 |
18 | int f_puts (
19 |   const TCHAR* Str,  /* String */
20 |   FIL* FileObject    /* File object */
21 | );
22 | 
23 |
24 | 25 |
26 |

Parameters

27 |
28 |
Str
29 |
Pointer to the null terminated string to be written. The null character will not be written.
30 |
FileObject
31 |
Pointer to the open file object structure.
32 |
33 |
34 | 35 | 36 |
37 |

Return Value

38 |

When the function succeeded, number of characters written that is not minus value is returned. When the write operation is aborted due to disk full or any error, an EOF (-1) will be returned.

39 |

When the FatFs is configured to Unicode API (_LFN_UNICODE == 1), the UTF-16 string is written to the file in UTF-8 encoding. If not the case, the byte stream will be written directly.

40 |
41 | 42 | 43 |
44 |

Description

45 |

The f_puts() is a wrapper function of f_putc().

46 |
47 | 48 | 49 |
50 |

QuickInfo

51 |

Available when _FS_READONLY == 0 and _USE_STRFUNC is 1 or 2. When it is set to 2, '\n's contained in the string are converted to "\r\n".

52 |
53 | 54 | 55 |
56 |

See Also

57 |

f_open, f_putc, f_printf, f_gets, f_close, FIL

58 |
59 | 60 |

Return

61 | 62 | 63 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/mkdir.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_mkdir 10 | 11 | 12 | 13 | 14 |
15 |

f_mkdir

16 |

The f_mkdir function creates a new directory.

17 |
18 | FRESULT f_mkdir (
19 |   const TCHAR* DirName /* Pointer to the directory name */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameter

26 |
27 |
DirName
28 |
Pointer to the null-terminated string that specifies the directory name to create.
29 |
30 |
31 | 32 | 33 |
34 |

Return Value

35 |

36 | FR_OK, 37 | FR_DISK_ERR, 38 | FR_INT_ERR, 39 | FR_NOT_READY, 40 | FR_NO_PATH, 41 | FR_INVALID_NAME, 42 | FR_DENIED, 43 | FR_EXIST, 44 | FR_WRITE_PROTECTED, 45 | FR_INVALID_DRIVE, 46 | FR_NOT_ENABLED, 47 | FR_NO_FILESYSTEM, 48 | FR_TIMEOUT, 49 | FR_NOT_ENOUGH_CORE 50 |

51 |
52 | 53 | 54 |
55 |

Description

56 |

The f_mkdir function creates a new directory.

57 |
58 | 59 | 60 |
61 |

QuickInfo

62 |

Available when _FS_READONLY == 0 and _FS_MINIMIZE == 0.

63 |
64 | 65 | 66 |
67 |

Example

68 |
69 |     res = f_mkdir("sub1");
70 |     if (res) die(res);
71 |     res = f_mkdir("sub1/sub2");
72 |     if (res) die(res);
73 |     res = f_mkdir("sub1/sub2/sub3");
74 |     if (res) die(res);
75 | 
76 |
77 | 78 |

Return

79 | 80 | 81 | -------------------------------------------------------------------------------- /src/drivers/config/conf_uart_serial.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Serial USART service configuration. 5 | * 6 | * Copyright (c) 2013 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef CONF_USART_SERIAL_H 45 | #define CONF_USART_SERIAL_H 46 | 47 | /** UART Interface */ 48 | #define CONF_UART CONSOLE_UART 49 | /** Baudrate setting */ 50 | #define CONF_UART_BAUDRATE 115200 51 | /** Parity setting */ 52 | #define CONF_UART_PARITY US_MR_PAR_NO 53 | 54 | /* Configure UART pins PIO */ 55 | #define CONF_UART_PIO PINS_UART1_PIO 56 | 57 | /* Configure UART pins */ 58 | #define CONF_PINS_UART PINS_UART1 59 | 60 | /* Configure UART pins flags */ 61 | #define CONF_PINS_UART_FLAGS PINS_UART1_FLAGS 62 | 63 | #endif/* CONF_USART_SERIAL_H_INCLUDED */ 64 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/dread.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - disk_read 10 | 11 | 12 | 13 | 14 |
15 |

disk_read

16 |

The disk_read function reads sector(s) from the disk drive.

17 |
18 | DRESULT disk_read (
19 |   BYTE Drive,          /* Physical drive number */
20 |   BYTE* Buffer,        /* Pointer to the read data buffer */
21 |   DWORD SectorNumber,  /* Start sector number */
22 |   BYTE SectorCount     /* Number of sectros to read */
23 | );
24 | 
25 |
26 | 27 |
28 |

Parameters

29 |
30 |
Drive
31 |
Specifies the physical drive number.
32 |
Buffer
33 |
Pointer to the byte array to store the read data. The buffer size of number of bytes to be read, sector size * sector count, is required. Note that the specified memory address is not that always aligned to word boundary. If the hardware does not support misaligned data transfer, it must be solved in this function.
34 |
SectorNumber
35 |
Specifies the start sector number in logical block address (LBA).
36 |
SectorCount
37 |
Specifies number of sectors to read. The value can be 1 to 128. Generally, a multiple sector transfer request must not be split into single sector transactions to the device, or you may not get good read performance.
38 |
39 |
40 | 41 | 42 |
43 |

Return Value

44 |
45 |
RES_OK (0)
46 |
The function succeeded.
47 |
RES_ERROR
48 |
Any hard error occured during the read operation and could not recover it.
49 |
RES_PARERR
50 |
Invalid parameter.
51 |
RES_NOTRDY
52 |
The disk drive has not been initialized.
53 |
54 |
55 | 56 | 57 |

Return

58 | 59 | 60 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/opendir.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_opendir 10 | 11 | 12 | 13 | 14 |
15 |

f_opendir

16 |

The f_opendir function opens a directory.

17 |
18 | FRESULT f_opendir (
19 |   DIR* DirObject,       /* Pointer to the blank directory object structure */
20 |   const TCHAR* DirName  /* Pointer to the directory name */
21 | );
22 | 
23 |
24 | 25 |
26 |

Parameters

27 |
28 |
DirObject
29 |
Pointer to the blank directory object to be created.
30 |
DirName
31 |
Pinter to the null-terminated string that specifies the directory name to be opened.
32 |
33 |
34 | 35 | 36 |
37 |

Return Values

38 |

39 | FR_OK, 40 | FR_DISK_ERR, 41 | FR_INT_ERR, 42 | FR_NOT_READY, 43 | FR_NO_PATH, 44 | FR_INVALID_NAME, 45 | FR_INVALID_DRIVE, 46 | FR_NOT_ENABLED, 47 | FR_NO_FILESYSTEM, 48 | FR_TIMEOUT, 49 | FR_NOT_ENOUGH_CORE 50 |

51 |
52 | 53 | 54 |
55 |

Description

56 |

The f_opendir function opens an exsisting directory and creates the directory object for subsequent calls. The directory object structure can be discarded at any time without any procedure.

57 |
58 | 59 | 60 |
61 |

QuickInfo

62 |

Available when _FS_MINIMIZE <= 1.

63 |
64 | 65 | 66 |
67 |

See Also

68 |

f_readdir, DIR

69 |
70 | 71 |

Return

72 | 73 | 74 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/stat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_stat 10 | 11 | 12 | 13 | 14 |
15 |

f_stat

16 |

The f_stat gets the file status.

17 |
18 | FRESULT f_stat (
19 |   const TCHAR* FileName,  /* Pointer to the file or directory name */
20 |   FILINFO* FileInfo       /* Pointer to the FILINFO structure */
21 | );
22 | 
23 |
24 | 25 |
26 |

Parameters

27 |
28 |
FileName
29 |
Pointer to the null-terminated string that specifies the file or directory to get its information.
30 |
FileInfo
31 |
Pointer to the blank FILINFO structure to store the information.
32 |
33 |
34 | 35 | 36 |
37 |

Return Values

38 |

39 | FR_OK, 40 | FR_DISK_ERR, 41 | FR_INT_ERR, 42 | FR_NOT_READY, 43 | FR_NO_FILE, 44 | FR_NO_PATH, 45 | FR_INVALID_NAME, 46 | FR_INVALID_DRIVE, 47 | FR_NOT_ENABLED, 48 | FR_NO_FILESYSTEM, 49 | FR_TIMEOUT, 50 | FR_NOT_ENOUGH_CORE 51 |

52 |
53 | 54 | 55 |
56 |

Description

57 |

The f_stat gets the information of a file or directory. For details of the infomation, refer to the FILINFO structure and f_readdir function. This function is not supported in minimization level of >= 1.

58 |
59 | 60 | 61 |
62 |

References

63 |

f_opendir, f_readdir, FILINFO

64 |
65 | 66 |

Return

67 | 68 | 69 | -------------------------------------------------------------------------------- /dockerdev.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # 3 | # The MIT License (MIT) 4 | # 5 | # Copyright 2019 Shift Cryptosecurity AG 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining 8 | # a copy of this software and associated documentation files (the "Software"), 9 | # to deal in the Software without restriction, including without limitation 10 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | # and/or sell copies of the Software, and to permit persons to whom the 12 | # Software is furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included 15 | # in all copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | # OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 26 | 27 | dockerdev () { 28 | local container_image=shift/mcu-base 29 | local container_name=mcu-dev 30 | 31 | if ! docker images | grep -q $container_image; then 32 | echo "No $container_image docker image found! Maybe you need to run 'docker build --tag $container_image -f Dockerfile.dev .'?" >&2 33 | exit 1 34 | fi 35 | 36 | # If already running, enter the container. 37 | if docker ps | grep -q $container_name; then 38 | docker exec --user=dockeruser --workdir=/app -it $container_name bash 39 | return 40 | fi 41 | 42 | if docker ps -a | grep -q $container_name; then 43 | docker rm $container_name 44 | fi 45 | 46 | local repo_path="$DIR" 47 | docker run \ 48 | --detach \ 49 | --privileged -v /dev/bus/usb:/dev/bus/usb \ 50 | --interactive --tty \ 51 | --name=$container_name \ 52 | -v $repo_path:/app \ 53 | $container_image bash 54 | 55 | # Use same user/group id as on the host, so that files are not created as root in the mounted 56 | # volume. 57 | docker exec -it $container_name groupadd -g `id -g` dockergroup 58 | docker exec -it $container_name useradd -u `id -u` -m -g dockergroup dockeruser 59 | 60 | # Call a second time to enter the container. 61 | dockerdev 62 | } 63 | 64 | dockerdev 65 | -------------------------------------------------------------------------------- /src/drivers/config/conf_spi_master.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Spi Master configuration. 5 | * 6 | * Copyright (c) 2011-2013 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef CONF_SPI_MASTER_H_INCLUDED 45 | #define CONF_SPI_MASTER_H_INCLUDED 46 | 47 | /* Possibility to change low-level configurations here */ 48 | 49 | //! Default Config Spi Master Delay BCS 50 | #define CONFIG_SPI_MASTER_DELAY_BCS 0 51 | 52 | //! Default Config Spi Master Bits per Transfer Definition 53 | #define CONFIG_SPI_MASTER_BITS_PER_TRANSFER 8 54 | 55 | //! Default Config Spi Master Delay BCT 56 | #define CONFIG_SPI_MASTER_DELAY_BCT 0 57 | 58 | //! Default Config Spi Master Delay BS 59 | #define CONFIG_SPI_MASTER_DELAY_BS 0 60 | 61 | //! Default Config Spi Master Dummy Field 62 | #define CONFIG_SPI_MASTER_DUMMY 0xFF 63 | 64 | #endif /* CONF_SPI_MASTER_H_INCLUDED */ 65 | -------------------------------------------------------------------------------- /src/drivers/sam/utils/cmsis/sam4s/include/instance/instance_chipid.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 5 | * 6 | * \asf_license_start 7 | * 8 | * \page License 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 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 | * 20 | * 3. The name of Atmel may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with an 24 | * Atmel microcontroller product. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _SAM4S_CHIPID_INSTANCE_ 43 | #define _SAM4S_CHIPID_INSTANCE_ 44 | 45 | /* ========== Register definition for CHIPID peripheral ========== */ 46 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 47 | #define REG_CHIPID_CIDR (0x400E0740U) /**< \brief (CHIPID) Chip ID Register */ 48 | #define REG_CHIPID_EXID (0x400E0744U) /**< \brief (CHIPID) Chip ID Extension Register */ 49 | #else 50 | #define REG_CHIPID_CIDR (*(__I uint32_t*)0x400E0740U) /**< \brief (CHIPID) Chip ID Register */ 51 | #define REG_CHIPID_EXID (*(__I uint32_t*)0x400E0744U) /**< \brief (CHIPID) Chip ID Extension Register */ 52 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 53 | 54 | #endif /* _SAM4S_CHIPID_INSTANCE_ */ 55 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/dwrite.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - disk_write 10 | 11 | 12 | 13 | 14 |
15 |

disk_write

16 |

The disk_write writes sector(s) to the disk.

17 |
18 | DRESULT disk_write (
19 |   BYTE Drive,          /* Physical drive number */
20 |   const BYTE* Buffer,  /* Pointer to the write data (may be non aligned) */
21 |   DWORD SectorNumber,  /* Sector number to write */
22 |   BYTE SectorCount     /* Number of sectors to write */
23 | );
24 | 
25 |
26 | 27 |
28 |

Parameters

29 |
30 |
Drive
31 |
Specifies the physical drive number.
32 |
Buffer
33 |
Pointer to the byte array to be written. Note that the specified memory address is not that always aligned to word boundary. If the hardware does not support misaligned data transfer, it must be solved in this function.
34 |
SectorNumber
35 |
Specifies the start sector number in logical block address (LBA).
36 |
SectorCount
37 |
Specifies the number of sectors to write. The value can be 1 to 128. Generally, a multiple sector transfer request must not be split into single sector transactions to the device, or you will never get good write performance.
38 |
39 |
40 | 41 | 42 |
43 |

Return Values

44 |
45 |
RES_OK (0)
46 |
The function succeeded.
47 |
RES_ERROR
48 |
Any hard error occured during the write operation and could not recover it.
49 |
RES_WRPRT
50 |
The medium is write protected.
51 |
RES_PARERR
52 |
Invalid parameter.
53 |
RES_NOTRDY
54 |
The disk drive has not been initialized.
55 |
56 |
57 | 58 | 59 |
60 |

Description

61 |

This function is not required in read only configuration.

62 |
63 | 64 | 65 |

Return

66 | 67 | 68 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/sfile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - FIL 10 | 11 | 12 | 13 | 14 |
15 |

FIL

16 |

The FIL structure (file object) holds state of an open file. It is created by f_open function and discarded by f_close function. There is no member that can be changed by the application program except for cltbl. Note that a sector buffer is defined in this structure under non-tiny configuration so that the FIL structures should not be defined as auto variable.

17 | 18 |
19 | typedef struct {
20 |     FATFS*  fs;           /* Pointer to the owner file system object */
21 |     WORD    id;           /* Owner file system mount ID */
22 |     BYTE    flag;         /* File status flags */
23 |     BYTE    pad1;
24 |     DWORD   fptr;         /* File read/write pointer (Byte offset origin from top of the file) */
25 |     DWORD   fsize;        /* File size */
26 |     DWORD   sclust;       /* File start cluster */
27 |     DWORD   clust;        /* Current cluster */
28 |     DWORD   dsect;        /* Current data sector */
29 | #if !_FS_READONLY
30 |     DWORD   dir_sect;     /* Sector containing the directory entry */
31 |     BYTE*   dir_ptr;      /* Ponter to the directory entry in the window */
32 | #endif
33 | #if _USE_FASTSEEK
34 |     DWORD*  cltbl;        /* Pointer to the cluster link map table (Nulled on file open) */
35 | #endif
36 | #if _FS_SHARE
37 |     UINT    lockid;       /* File lock ID */
38 | #endif
39 | #if !_FS_TINY
40 |     BYTE    buf[_MAX_SS]; /* Data read/write buffer */
41 | #endif
42 | } FIL;
43 | 
44 | 45 |
46 | 47 |

Return

48 | 49 | 50 | -------------------------------------------------------------------------------- /src/drivers/sam/drivers/pio/pio_handler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Parallel Input/Output (PIO) interrupt handler for SAM. 5 | * 6 | * Copyright (c) 2011-2013 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef PIO_HANDLER_H_INCLUDED 45 | #define PIO_HANDLER_H_INCLUDED 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | void pio_handler_process(Pio *p_pio, uint32_t ul_id); 52 | void pio_handler_set_priority(Pio *p_pio, IRQn_Type ul_irqn, uint32_t ul_priority); 53 | uint32_t pio_handler_set(Pio *p_pio, uint32_t ul_id, uint32_t ul_mask, 54 | uint32_t ul_attr, void (*p_handler) (uint32_t, uint32_t)); 55 | uint32_t pio_handler_set_pin(uint32_t ul_pin, uint32_t ul_flag, 56 | void (*p_handler) (uint32_t, uint32_t)); 57 | 58 | #if (SAM3S || SAM4S || SAM4E) 59 | void pio_capture_handler_set(void (*p_handler)(Pio *)); 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* PIO_HANDLER_H_INCLUDED */ 67 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/src/diskio.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO 6 | 7 | #define _READONLY 0 /* 1: Remove write functions */ 8 | #define _USE_IOCTL 1 /* 1: Use disk_ioctl fucntion */ 9 | 10 | #include "integer.h" 11 | 12 | 13 | /* Status of Disk Functions */ 14 | typedef BYTE DSTATUS; 15 | 16 | /* Results of Disk Functions */ 17 | typedef enum { 18 | RES_OK = 0, /* 0: Successful */ 19 | RES_ERROR, /* 1: R/W Error */ 20 | RES_WRPRT, /* 2: Write Protected */ 21 | RES_NOTRDY, /* 3: Not Ready */ 22 | RES_PARERR /* 4: Invalid Parameter */ 23 | } DRESULT; 24 | 25 | 26 | /*---------------------------------------*/ 27 | /* Prototypes for disk control functions */ 28 | 29 | int assign_drives (int, int); 30 | DSTATUS disk_initialize (BYTE); 31 | DSTATUS disk_status (BYTE); 32 | DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); 33 | #if _READONLY == 0 34 | DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); 35 | #endif 36 | DRESULT disk_ioctl (BYTE, BYTE, void*); 37 | 38 | 39 | 40 | /* Disk Status Bits (DSTATUS) */ 41 | 42 | #define STA_NOINIT 0x01 /* Drive not initialized */ 43 | #define STA_NODISK 0x02 /* No medium in the drive */ 44 | #define STA_PROTECT 0x04 /* Write protected */ 45 | 46 | 47 | /* Command code for disk_ioctrl fucntion */ 48 | 49 | /* Generic command (defined for FatFs) */ 50 | #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */ 51 | #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */ 52 | #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */ 53 | #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */ 54 | #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */ 55 | 56 | /* Generic command */ 57 | #define CTRL_POWER 5 /* Get/Set power status */ 58 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 59 | #define CTRL_EJECT 7 /* Eject media */ 60 | 61 | /* MMC/SDC specific ioctl command */ 62 | #define MMC_GET_TYPE 10 /* Get card type */ 63 | #define MMC_GET_CSD 11 /* Get CSD */ 64 | #define MMC_GET_CID 12 /* Get CID */ 65 | #define MMC_GET_OCR 13 /* Get OCR */ 66 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 67 | 68 | /* ATA/CF specific ioctl command */ 69 | #define ATA_GET_REV 20 /* Get F/W revision */ 70 | #define ATA_GET_MODEL 21 /* Get model name */ 71 | #define ATA_GET_SN 22 /* Get serial number */ 72 | 73 | /* NAND specific ioctl command */ 74 | #define NAND_FORMAT 30 /* Create physical format */ 75 | 76 | 77 | #define _DISKIO 78 | #endif 79 | -------------------------------------------------------------------------------- /src/drivers/sam/drivers/wdt/wdt.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Watchdog Timer (WDT) driver for SAM. 5 | * 6 | * Copyright (c) 2011-2014 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef WDT_H_INCLUDED 45 | #define WDT_H_INCLUDED 46 | 47 | #include "compiler.h" 48 | 49 | /// @cond 0 50 | /**INDENT-OFF**/ 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | /**INDENT-ON**/ 55 | /// @endcond 56 | 57 | #define WDT_INVALID_ARGUMENT 0xFFFF 58 | 59 | uint32_t wdt_get_timeout_value(uint32_t ul_us, uint32_t ul_sclk); 60 | void wdt_init(Wdt *p_wdt, uint32_t ul_mode, uint16_t us_counter, 61 | uint16_t us_delta); 62 | void wdt_disable(Wdt *p_wdt); 63 | void wdt_restart(Wdt *p_wdt); 64 | uint32_t wdt_get_status(Wdt *p_wdt); 65 | uint32_t wdt_get_us_timeout_period(Wdt *p_wdt, uint32_t ul_sclk); 66 | 67 | /// @cond 0 68 | /**INDENT-OFF**/ 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | /**INDENT-ON**/ 73 | /// @endcond 74 | 75 | #endif /* WDT_H_INCLUDED */ 76 | -------------------------------------------------------------------------------- /src/pbkdf2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015-2016 Douglas J. Bakkum 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of this software and associated documentation files (the "Software"), 9 | to deal in the Software without restriction, including without limitation 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | and/or sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 21 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | 28 | #include 29 | #include "pbkdf2.h" 30 | #include "utils.h" 31 | #include "hmac.h" 32 | #include "sha2.h" 33 | 34 | 35 | void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const char *salt, uint8_t *key, 36 | int keylen) 37 | { 38 | uint32_t i, j, k; 39 | uint8_t f[PBKDF2_HMACLEN], g[PBKDF2_HMACLEN]; 40 | uint32_t blocks = keylen / PBKDF2_HMACLEN; 41 | int saltlen = strlens(salt); 42 | uint8_t salt_pbkdf2[saltlen + 4]; 43 | memset(salt_pbkdf2, 0, sizeof(salt_pbkdf2)); 44 | memcpy(salt_pbkdf2, salt, saltlen); 45 | 46 | if (keylen & (PBKDF2_HMACLEN - 1)) { 47 | blocks++; 48 | } 49 | for (i = 1; i <= blocks; i++) { 50 | salt_pbkdf2[saltlen ] = (i >> 24) & 0xFF; 51 | salt_pbkdf2[saltlen + 1] = (i >> 16) & 0xFF; 52 | salt_pbkdf2[saltlen + 2] = (i >> 8) & 0xFF; 53 | salt_pbkdf2[saltlen + 3] = i & 0xFF; 54 | hmac_sha512(pass, passlen, salt_pbkdf2, saltlen + 4, g); 55 | memcpy(f, g, PBKDF2_HMACLEN); 56 | for (j = 1; j < PBKDF2_ROUNDS; j++) { 57 | hmac_sha512(pass, passlen, g, PBKDF2_HMACLEN, g); 58 | for (k = 0; k < PBKDF2_HMACLEN; k++) { 59 | f[k] ^= g[k]; 60 | } 61 | } 62 | if (i == blocks && (keylen & (PBKDF2_HMACLEN - 1))) { 63 | memcpy(key + PBKDF2_HMACLEN * (i - 1), f, keylen & (PBKDF2_HMACLEN - 1)); 64 | } else { 65 | memcpy(key + PBKDF2_HMACLEN * (i - 1), f, PBKDF2_HMACLEN); 66 | } 67 | } 68 | utils_zero(f, sizeof(f)); 69 | utils_zero(g, sizeof(g)); 70 | } 71 | -------------------------------------------------------------------------------- /src/drivers/common/services/twi/sam_twi/twi_slave.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief TWI Slave driver for SAM. 5 | * 6 | * Copyright (c) 2011-2014 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef _TWI_SLAVE_H_ 45 | #define _TWI_SLAVE_H_ 46 | 47 | #include "twi.h" 48 | #include "sysclk.h" 49 | 50 | typedef Twi *twi_slave_t; 51 | 52 | static inline void twi_slave_setup(twi_slave_t p_twi, uint32_t dw_device_addr) 53 | { 54 | #if (!SAMG) 55 | if (p_twi == TWI0) { 56 | sysclk_enable_peripheral_clock(ID_TWI0); 57 | } else 58 | #endif 59 | if (p_twi == TWI1) { 60 | sysclk_enable_peripheral_clock(ID_TWI1); 61 | #if (SAM4N || SAMG) 62 | } else if (p_twi == TWI2) { 63 | sysclk_enable_peripheral_clock(ID_TWI2); 64 | #endif 65 | } else { 66 | // Do Nothing 67 | } 68 | twi_slave_init(p_twi, dw_device_addr); 69 | } 70 | 71 | #define twi_slave_enable(p_twi) twi_enable_slave_mode(p_twi) 72 | 73 | #define twi_slave_disable(p_twi) twi_disable_slave_mode(p_twi) 74 | 75 | #endif // _TWI_SLAVE_H_ 76 | -------------------------------------------------------------------------------- /src/drivers/sam/utils/cmsis/sam4s/include/instance/instance_wdt.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 5 | * 6 | * \asf_license_start 7 | * 8 | * \page License 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 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 | * 20 | * 3. The name of Atmel may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with an 24 | * Atmel microcontroller product. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _SAM4S_WDT_INSTANCE_ 43 | #define _SAM4S_WDT_INSTANCE_ 44 | 45 | /* ========== Register definition for WDT peripheral ========== */ 46 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 47 | #define REG_WDT_CR (0x400E1450U) /**< \brief (WDT) Control Register */ 48 | #define REG_WDT_MR (0x400E1454U) /**< \brief (WDT) Mode Register */ 49 | #define REG_WDT_SR (0x400E1458U) /**< \brief (WDT) Status Register */ 50 | #else 51 | #define REG_WDT_CR (*(__O uint32_t*)0x400E1450U) /**< \brief (WDT) Control Register */ 52 | #define REG_WDT_MR (*(__IO uint32_t*)0x400E1454U) /**< \brief (WDT) Mode Register */ 53 | #define REG_WDT_SR (*(__I uint32_t*)0x400E1458U) /**< \brief (WDT) Status Register */ 54 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 55 | 56 | #endif /* _SAM4S_WDT_INSTANCE_ */ 57 | -------------------------------------------------------------------------------- /src/drivers/sam/utils/cmsis/sam4s/include/instance/instance_rstc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 5 | * 6 | * \asf_license_start 7 | * 8 | * \page License 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 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 | * 20 | * 3. The name of Atmel may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with an 24 | * Atmel microcontroller product. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _SAM4S_RSTC_INSTANCE_ 43 | #define _SAM4S_RSTC_INSTANCE_ 44 | 45 | /* ========== Register definition for RSTC peripheral ========== */ 46 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 47 | #define REG_RSTC_CR (0x400E1400U) /**< \brief (RSTC) Control Register */ 48 | #define REG_RSTC_SR (0x400E1404U) /**< \brief (RSTC) Status Register */ 49 | #define REG_RSTC_MR (0x400E1408U) /**< \brief (RSTC) Mode Register */ 50 | #else 51 | #define REG_RSTC_CR (*(__O uint32_t*)0x400E1400U) /**< \brief (RSTC) Control Register */ 52 | #define REG_RSTC_SR (*(__I uint32_t*)0x400E1404U) /**< \brief (RSTC) Status Register */ 53 | #define REG_RSTC_MR (*(__IO uint32_t*)0x400E1408U) /**< \brief (RSTC) Mode Register */ 54 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 55 | 56 | #endif /* _SAM4S_RSTC_INSTANCE_ */ 57 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/chdir.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_chdir 10 | 11 | 12 | 13 | 14 |
15 |

f_chdir

16 |

The f_chdir function changes the current directory of a drive.

17 |
18 | FRESULT f_chdir (
19 |   const TCHAR* Path /* Pointer to the path name */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameters

26 |
27 |
Path
28 |
Pointer to the null-terminated string that specifies a directory to go.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

36 | FR_OK, 37 | FR_DISK_ERR, 38 | FR_INT_ERR, 39 | FR_NOT_READY, 40 | FR_NO_PATH, 41 | FR_INVALID_NAME, 42 | FR_INVALID_DRIVE, 43 | FR_NOT_ENABLED, 44 | FR_NO_FILESYSTEM, 45 | FR_TIMEOUT, 46 | FR_NOT_ENOUGH_CORE 47 |

48 |
49 | 50 | 51 |
52 |

Description

53 |

The f_chdir function changes the current directory of the logical drive. The current directory of a drive is initialized to the root directory when the drive is auto-mounted. Note that the current directory is retained in the each file system object so that it also affects other tasks that using the drive.

54 |
55 | 56 | 57 |
58 |

QuickInfo

59 |

Available when _FS_RPATH >= 1.

60 |
61 | 62 | 63 |
64 |

Example

65 |
66 |     /* Change current direcoty of the current drive (dir1 under root dir) */
67 |     f_chdir("/dir1");
68 | 
69 |     /* Change current direcoty of drive 2 (parent dir) */
70 |     f_chdir("2:..");
71 | 
72 |
73 | 74 |
75 |

See Also

76 |

f_chdrive, f_getcwd

77 |
78 | 79 |

Return

80 | 81 | 82 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/read.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_read 10 | 11 | 12 | 13 | 14 |
15 |

f_read

16 |

The f_read function reads data from a file.

17 |
18 | FRESULT f_read (
19 |   FIL* FileObject,    /* Pointer to the file object structure */
20 |   void* Buffer,       /* Pointer to the buffer to store read data */
21 |   UINT ByteToRead,    /* Number of bytes to read */
22 |   UINT* ByteRead      /* Pointer to the variable to return number of bytes read */
23 | );
24 | 
25 |
26 | 27 |
28 |

Parameters

29 |
30 |
FileObject
31 |
Pointer to the open file object.
32 |
Buffer
33 |
Pointer to the buffer to store read data
34 |
ByteToRead
35 |
Number of bytes to read in range of UINT.
36 |
ByteRead
37 |
Pointer to the UINT variable to return number of bytes read. The value is always valid after the function call regardless of the result.
38 |
39 |
40 | 41 | 42 |
43 |

Return Values

44 |

45 | FR_OK, 46 | FR_DISK_ERR, 47 | FR_INT_ERR, 48 | FR_NOT_READY, 49 | FR_INVALID_OBJECT, 50 | FR_TIMEOUT 51 |

52 |
53 | 54 | 55 |
56 |

Description

57 |

The file pointer of the file object increases in number of bytes read. After the function succeeded, *ByteRead should be checked to detect the end of file. In case of *ByteRead < ByteToRead, it means the read/write pointer reached end of the file during read operation.

58 |
59 | 60 | 61 |
62 |

QuickInfo

63 |

Always available.

64 |
65 | 66 | 67 |
68 |

See Also

69 |

f_open, fgets, f_write, f_close, FIL

70 |
71 | 72 |

Return

73 | 74 | 75 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/unlink.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_unlink 10 | 11 | 12 | 13 | 14 |
15 |

f_unlink

16 |

The f_unlink function removes a file or directory.

17 |
18 | FRESULT f_unlink (
19 |   const TCHAR* FileName  /* Pointer to the object name */
20 | );
21 | 
22 |
23 | 24 |
25 |

Parameter

26 |
27 |
FileName
28 |
Pointer to the null-terminated string that specifies an object to be removed.
29 |
30 |
31 | 32 | 33 |
34 |

Return Values

35 |

36 | FR_OK, 37 | FR_DISK_ERR, 38 | FR_INT_ERR, 39 | FR_NOT_READY, 40 | FR_NO_FILE, 41 | FR_NO_PATH, 42 | FR_INVALID_NAME, 43 | FR_DENIED, 44 | FR_EXIST, 45 | FR_WRITE_PROTECTED, 46 | FR_INVALID_DRIVE, 47 | FR_NOT_ENABLED, 48 | FR_NO_FILESYSTEM, 49 | FR_TIMEOUT, 50 | FR_LOCKED, 51 | FR_NOT_ENOUGH_CORE 52 |

53 |
54 | 55 | 56 |
57 |

Description

58 |

59 | If condition of the object to be removed is applicable to the following terms, the function will fail with error. 60 |

    61 |
  • The object must not have read-only attribute (AM_RDO) or the function will be rejected with FR_DENIED.
  • 62 |
  • The directory must be empty and must not be current directory or the function will be rejected with FR_DENIED.
  • 63 |
  • The file must not have been opened or the FAT volume can be collapted. It will able to be rejected with FR_LOCKED when file shareing control is enabled.
  • 64 |
65 |
66 | 67 | 68 |
69 |

QuickInfo

70 |

Available when _FS_READONLY == 0 and _FS_MINIMIZE == 0.

71 |
72 | 73 | 74 |

Return

75 | 76 | 77 | -------------------------------------------------------------------------------- /src/sha2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2000-2001 Aaron D. Gifford 3 | * Copyright (c) 2013 Pavol Rusnak 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holder nor the names of contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef __SHA2_H__ 32 | #define __SHA2_H__ 33 | 34 | #include 35 | #include 36 | 37 | #define SHA256_BLOCK_LENGTH 64 38 | #define SHA256_DIGEST_LENGTH 32 39 | #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 40 | #define SHA512_BLOCK_LENGTH 128 41 | #define SHA512_DIGEST_LENGTH 64 42 | #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) 43 | 44 | typedef struct _SHA256_CTX { 45 | uint32_t state[8]; 46 | uint64_t bitcount; 47 | uint8_t buffer[SHA256_BLOCK_LENGTH]; 48 | } SHA256_CTX; 49 | typedef struct _SHA512_CTX { 50 | uint64_t state[8]; 51 | uint64_t bitcount[2]; 52 | uint8_t buffer[SHA512_BLOCK_LENGTH]; 53 | } SHA512_CTX; 54 | 55 | void sha256_Init(SHA256_CTX *); 56 | void sha256_Update(SHA256_CTX *, const uint8_t *, size_t); 57 | void sha256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX *); 58 | void sha256_Raw(const uint8_t *, size_t, uint8_t[SHA256_DIGEST_LENGTH]); 59 | 60 | void sha512_Init(SHA512_CTX *); 61 | void sha512_Update(SHA512_CTX *, const uint8_t *, size_t); 62 | void sha512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX *); 63 | void sha512_Raw(const uint8_t *, size_t, uint8_t[SHA512_DIGEST_LENGTH]); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/gets.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_gets 10 | 11 | 12 | 13 | 14 |
15 |

f_gets

16 |

The f_gets reads a string from the file.

17 |
18 | TCHAR* f_gets (
19 |   TCHAR* Str,       /* Read buffer */
20 |   int Size,         /* Size of the read buffer */
21 |   FIL* FileObject   /* File object */
22 | );
23 | 
24 |
25 | 26 |
27 |

Parameters

28 |
29 |
Str
30 |
Pointer to read buffer to store the read string.
31 |
Size
32 |
Size of the read buffer in unit of character.
33 |
FileObject
34 |
Pointer to the open file object structure.
35 |
36 |
37 | 38 | 39 |
40 |

Return Values

41 |

When the function succeeded, Str will be returuned.

42 |
43 | 44 | 45 |
46 |

Description

47 |

The f_gets() is a wrapper function of f_read(). The read operation continues until a '\n' is stored, reached end of the file or the buffer is filled with Size - 1 characters. The read string is terminated with a '\0'. When no character to read or any error occured during read operation, f_gets() returns a null pointer. The end of file and error status can be examined with f_eof() and f_error() macros.

48 |

When the FatFs is configured to Unicode API (_LFN_UNICODE == 1), the file is read in UTF-8 encoding and stored it to the buffer in UCS-2. If not the case, the file will be read in one byte per character without any code conversion.

49 |
50 | 51 | 52 |
53 |

QuickInfo

54 |

Available when _USE_STRFUNC is 1 or 2. When it is set to 2, '\r's contained in the file are stripped out.

55 |
56 | 57 | 58 |
59 |

See Also

60 |

f_open, f_read, f_putc, f_puts, f_printf, f_close, FIL

61 |
62 | 63 |

Return

64 | 65 | 66 | -------------------------------------------------------------------------------- /src/drivers/common/services/serial/usart_serial.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief USART Serial driver functions. 6 | * 7 | * 8 | * Copyright (c) 2010-2013 Atmel Corporation. All rights reserved. 9 | * 10 | * \asf_license_start 11 | * 12 | * \page License 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions are met: 16 | * 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, 21 | * this list of conditions and the following disclaimer in the documentation 22 | * and/or other materials provided with the distribution. 23 | * 24 | * 3. The name of Atmel may not be used to endorse or promote products derived 25 | * from this software without specific prior written permission. 26 | * 27 | * 4. This software may only be redistributed and used in connection with an 28 | * Atmel microcontroller product. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 31 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 32 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 33 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 34 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 38 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 39 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 | * POSSIBILITY OF SUCH DAMAGE. 41 | * 42 | * \asf_license_stop 43 | * 44 | */ 45 | #include "serial.h" 46 | 47 | /** 48 | * \brief Send a sequence of bytes to USART device 49 | * 50 | * \param usart Base address of the USART instance. 51 | * \param data Data buffer to read 52 | * \param len Length of data 53 | * 54 | */ 55 | status_code_t usart_serial_write_packet(usart_if usart, const uint8_t *data, 56 | size_t len) 57 | { 58 | while (len) { 59 | usart_serial_putchar(usart, *data); 60 | len--; 61 | data++; 62 | } 63 | return STATUS_OK; 64 | } 65 | 66 | 67 | /** 68 | * \brief Receive a sequence of bytes from USART device 69 | * 70 | * \param usart Base address of the USART instance. 71 | * \param data Data buffer to write 72 | * \param len Length of data 73 | * 74 | */ 75 | status_code_t usart_serial_read_packet(usart_if usart, uint8_t *data, 76 | size_t len) 77 | { 78 | while (len) { 79 | usart_serial_getchar(usart, data); 80 | len--; 81 | data++; 82 | } 83 | return STATUS_OK; 84 | } 85 | -------------------------------------------------------------------------------- /src/drivers/sam/utils/cmsis/sam4s/include/system_sam4s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief Provides the low-level initialization functions that called 5 | * on chip startup. 6 | * 7 | * Copyright (c) 2011 - 2013 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * 4. This software may only be redistributed and used in connection with an 27 | * Atmel microcontroller product. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 32 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 33 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 38 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 | * POSSIBILITY OF SUCH DAMAGE. 40 | * 41 | * \asf_license_stop 42 | * 43 | */ 44 | 45 | #ifndef SYSTEM_SAM4S_H_INCLUDED 46 | #define SYSTEM_SAM4S_H_INCLUDED 47 | 48 | /* @cond 0 */ 49 | /**INDENT-OFF**/ 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | /**INDENT-ON**/ 54 | /* @endcond */ 55 | 56 | #include 57 | 58 | extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */ 59 | 60 | /** 61 | * @brief Setup the microcontroller system. 62 | * Initialize the System and update the SystemCoreClock variable. 63 | */ 64 | void SystemInit(void); 65 | 66 | /** 67 | * @brief Updates the SystemCoreClock with current core Clock 68 | * retrieved from cpu registers. 69 | */ 70 | void SystemCoreClockUpdate(void); 71 | 72 | /** 73 | * Initialize flash. 74 | */ 75 | void system_init_flash(uint32_t dw_clk); 76 | 77 | /* @cond 0 */ 78 | /**INDENT-OFF**/ 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | /**INDENT-ON**/ 83 | /* @endcond */ 84 | 85 | #endif /* SYSTEM_SAM4S_H_INCLUDED */ 86 | -------------------------------------------------------------------------------- /src/drivers/sam/utils/cmsis/sam4s/include/instance/instance_rtt.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * Copyright (c) 2012-2013 Atmel Corporation. All rights reserved. 5 | * 6 | * \asf_license_start 7 | * 8 | * \page License 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 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 | * 20 | * 3. The name of Atmel may not be used to endorse or promote products derived 21 | * from this software without specific prior written permission. 22 | * 23 | * 4. This software may only be redistributed and used in connection with an 24 | * Atmel microcontroller product. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _SAM4S_RTT_INSTANCE_ 43 | #define _SAM4S_RTT_INSTANCE_ 44 | 45 | /* ========== Register definition for RTT peripheral ========== */ 46 | #if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) 47 | #define REG_RTT_MR (0x400E1430U) /**< \brief (RTT) Mode Register */ 48 | #define REG_RTT_AR (0x400E1434U) /**< \brief (RTT) Alarm Register */ 49 | #define REG_RTT_VR (0x400E1438U) /**< \brief (RTT) Value Register */ 50 | #define REG_RTT_SR (0x400E143CU) /**< \brief (RTT) Status Register */ 51 | #else 52 | #define REG_RTT_MR (*(__IO uint32_t*)0x400E1430U) /**< \brief (RTT) Mode Register */ 53 | #define REG_RTT_AR (*(__IO uint32_t*)0x400E1434U) /**< \brief (RTT) Alarm Register */ 54 | #define REG_RTT_VR (*(__I uint32_t*)0x400E1438U) /**< \brief (RTT) Value Register */ 55 | #define REG_RTT_SR (*(__I uint32_t*)0x400E143CU) /**< \brief (RTT) Status Register */ 56 | #endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ 57 | 58 | #endif /* _SAM4S_RTT_INSTANCE_ */ 59 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/css_e.css: -------------------------------------------------------------------------------- 1 | * {margin: 0; padding: 0; border-width: 0;} 2 | body {margin: 8px; background-color: #e0ffff; font-color: black; font-family: serif; line-height: 133%; max-width: 1024px;} 3 | a:link {color: blue;} 4 | a:visited {color: darkmagenta;} 5 | a:hover {background-color: #a0ffff;} 6 | a:active {color: darkmagenta; position: relative; top: 1px; left: 1px;} 7 | abbr {border-width: 1px;} 8 | 9 | p {margin: 0 0 0.3em 1em;} 10 | em {font-style: normal; font-weight: bold; margin: 0 0.1em;} 11 | pre em {font-style: italic; font-weight: normal;} 12 | strong {} 13 | pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-family: monospace; background-color: white;} 14 | pre span.c {color: green;} 15 | pre span.k {color: blue;} 16 | tt {margin: 0 0.2em; font-family: monospace; } 17 | ol {margin: 0 2.5em;} 18 | ul {margin: 0 2em;} 19 | dl {margin: 0 1em;} 20 | dt {font-family: monospace;} 21 | dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; } 22 | dl.ret dt {margin: 0.5em 0 0 0 ; font-weight: bold;} 23 | dd {margin: 0 2em;} 24 | hr {border-width: 1px; margin: 1em;} 25 | div.abst {font-family: sans-serif;} 26 | div.para {clear: both; font-family: serif;} 27 | div.ret a {font-family: monospace; } 28 | .equ {text-indent: 0; margin: 1em 2em 1em;} 29 | .indent {margin-left: 2em;} 30 | .rset {float: right; margin: 0 0 0.5em 0.5em;} 31 | .lset {float: left; margin: 0 0.5em 0.5em 0.5em;} 32 | ul.flat li {list-style-type: none; margin: 0;} 33 | a.imglnk img {border: 1px solid;} 34 | .iequ {white-space: nowrap; font-weight: bold;} 35 | .clr {clear: both;} 36 | .it {font-style: italic;} 37 | .mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap} 38 | 39 | h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;} 40 | p.hdd {float: right; text-align: right; margin-top: 0.5em;} 41 | hr.hds {clear: both; margin-bottom: 1em;} 42 | 43 | h2 {font-size: 1.6em; font-family: sans-serif; background-color: #d8d8FF; padding: 0.2em 0.5em; margin: 0 0 0.5em;} 44 | h3 {font-size: 1.5em; font-family: sans-serif; margin: 1.5em 0 0.5em;} 45 | h4 {font-size: 1.2em; font-family: sans-serif; margin: 1em 0 0.2em;} 46 | h5 {font-size: 1em; font-family: sans-serif; margin: 0.5em 0 0em;} 47 | small {font-size: 80%;} 48 | .indent {margin-left: 2em;} 49 | 50 | /* Tables */ 51 | table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; } 52 | th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;} 53 | td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;} 54 | table.lst td:first-child {font-family: monospace;} 55 | table.lst2 td {font-family: monospace;} 56 | table caption {font-family: sans-serif; font-weight: bold;} 57 | tr.lst3 td { border-width: 2px 1px 1px; } 58 | 59 | p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;} 60 | -------------------------------------------------------------------------------- /src/drivers/common/services/twi/sam_twi/twi_master.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \brief TWI Master driver for SAM. 5 | * 6 | * Copyright (c) 2011-2014 Atmel Corporation. All rights reserved. 7 | * 8 | * \asf_license_start 9 | * 10 | * \page License 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 22 | * 3. The name of Atmel may not be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * 4. This software may only be redistributed and used in connection with an 26 | * Atmel microcontroller product. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | * \asf_license_stop 41 | * 42 | */ 43 | 44 | #ifndef _TWI_MASTER_H_ 45 | #define _TWI_MASTER_H_ 46 | 47 | #include "twi.h" 48 | #include "sysclk.h" 49 | 50 | typedef Twi *twi_master_t; 51 | typedef twi_options_t twi_master_options_t; 52 | typedef twi_packet_t twi_package_t; 53 | 54 | static inline uint32_t twi_master_setup(twi_master_t p_twi, 55 | twi_master_options_t *p_opt) 56 | { 57 | p_opt->master_clk = sysclk_get_cpu_hz(); 58 | p_opt->smbus = 0; 59 | 60 | #if (!SAMG) 61 | if (p_twi == TWI0) { 62 | sysclk_enable_peripheral_clock(ID_TWI0); 63 | } else 64 | #endif 65 | if (p_twi == TWI1) { 66 | sysclk_enable_peripheral_clock(ID_TWI1); 67 | #if (SAM4N || SAMG) 68 | } else if (p_twi == TWI2) { 69 | sysclk_enable_peripheral_clock(ID_TWI2); 70 | #endif 71 | } else { 72 | // Do Nothing 73 | } 74 | 75 | return (twi_master_init(p_twi, p_opt)); 76 | } 77 | 78 | #define twi_master_enable(p_twi) twi_enable_master_mode(p_twi) 79 | #define twi_master_disable(p_twi) twi_disable_master_mode(p_twi) 80 | 81 | #endif // _TWI_MASTER_H_ 82 | -------------------------------------------------------------------------------- /src/drivers/thirdparty/fatfs/fatfs-r0.09/doc/en/rename.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | FatFs - f_rename 10 | 11 | 12 | 13 | 14 |
15 |

f_rename

16 |

Renames an object.

17 |
18 | FRESULT f_rename (
19 |   const TCHAR* OldName, /* Pointer to old object name */
20 |   const TCHAR* NewName  /* Pointer to new object name */
21 | );
22 | 
23 |
24 | 25 |
26 |

Parameters

27 |
28 |
OldName
29 |
Pointer to a null-terminated string specifies the old object name to be renamed.
30 |
NewName
31 |
Pointer to a null-terminated string specifies the new object name without drive number.
32 |
33 |
34 | 35 | 36 |
37 |

Return Values

38 |

39 | FR_OK, 40 | FR_DISK_ERR, 41 | FR_INT_ERR, 42 | FR_NOT_READY, 43 | FR_NO_FILE, 44 | FR_NO_PATH, 45 | FR_INVALID_NAME, 46 | FR_DENIED, 47 | FR_EXIST, 48 | FR_WRITE_PROTECTED, 49 | FR_INVALID_DRIVE, 50 | FR_NOT_ENABLED, 51 | FR_NO_FILESYSTEM, 52 | FR_TIMEOUT, 53 | FR_LOCKED, 54 | FR_NOT_ENOUGH_CORE 55 |

56 |
57 | 58 | 59 |
60 |

Description

61 |

Renames an object (file or directory) and can also move it to other directory. The logical drive number is determined by old name, new name must not contain a logical drive number. Do not rename open objects.

62 |
63 | 64 | 65 |
66 |

QuickInfo

67 |

Available when _FS_READONLY == 0 and _FS_MINIMIZE == 0.

68 |
69 | 70 | 71 |
72 |

Example

73 |
74 |     /* Rename an object */
75 |     f_rename("oldname.txt", "newname.txt");
76 | 
77 |     /* Rename and move an object to other directory */
78 |     f_rename("oldname.txt", "dir1/newname.txt");
79 | 
80 |
81 | 82 |

Return

83 | 84 | 85 | --------------------------------------------------------------------------------