DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

The MAXREFDES155# is an internet-of-things (IoT) embedded-security reference design, built to authenticate and control a sensing node using elliptic-curve-based public-key cryptography with control and notification from a web server.

The hardware includes an ARM® mbed™ shield and attached sensor endpoint. The shield contains a DS2476 DeepCover® ECDSA/SHA-2 coprocessor, Wifi communication, LCD push-button controls, and status LEDs. The sensor endpoint is attached to the shield using a 300mm cable and contains a DS28C36 DeepCover ECDSA/SHA-2 authenticator, IR-thermal sensor, and aiming laser for the IR sensor. The MAXREFDES155# is equipped with a standard Arduino® form-factor shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The combination of these two devices represent an IoT device. Communication to the web server is accomplished with the shield Wifi circuitry. Communication from the shield to the attached sensor module is accomplished over I2C . The sensor module represents an IoT endpoint that generates small data with a requirement for message authenticity/integrity and secure on/off operational control.

The design is hierarchical with each mbed platform and shield communicating data from the sensor node to a web server that maintains a centralized log and dispatches notifications as necessary. The simplicity of this design enables rapid integration into any star-topology IoT network to provide security with the low overhead and cost provided by the ECDSA-P256 asymmetric-key and SHA-256 symmetric-key algorithms.

More information about the MAXREFDES155# is available on the Maxim Integrated website.

Committer:
IanBenzMaxim
Date:
Tue Dec 03 12:56:25 2019 -0600
Revision:
18:c2631e985780
Parent:
16:a004191a79ab
Updated MaximInterface to version 2.1.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:33d4e66780c0 1 /*
IanBenzMaxim 0:33d4e66780c0 2 * fs.h - CC31xx/CC32xx Host Driver Implementation
IanBenzMaxim 0:33d4e66780c0 3 *
IanBenzMaxim 0:33d4e66780c0 4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
IanBenzMaxim 0:33d4e66780c0 5 *
IanBenzMaxim 0:33d4e66780c0 6 *
IanBenzMaxim 0:33d4e66780c0 7 * Redistribution and use in source and binary forms, with or without
IanBenzMaxim 0:33d4e66780c0 8 * modification, are permitted provided that the following conditions
IanBenzMaxim 0:33d4e66780c0 9 * are met:
IanBenzMaxim 0:33d4e66780c0 10 *
IanBenzMaxim 0:33d4e66780c0 11 * Redistributions of source code must retain the above copyright
IanBenzMaxim 0:33d4e66780c0 12 * notice, this list of conditions and the following disclaimer.
IanBenzMaxim 0:33d4e66780c0 13 *
IanBenzMaxim 0:33d4e66780c0 14 * Redistributions in binary form must reproduce the above copyright
IanBenzMaxim 0:33d4e66780c0 15 * notice, this list of conditions and the following disclaimer in the
IanBenzMaxim 0:33d4e66780c0 16 * documentation and/or other materials provided with the
IanBenzMaxim 0:33d4e66780c0 17 * distribution.
IanBenzMaxim 0:33d4e66780c0 18 *
IanBenzMaxim 0:33d4e66780c0 19 * Neither the name of Texas Instruments Incorporated nor the names of
IanBenzMaxim 0:33d4e66780c0 20 * its contributors may be used to endorse or promote products derived
IanBenzMaxim 0:33d4e66780c0 21 * from this software without specific prior written permission.
IanBenzMaxim 0:33d4e66780c0 22 *
IanBenzMaxim 0:33d4e66780c0 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
IanBenzMaxim 0:33d4e66780c0 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
IanBenzMaxim 0:33d4e66780c0 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
IanBenzMaxim 0:33d4e66780c0 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
IanBenzMaxim 0:33d4e66780c0 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
IanBenzMaxim 0:33d4e66780c0 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
IanBenzMaxim 0:33d4e66780c0 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
IanBenzMaxim 0:33d4e66780c0 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
IanBenzMaxim 0:33d4e66780c0 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
IanBenzMaxim 0:33d4e66780c0 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
IanBenzMaxim 0:33d4e66780c0 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IanBenzMaxim 0:33d4e66780c0 34 *
IanBenzMaxim 0:33d4e66780c0 35 */
IanBenzMaxim 0:33d4e66780c0 36
IanBenzMaxim 0:33d4e66780c0 37 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 38 /* Include files */
IanBenzMaxim 0:33d4e66780c0 39 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 40
IanBenzMaxim 0:33d4e66780c0 41 #include "simplelink.h"
IanBenzMaxim 0:33d4e66780c0 42
IanBenzMaxim 0:33d4e66780c0 43 #ifndef __FS_H__
IanBenzMaxim 0:33d4e66780c0 44 #define __FS_H__
IanBenzMaxim 0:33d4e66780c0 45
IanBenzMaxim 0:33d4e66780c0 46
IanBenzMaxim 0:33d4e66780c0 47
IanBenzMaxim 0:33d4e66780c0 48 #ifdef __cplusplus
IanBenzMaxim 0:33d4e66780c0 49 extern "C" {
IanBenzMaxim 0:33d4e66780c0 50 #endif
IanBenzMaxim 0:33d4e66780c0 51
IanBenzMaxim 0:33d4e66780c0 52 /*!
IanBenzMaxim 0:33d4e66780c0 53
IanBenzMaxim 0:33d4e66780c0 54 \addtogroup FileSystem
IanBenzMaxim 0:33d4e66780c0 55 @{
IanBenzMaxim 0:33d4e66780c0 56
IanBenzMaxim 0:33d4e66780c0 57 */
IanBenzMaxim 0:33d4e66780c0 58
IanBenzMaxim 0:33d4e66780c0 59 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 60 /* Macro declarations */
IanBenzMaxim 0:33d4e66780c0 61 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 62
IanBenzMaxim 0:33d4e66780c0 63 /* FS error codes */
IanBenzMaxim 0:33d4e66780c0 64 #define SL_FS_OK (0)
IanBenzMaxim 0:33d4e66780c0 65 #define SL_FS_ERR_EMPTY_SFLASH (-67)
IanBenzMaxim 0:33d4e66780c0 66 #define SL_FS_ERR_FILE_IS_NOT_SECURE_AND_SIGN (-66)
IanBenzMaxim 0:33d4e66780c0 67 #define SL_FS_ERASING_FLASH (-65)
IanBenzMaxim 0:33d4e66780c0 68 #define SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY (-64)
IanBenzMaxim 0:33d4e66780c0 69 #define SL_FS_WRONG_SIGNATURE (-63)
IanBenzMaxim 0:33d4e66780c0 70 #define SL_FS_WRONG_SIGNATURE_OR_CERTIFIC_NAME_LENGTH (-62)
IanBenzMaxim 0:33d4e66780c0 71 #define SL_FS_NOT_16_ALIGNED (-61)
IanBenzMaxim 0:33d4e66780c0 72 #define SL_FS_CERT_CHAIN_ERROR (-60)
IanBenzMaxim 0:33d4e66780c0 73 #define SL_FS_FILE_NAME_EXIST (-59)
IanBenzMaxim 0:33d4e66780c0 74 #define SL_FS_SECURITY_BUF_ALREADY_ALLOC (-58)
IanBenzMaxim 0:33d4e66780c0 75 #define SL_FS_SECURE_FILE_MUST_BE_COMMIT (-57)
IanBenzMaxim 0:33d4e66780c0 76 #define SL_FS_ERR_INCORRECT_OFFSET_ALIGNMENT (-56)
IanBenzMaxim 0:33d4e66780c0 77 #define SL_FS_ERR_FAILED_READ_NVMEM_HEADER (-55)
IanBenzMaxim 0:33d4e66780c0 78 #define SL_FS_WRONG_FILE_NAME (-54)
IanBenzMaxim 0:33d4e66780c0 79 #define SL_FS_FILE_SYSTEM_IS_LOCKED (-53)
IanBenzMaxim 0:33d4e66780c0 80 #define SL_FS_SECURITY_ALLERT (-52)
IanBenzMaxim 0:33d4e66780c0 81 #define SL_FS_FILE_UNVALID_FILE_SIZE (-51)
IanBenzMaxim 0:33d4e66780c0 82 #define SL_FS_ERR_TOKEN_IS_NOT_VALID (-50)
IanBenzMaxim 0:33d4e66780c0 83 #define SL_FS_NO_DEVICE_IS_LOADED (-49)
IanBenzMaxim 0:33d4e66780c0 84 #define SL_FS_DATA_ADDRESS_SHOUD_BE_IN_DATA_RAM (-48)
IanBenzMaxim 0:33d4e66780c0 85 #define SL_FS_DATA_IS_NOT_ALIGNED (-47)
IanBenzMaxim 0:33d4e66780c0 86 #define SL_FS_ERR_OVERLAP_DETECTION_THRESHHOLD (-46)
IanBenzMaxim 0:33d4e66780c0 87 #define SL_FS_FILE_HAS_RESERVED_NV_INDEX (-45)
IanBenzMaxim 0:33d4e66780c0 88 #define SL_FS_ERR_MAX_FS_FILES_IS_LARGER (-44)
IanBenzMaxim 0:33d4e66780c0 89 #define SL_FS_ERR_MAX_FS_FILES_IS_SMALLER (-43)
IanBenzMaxim 0:33d4e66780c0 90 #define SL_FS_FILE_MAX_SIZE_EXCEEDED (-42)
IanBenzMaxim 0:33d4e66780c0 91 #define SL_FS_INVALID_BUFFER_FOR_READ (-41)
IanBenzMaxim 0:33d4e66780c0 92 #define SL_FS_INVALID_BUFFER_FOR_WRITE (-40)
IanBenzMaxim 0:33d4e66780c0 93 #define SL_FS_ERR_FILE_IMAGE_IS_CORRUPTED (-39)
IanBenzMaxim 0:33d4e66780c0 94 #define SL_FS_ERR_SIZE_OF_FILE_EXT_EXCEEDED (-38)
IanBenzMaxim 0:33d4e66780c0 95 #define SL_FS_WARNING_FILE_NAME_NOT_KEPT (-37)
IanBenzMaxim 0:33d4e66780c0 96 #define SL_FS_ERR_DEVICE_IS_NOT_FORMATTED (-36)
IanBenzMaxim 0:33d4e66780c0 97 #define SL_FS_ERR_FAILED_WRITE_NVMEM_HEADER (-35)
IanBenzMaxim 0:33d4e66780c0 98 #define SL_FS_ERR_NO_AVAILABLE_NV_INDEX (-34)
IanBenzMaxim 0:33d4e66780c0 99 #define SL_FS_ERR_FAILED_TO_ALLOCATE_MEM (-33)
IanBenzMaxim 0:33d4e66780c0 100 #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_2 (-32)
IanBenzMaxim 0:33d4e66780c0 101 #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_1 (-31)
IanBenzMaxim 0:33d4e66780c0 102 #define SL_FS_ERR_NO_AVAILABLE_BLOCKS (-30)
IanBenzMaxim 0:33d4e66780c0 103 #define SL_FS_ERR_FILE_MAX_SIZE_BIGGER_THAN_EXISTING_FILE (-29)
IanBenzMaxim 0:33d4e66780c0 104 #define SL_FS_ERR_FILE_EXISTS_ON_DIFFERENT_DEVICE_ID (-28)
IanBenzMaxim 0:33d4e66780c0 105 #define SL_FS_ERR_INVALID_ACCESS_TYPE (-27)
IanBenzMaxim 0:33d4e66780c0 106 #define SL_FS_ERR_FILE_ALREADY_EXISTS (-26)
IanBenzMaxim 0:33d4e66780c0 107 #define SL_FS_ERR_PROGRAM (-25)
IanBenzMaxim 0:33d4e66780c0 108 #define SL_FS_ERR_NO_ENTRIES_AVAILABLE (-24)
IanBenzMaxim 0:33d4e66780c0 109 #define SL_FS_ERR_FILE_ACCESS_IS_DIFFERENT (-23)
IanBenzMaxim 0:33d4e66780c0 110 #define SL_FS_ERR_BAD_FILE_MODE (-22)
IanBenzMaxim 0:33d4e66780c0 111 #define SL_FS_ERR_FAILED_READ_NVFILE (-21)
IanBenzMaxim 0:33d4e66780c0 112 #define SL_FS_ERR_FAILED_INIT_STORAGE (-20)
IanBenzMaxim 0:33d4e66780c0 113 #define SL_FS_ERR_CONTINUE_WRITE_MUST_BE_MOD_4 (-19)
IanBenzMaxim 0:33d4e66780c0 114 #define SL_FS_ERR_FAILED_LOAD_FILE (-18)
IanBenzMaxim 0:33d4e66780c0 115 #define SL_FS_ERR_INVALID_HANDLE (-17)
IanBenzMaxim 0:33d4e66780c0 116 #define SL_FS_ERR_FAILED_TO_WRITE (-16)
IanBenzMaxim 0:33d4e66780c0 117 #define SL_FS_ERR_OFFSET_OUT_OF_RANGE (-15)
IanBenzMaxim 0:33d4e66780c0 118 #define SL_FS_ERR_ALLOC (-14)
IanBenzMaxim 0:33d4e66780c0 119 #define SL_FS_ERR_READ_DATA_LENGTH (-13)
IanBenzMaxim 0:33d4e66780c0 120 #define SL_FS_ERR_INVALID_FILE_ID (-12)
IanBenzMaxim 0:33d4e66780c0 121 #define SL_FS_ERR_FILE_NOT_EXISTS (-11)
IanBenzMaxim 0:33d4e66780c0 122 #define SL_FS_ERR_EMPTY_ERROR (-10)
IanBenzMaxim 0:33d4e66780c0 123 #define SL_FS_ERR_INVALID_ARGS (-9)
IanBenzMaxim 0:33d4e66780c0 124 #define SL_FS_ERR_FAILED_TO_CREATE_FILE (-8)
IanBenzMaxim 0:33d4e66780c0 125 #define SL_FS_ERR_FS_ALREADY_LOADED (-7)
IanBenzMaxim 0:33d4e66780c0 126 #define SL_FS_ERR_UNKNOWN (-6)
IanBenzMaxim 0:33d4e66780c0 127 #define SL_FS_ERR_FAILED_TO_CREATE_LOCK_OBJ (-5)
IanBenzMaxim 0:33d4e66780c0 128 #define SL_FS_ERR_DEVICE_NOT_LOADED (-4)
IanBenzMaxim 0:33d4e66780c0 129 #define SL_FS_ERR_INVALID_MAGIC_NUM (-3)
IanBenzMaxim 0:33d4e66780c0 130 #define SL_FS_ERR_FAILED_TO_READ (-2)
IanBenzMaxim 0:33d4e66780c0 131 #define SL_FS_ERR_NOT_SUPPORTED (-1)
IanBenzMaxim 0:33d4e66780c0 132 /* end of error codes */
IanBenzMaxim 0:33d4e66780c0 133
IanBenzMaxim 0:33d4e66780c0 134 #define _FS_MODE_ACCESS_RESERVED_OFFSET (24)
IanBenzMaxim 0:33d4e66780c0 135 #define _FS_MODE_ACCESS_RESERVED_MASK (0xFF)
IanBenzMaxim 0:33d4e66780c0 136 #define _FS_MODE_ACCESS_FLAGS_OFFSET (16)
IanBenzMaxim 0:33d4e66780c0 137 #define _FS_MODE_ACCESS_FLAGS_MASK (0xFF)
IanBenzMaxim 0:33d4e66780c0 138 #define _FS_MODE_ACCESS_OFFSET (12)
IanBenzMaxim 0:33d4e66780c0 139 #define _FS_MODE_ACCESS_MASK (0xF)
IanBenzMaxim 0:33d4e66780c0 140 #define _FS_MODE_OPEN_SIZE_GRAN_OFFSET (8)
IanBenzMaxim 0:33d4e66780c0 141 #define _FS_MODE_OPEN_SIZE_GRAN_MASK (0xF)
IanBenzMaxim 0:33d4e66780c0 142 #define _FS_MODE_OPEN_SIZE_OFFSET (0)
IanBenzMaxim 0:33d4e66780c0 143 #define _FS_MODE_OPEN_SIZE_MASK (0xFF)
IanBenzMaxim 0:33d4e66780c0 144 #define MAX_MODE_SIZE (0xFF)
IanBenzMaxim 0:33d4e66780c0 145 #define _FS_MODE(Access, SizeGran, Size,Flags) (_u32)(((_u32)((Access) & _FS_MODE_ACCESS_MASK)<<_FS_MODE_ACCESS_OFFSET) | \
IanBenzMaxim 0:33d4e66780c0 146 ((_u32)((SizeGran) & _FS_MODE_OPEN_SIZE_GRAN_MASK)<<_FS_MODE_OPEN_SIZE_GRAN_OFFSET) | \
IanBenzMaxim 0:33d4e66780c0 147 ((_u32)((Size) & _FS_MODE_OPEN_SIZE_MASK)<<_FS_MODE_OPEN_SIZE_OFFSET) | \
IanBenzMaxim 0:33d4e66780c0 148 ((_u32)((Flags) & _FS_MODE_ACCESS_FLAGS_MASK)<<_FS_MODE_ACCESS_FLAGS_OFFSET))
IanBenzMaxim 0:33d4e66780c0 149
IanBenzMaxim 0:33d4e66780c0 150
IanBenzMaxim 0:33d4e66780c0 151 /* sl_FsOpen options */
IanBenzMaxim 0:33d4e66780c0 152 /* Open for Read */
IanBenzMaxim 0:33d4e66780c0 153 #define FS_MODE_OPEN_READ _FS_MODE(_FS_MODE_OPEN_READ,0,0,0)
IanBenzMaxim 0:33d4e66780c0 154 /* Open for Write (in case file exist) */
IanBenzMaxim 0:33d4e66780c0 155 #define FS_MODE_OPEN_WRITE _FS_MODE(_FS_MODE_OPEN_WRITE,0,0,0)
IanBenzMaxim 0:33d4e66780c0 156 /* Open for Creating a new file */
IanBenzMaxim 0:33d4e66780c0 157 #define FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) _sl_GetCreateFsMode(maxSizeInBytes,accessModeFlags)
IanBenzMaxim 0:33d4e66780c0 158
IanBenzMaxim 0:33d4e66780c0 159 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 160 /* Structure/Enum declarations */
IanBenzMaxim 0:33d4e66780c0 161 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 162 typedef struct
IanBenzMaxim 0:33d4e66780c0 163 {
IanBenzMaxim 0:33d4e66780c0 164 _u16 flags;
IanBenzMaxim 0:33d4e66780c0 165 _u32 FileLen;
IanBenzMaxim 0:33d4e66780c0 166 _u32 AllocatedLen;
IanBenzMaxim 0:33d4e66780c0 167 _u32 Token[4];
IanBenzMaxim 0:33d4e66780c0 168 }SlFsFileInfo_t;
IanBenzMaxim 0:33d4e66780c0 169
IanBenzMaxim 0:33d4e66780c0 170 typedef enum
IanBenzMaxim 0:33d4e66780c0 171 {
IanBenzMaxim 0:33d4e66780c0 172 _FS_MODE_OPEN_READ = 0,
IanBenzMaxim 0:33d4e66780c0 173 _FS_MODE_OPEN_WRITE,
IanBenzMaxim 0:33d4e66780c0 174 _FS_MODE_OPEN_CREATE,
IanBenzMaxim 0:33d4e66780c0 175 _FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST
IanBenzMaxim 0:33d4e66780c0 176 }SlFsFileOpenAccessType_e;
IanBenzMaxim 0:33d4e66780c0 177
IanBenzMaxim 0:33d4e66780c0 178 typedef enum
IanBenzMaxim 0:33d4e66780c0 179 {
IanBenzMaxim 0:33d4e66780c0 180 _FS_FILE_OPEN_FLAG_COMMIT = 0x1, /* MIRROR - for fail safe */
IanBenzMaxim 0:33d4e66780c0 181 _FS_FILE_OPEN_FLAG_SECURE = 0x2, /* SECURE */
IanBenzMaxim 0:33d4e66780c0 182 _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST = 0x4, /* Relevant to secure file only */
IanBenzMaxim 0:33d4e66780c0 183 _FS_FILE_OPEN_FLAG_STATIC = 0x8, /* Relevant to secure file only */
IanBenzMaxim 0:33d4e66780c0 184 _FS_FILE_OPEN_FLAG_VENDOR = 0x10, /* Relevant to secure file only */
IanBenzMaxim 0:33d4e66780c0 185 _FS_FILE_PUBLIC_WRITE= 0x20, /* Relevant to secure file only, the file can be opened for write without Token */
IanBenzMaxim 0:33d4e66780c0 186 _FS_FILE_PUBLIC_READ = 0x40 /* Relevant to secure file only, the file can be opened for read without Token */
IanBenzMaxim 0:33d4e66780c0 187 }SlFileOpenFlags_e;
IanBenzMaxim 0:33d4e66780c0 188
IanBenzMaxim 0:33d4e66780c0 189 typedef enum
IanBenzMaxim 0:33d4e66780c0 190 {
IanBenzMaxim 0:33d4e66780c0 191 _FS_MODE_SIZE_GRAN_256B = 0, /* MAX_SIZE = 64K */
IanBenzMaxim 0:33d4e66780c0 192 _FS_MODE_SIZE_GRAN_1KB, /* MAX_SIZE = 256K */
IanBenzMaxim 0:33d4e66780c0 193 _FS_MODE_SIZE_GRAN_4KB, /* MAX_SZIE = 1M */
IanBenzMaxim 0:33d4e66780c0 194 _FS_MODE_SIZE_GRAN_16KB, /* MAX_SIZE = 4M */
IanBenzMaxim 0:33d4e66780c0 195 _FS_MODE_SIZE_GRAN_64KB, /* MAX_SIZE = 16M */
IanBenzMaxim 0:33d4e66780c0 196 _FS_MAX_MODE_SIZE_GRAN
IanBenzMaxim 0:33d4e66780c0 197 }_SlFsFileOpenMaxSizeGran_e;
IanBenzMaxim 0:33d4e66780c0 198
IanBenzMaxim 0:33d4e66780c0 199 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 200 /* Internal Function prototypes */
IanBenzMaxim 0:33d4e66780c0 201 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 202 _u32 _sl_GetCreateFsMode(_u32 maxSizeInBytes,_u32 accessFlags);
IanBenzMaxim 0:33d4e66780c0 203
IanBenzMaxim 0:33d4e66780c0 204 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 205 /* Function prototypes */
IanBenzMaxim 0:33d4e66780c0 206 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 207
IanBenzMaxim 0:33d4e66780c0 208 /*!
IanBenzMaxim 0:33d4e66780c0 209 \brief open file for read or write from/to storage device
IanBenzMaxim 0:33d4e66780c0 210
IanBenzMaxim 0:33d4e66780c0 211 \param[in] pFileName File Name buffer pointer
IanBenzMaxim 0:33d4e66780c0 212 \param[in] AccessModeAndMaxSize Options: As described below
IanBenzMaxim 0:33d4e66780c0 213 \param[in] pToken Reserved for future use. Use NULL for this field
IanBenzMaxim 0:33d4e66780c0 214 \param[out] pFileHandle Pointing on the file and used for read and write commands to the file
IanBenzMaxim 0:33d4e66780c0 215
IanBenzMaxim 0:33d4e66780c0 216 AccessModeAndMaxSize possible input \n
IanBenzMaxim 0:33d4e66780c0 217 FS_MODE_OPEN_READ - Read a file \n
IanBenzMaxim 0:33d4e66780c0 218 FS_MODE_OPEN_WRITE - Open for write for an existing file \n
IanBenzMaxim 0:33d4e66780c0 219 FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) - Open for creating a new file. Max file size is defined in bytes. \n
IanBenzMaxim 0:33d4e66780c0 220 For optimal FS size, use max size in 4K-512 bytes steps (e.g. 3584,7680,117760) \n
IanBenzMaxim 0:33d4e66780c0 221 Several access modes bits can be combined together from SlFileOpenFlags_e enum
IanBenzMaxim 0:33d4e66780c0 222
IanBenzMaxim 0:33d4e66780c0 223 \return On success, zero is returned. On error, an error code is returned
IanBenzMaxim 0:33d4e66780c0 224
IanBenzMaxim 0:33d4e66780c0 225 \sa sl_FsRead sl_FsWrite sl_FsClose
IanBenzMaxim 0:33d4e66780c0 226 \note belongs to \ref basic_api
IanBenzMaxim 0:33d4e66780c0 227 \warning
IanBenzMaxim 0:33d4e66780c0 228 \par Example:
IanBenzMaxim 0:33d4e66780c0 229 \code
IanBenzMaxim 0:33d4e66780c0 230 char* DeviceFileName = "MyFile.txt";
IanBenzMaxim 0:33d4e66780c0 231 unsigned long MaxSize = 63 * 1024; //62.5K is max file size
IanBenzMaxim 0:33d4e66780c0 232 long DeviceFileHandle = -1;
IanBenzMaxim 0:33d4e66780c0 233 long RetVal; //negative retval is an error
IanBenzMaxim 0:33d4e66780c0 234 unsigned long Offset = 0;
IanBenzMaxim 0:33d4e66780c0 235 unsigned char InputBuffer[100];
IanBenzMaxim 0:33d4e66780c0 236
IanBenzMaxim 0:33d4e66780c0 237 // Create a file and write data. The file in this example is secured, without signature and with a fail safe commit
IanBenzMaxim 0:33d4e66780c0 238 RetVal = sl_FsOpen((unsigned char *)DeviceFileName,
IanBenzMaxim 0:33d4e66780c0 239 FS_MODE_OPEN_CREATE(MaxSize , _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST | _FS_FILE_OPEN_FLAG_COMMIT ),
IanBenzMaxim 0:33d4e66780c0 240 NULL, &DeviceFileHandle);
IanBenzMaxim 0:33d4e66780c0 241
IanBenzMaxim 0:33d4e66780c0 242 Offset = 0;
IanBenzMaxim 0:33d4e66780c0 243 //Preferred in secure file that the Offset and the length will be aligned to 16 bytes.
IanBenzMaxim 0:33d4e66780c0 244 RetVal = sl_FsWrite( DeviceFileHandle, Offset, (unsigned char *)"HelloWorld", strlen("HelloWorld"));
IanBenzMaxim 0:33d4e66780c0 245
IanBenzMaxim 0:33d4e66780c0 246 RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0);
IanBenzMaxim 0:33d4e66780c0 247
IanBenzMaxim 0:33d4e66780c0 248 // open the same file for read, using the Token we got from the creation procedure above
IanBenzMaxim 0:33d4e66780c0 249 RetVal = sl_FsOpen((unsigned char *)DeviceFileName,
IanBenzMaxim 0:33d4e66780c0 250 FS_MODE_OPEN_READ,
IanBenzMaxim 0:33d4e66780c0 251 NULL, &DeviceFileHandle);
IanBenzMaxim 0:33d4e66780c0 252
IanBenzMaxim 0:33d4e66780c0 253 Offset = 0;
IanBenzMaxim 0:33d4e66780c0 254 RetVal = sl_FsRead( DeviceFileHandle, Offset, (unsigned char *)InputBuffer, strlen("HelloWorld"));
IanBenzMaxim 0:33d4e66780c0 255
IanBenzMaxim 0:33d4e66780c0 256 RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0);
IanBenzMaxim 0:33d4e66780c0 257
IanBenzMaxim 0:33d4e66780c0 258 \endcode
IanBenzMaxim 0:33d4e66780c0 259 */
IanBenzMaxim 0:33d4e66780c0 260 #if _SL_INCLUDE_FUNC(sl_FsOpen)
IanBenzMaxim 0:33d4e66780c0 261 _i32 sl_FsOpen(const _u8 *pFileName,const _u32 AccessModeAndMaxSize,_u32 *pToken,_i32 *pFileHandle);
IanBenzMaxim 0:33d4e66780c0 262 #endif
IanBenzMaxim 0:33d4e66780c0 263
IanBenzMaxim 0:33d4e66780c0 264 /*!
IanBenzMaxim 0:33d4e66780c0 265 \brief close file in storage device
IanBenzMaxim 0:33d4e66780c0 266
IanBenzMaxim 0:33d4e66780c0 267 \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen)
IanBenzMaxim 0:33d4e66780c0 268 \param[in] pCeritificateFileName Reserved for future use. Use NULL.
IanBenzMaxim 0:33d4e66780c0 269 \param[in] pSignature Reserved for future use. Use NULL.
IanBenzMaxim 0:33d4e66780c0 270 \param[in] SignatureLen Reserved for future use. Use 0.
IanBenzMaxim 0:33d4e66780c0 271
IanBenzMaxim 0:33d4e66780c0 272
IanBenzMaxim 0:33d4e66780c0 273 \return On success, zero is returned. On error, an error code is returned
IanBenzMaxim 0:33d4e66780c0 274
IanBenzMaxim 0:33d4e66780c0 275 \sa sl_FsRead sl_FsWrite sl_FsOpen
IanBenzMaxim 0:33d4e66780c0 276 \note Call the fs_Close with signature = 'A' signature len = 1 for activating an abort action
IanBenzMaxim 0:33d4e66780c0 277 \warning
IanBenzMaxim 0:33d4e66780c0 278 \par Example:
IanBenzMaxim 0:33d4e66780c0 279 \code
IanBenzMaxim 0:33d4e66780c0 280 sl_FsClose(FileHandle,0,0,0);
IanBenzMaxim 0:33d4e66780c0 281 \endcode
IanBenzMaxim 0:33d4e66780c0 282 */
IanBenzMaxim 0:33d4e66780c0 283 #if _SL_INCLUDE_FUNC(sl_FsClose)
IanBenzMaxim 0:33d4e66780c0 284 _i16 sl_FsClose(const _i32 FileHdl,const _u8* pCeritificateFileName,const _u8* pSignature,const _u32 SignatureLen);
IanBenzMaxim 0:33d4e66780c0 285 #endif
IanBenzMaxim 0:33d4e66780c0 286
IanBenzMaxim 0:33d4e66780c0 287 /*!
IanBenzMaxim 0:33d4e66780c0 288 \brief Read block of data from a file in storage device
IanBenzMaxim 0:33d4e66780c0 289
IanBenzMaxim 0:33d4e66780c0 290 \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen)
IanBenzMaxim 0:33d4e66780c0 291 \param[in] Offset Offset to specific read block
IanBenzMaxim 0:33d4e66780c0 292 \param[out] pData Pointer for the received data
IanBenzMaxim 0:33d4e66780c0 293 \param[in] Len Length of the received data
IanBenzMaxim 0:33d4e66780c0 294
IanBenzMaxim 0:33d4e66780c0 295 \return On success, returns the number of read bytes. On error, negative number is returned
IanBenzMaxim 0:33d4e66780c0 296
IanBenzMaxim 0:33d4e66780c0 297 \sa sl_FsClose sl_FsWrite sl_FsOpen
IanBenzMaxim 0:33d4e66780c0 298 \note belongs to \ref basic_api
IanBenzMaxim 0:33d4e66780c0 299 \warning
IanBenzMaxim 0:33d4e66780c0 300 \par Example:
IanBenzMaxim 0:33d4e66780c0 301 \code
IanBenzMaxim 0:33d4e66780c0 302 Status = sl_FsRead(FileHandle, 0, &readBuff[0], readSize);
IanBenzMaxim 0:33d4e66780c0 303 \endcode
IanBenzMaxim 0:33d4e66780c0 304 */
IanBenzMaxim 0:33d4e66780c0 305 #if _SL_INCLUDE_FUNC(sl_FsRead)
IanBenzMaxim 0:33d4e66780c0 306 _i32 sl_FsRead(const _i32 FileHdl,_u32 Offset ,_u8* pData,_u32 Len);
IanBenzMaxim 0:33d4e66780c0 307 #endif
IanBenzMaxim 0:33d4e66780c0 308
IanBenzMaxim 0:33d4e66780c0 309 /*!
IanBenzMaxim 0:33d4e66780c0 310 \brief write block of data to a file in storage device
IanBenzMaxim 0:33d4e66780c0 311
IanBenzMaxim 0:33d4e66780c0 312 \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen)
IanBenzMaxim 0:33d4e66780c0 313 \param[in] Offset Offset to specific block to be written
IanBenzMaxim 0:33d4e66780c0 314 \param[in] pData Pointer the transmitted data to the storage device
IanBenzMaxim 0:33d4e66780c0 315 \param[in] Len Length of the transmitted data
IanBenzMaxim 0:33d4e66780c0 316
IanBenzMaxim 0:33d4e66780c0 317 \return On success, returns the number of written bytes. On error, an error code is returned
IanBenzMaxim 0:33d4e66780c0 318
IanBenzMaxim 0:33d4e66780c0 319 \sa
IanBenzMaxim 0:33d4e66780c0 320 \note belongs to \ref basic_api
IanBenzMaxim 0:33d4e66780c0 321 \warning
IanBenzMaxim 0:33d4e66780c0 322 \par Example:
IanBenzMaxim 0:33d4e66780c0 323 \code
IanBenzMaxim 0:33d4e66780c0 324 Status = sl_FsWrite(FileHandle, 0, &buff[0], readSize);
IanBenzMaxim 0:33d4e66780c0 325 \endcode
IanBenzMaxim 0:33d4e66780c0 326 */
IanBenzMaxim 0:33d4e66780c0 327 #if _SL_INCLUDE_FUNC(sl_FsWrite)
IanBenzMaxim 0:33d4e66780c0 328 _i32 sl_FsWrite(const _i32 FileHdl,_u32 Offset,_u8* pData,_u32 Len);
IanBenzMaxim 0:33d4e66780c0 329 #endif
IanBenzMaxim 0:33d4e66780c0 330
IanBenzMaxim 0:33d4e66780c0 331 /*!
IanBenzMaxim 0:33d4e66780c0 332 \brief get info on a file
IanBenzMaxim 0:33d4e66780c0 333
IanBenzMaxim 0:33d4e66780c0 334 \param[in] pFileName File name
IanBenzMaxim 0:33d4e66780c0 335 \param[in] Token Reserved for future use. Use 0
IanBenzMaxim 0:33d4e66780c0 336 \param[out] pFsFileInfo Returns the File's Information: flags,file size, allocated size and Tokens
IanBenzMaxim 0:33d4e66780c0 337
IanBenzMaxim 0:33d4e66780c0 338 \return On success, zero is returned. On error, an error code is returned
IanBenzMaxim 0:33d4e66780c0 339
IanBenzMaxim 0:33d4e66780c0 340 \sa sl_FsOpen
IanBenzMaxim 0:33d4e66780c0 341 \note belongs to \ref basic_api
IanBenzMaxim 0:33d4e66780c0 342 \warning
IanBenzMaxim 0:33d4e66780c0 343 \par Example:
IanBenzMaxim 0:33d4e66780c0 344 \code
IanBenzMaxim 0:33d4e66780c0 345 Status = sl_FsGetInfo("FileName.html",0,&FsFileInfo);
IanBenzMaxim 0:33d4e66780c0 346 \endcode
IanBenzMaxim 0:33d4e66780c0 347 */
IanBenzMaxim 0:33d4e66780c0 348 #if _SL_INCLUDE_FUNC(sl_FsGetInfo)
IanBenzMaxim 0:33d4e66780c0 349 _i16 sl_FsGetInfo(const _u8 *pFileName,const _u32 Token,SlFsFileInfo_t* pFsFileInfo);
IanBenzMaxim 0:33d4e66780c0 350 #endif
IanBenzMaxim 0:33d4e66780c0 351
IanBenzMaxim 0:33d4e66780c0 352 /*!
IanBenzMaxim 0:33d4e66780c0 353 \brief Delete specific file from a storage or all files from a storage (format)
IanBenzMaxim 0:33d4e66780c0 354
IanBenzMaxim 0:33d4e66780c0 355 \param[in] pFileName File Name
IanBenzMaxim 0:33d4e66780c0 356 \param[in] Token Reserved for future use. Use 0
IanBenzMaxim 0:33d4e66780c0 357 \return On success, zero is returned. On error, an error code is returned
IanBenzMaxim 0:33d4e66780c0 358
IanBenzMaxim 0:33d4e66780c0 359 \sa
IanBenzMaxim 0:33d4e66780c0 360 \note belongs to \ref basic_api
IanBenzMaxim 0:33d4e66780c0 361 \warning
IanBenzMaxim 0:33d4e66780c0 362 \par Example:
IanBenzMaxim 0:33d4e66780c0 363 \code
IanBenzMaxim 0:33d4e66780c0 364 Status = sl_FsDel("FileName.html",0);
IanBenzMaxim 0:33d4e66780c0 365 \endcode
IanBenzMaxim 0:33d4e66780c0 366 */
IanBenzMaxim 0:33d4e66780c0 367 #if _SL_INCLUDE_FUNC(sl_FsDel)
IanBenzMaxim 0:33d4e66780c0 368 _i16 sl_FsDel(const _u8 *pFileName,const _u32 Token);
IanBenzMaxim 0:33d4e66780c0 369 #endif
IanBenzMaxim 0:33d4e66780c0 370 /*!
IanBenzMaxim 0:33d4e66780c0 371
IanBenzMaxim 0:33d4e66780c0 372 Close the Doxygen group.
IanBenzMaxim 0:33d4e66780c0 373 @}
IanBenzMaxim 0:33d4e66780c0 374
IanBenzMaxim 0:33d4e66780c0 375 */
IanBenzMaxim 0:33d4e66780c0 376
IanBenzMaxim 0:33d4e66780c0 377 #ifdef __cplusplus
IanBenzMaxim 0:33d4e66780c0 378 }
IanBenzMaxim 0:33d4e66780c0 379 #endif /* __cplusplus */
IanBenzMaxim 0:33d4e66780c0 380
IanBenzMaxim 0:33d4e66780c0 381 #endif /* __FS_H__ */
IanBenzMaxim 0:33d4e66780c0 382