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:
Thu Oct 03 11:40:13 2019 -0500
Revision:
16:a004191a79ab
Parent:
simplelink/source/fs.c@0:33d4e66780c0
Updated MaximInterface to version 2.0. Updated mbed-os to version 5.5.7. Cleaned up code styling.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:33d4e66780c0 1 /*
IanBenzMaxim 0:33d4e66780c0 2 * fs.c - 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
IanBenzMaxim 0:33d4e66780c0 39 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 40 /* Include files */
IanBenzMaxim 0:33d4e66780c0 41 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 42 #include "simplelink.h"
IanBenzMaxim 0:33d4e66780c0 43 #include "protocol.h"
IanBenzMaxim 0:33d4e66780c0 44 #include "driver.h"
IanBenzMaxim 0:33d4e66780c0 45
IanBenzMaxim 0:33d4e66780c0 46 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 47 /* Macro declarations */
IanBenzMaxim 0:33d4e66780c0 48 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 49 #define sl_min(a,b) (((a) < (b)) ? (a) : (b))
IanBenzMaxim 0:33d4e66780c0 50 #define MAX_NVMEM_CHUNK_SIZE 1460
IanBenzMaxim 0:33d4e66780c0 51
IanBenzMaxim 0:33d4e66780c0 52 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 53 /* Internal functions */
IanBenzMaxim 0:33d4e66780c0 54 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 55
IanBenzMaxim 0:33d4e66780c0 56 #ifndef SL_TINY
IanBenzMaxim 0:33d4e66780c0 57
IanBenzMaxim 0:33d4e66780c0 58 static _u16 _sl_Strlen(const _u8 *buffer);
IanBenzMaxim 0:33d4e66780c0 59
IanBenzMaxim 0:33d4e66780c0 60 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 61 /* _sl_Strlen */
IanBenzMaxim 0:33d4e66780c0 62 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 63 static _u16 _sl_Strlen(const _u8 *buffer)
IanBenzMaxim 0:33d4e66780c0 64 {
IanBenzMaxim 0:33d4e66780c0 65 _u16 len = 0;
IanBenzMaxim 0:33d4e66780c0 66 if( buffer != NULL )
IanBenzMaxim 0:33d4e66780c0 67 {
IanBenzMaxim 0:33d4e66780c0 68 while(*buffer++) len++;
IanBenzMaxim 0:33d4e66780c0 69 }
IanBenzMaxim 0:33d4e66780c0 70 return len;
IanBenzMaxim 0:33d4e66780c0 71 }
IanBenzMaxim 0:33d4e66780c0 72
IanBenzMaxim 0:33d4e66780c0 73 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 74 /* _sl_GetCreateFsMode */
IanBenzMaxim 0:33d4e66780c0 75 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 76 _u32 _sl_GetCreateFsMode(_u32 maxSizeInBytes,_u32 accessFlags)
IanBenzMaxim 0:33d4e66780c0 77 {
IanBenzMaxim 0:33d4e66780c0 78 _u32 granIdx = 0;
IanBenzMaxim 0:33d4e66780c0 79 _u32 granNum = 0;
IanBenzMaxim 0:33d4e66780c0 80 _u32 granTable[_FS_MAX_MODE_SIZE_GRAN] = {256,1024,4096,16384,65536};
IanBenzMaxim 0:33d4e66780c0 81 for(granIdx= _FS_MODE_SIZE_GRAN_256B ;granIdx< _FS_MAX_MODE_SIZE_GRAN;granIdx++)
IanBenzMaxim 0:33d4e66780c0 82 {
IanBenzMaxim 0:33d4e66780c0 83 if( granTable[granIdx]*255 >= maxSizeInBytes )
IanBenzMaxim 0:33d4e66780c0 84 break;
IanBenzMaxim 0:33d4e66780c0 85 }
IanBenzMaxim 0:33d4e66780c0 86 granNum = maxSizeInBytes/granTable[granIdx];
IanBenzMaxim 0:33d4e66780c0 87 if( maxSizeInBytes % granTable[granIdx] != 0 )
IanBenzMaxim 0:33d4e66780c0 88 granNum++;
IanBenzMaxim 0:33d4e66780c0 89
IanBenzMaxim 0:33d4e66780c0 90 return _FS_MODE(_FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST, granIdx, granNum, accessFlags);
IanBenzMaxim 0:33d4e66780c0 91 }
IanBenzMaxim 0:33d4e66780c0 92
IanBenzMaxim 0:33d4e66780c0 93 #endif
IanBenzMaxim 0:33d4e66780c0 94
IanBenzMaxim 0:33d4e66780c0 95 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 96 /* API functions */
IanBenzMaxim 0:33d4e66780c0 97 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 98
IanBenzMaxim 0:33d4e66780c0 99 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 100 /* sl_FsOpen */
IanBenzMaxim 0:33d4e66780c0 101 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 102 typedef union
IanBenzMaxim 0:33d4e66780c0 103 {
IanBenzMaxim 0:33d4e66780c0 104 _FsOpenCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 105 _FsOpenResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 106 }_SlFsOpenMsg_u;
IanBenzMaxim 0:33d4e66780c0 107
IanBenzMaxim 0:33d4e66780c0 108
IanBenzMaxim 0:33d4e66780c0 109 #if _SL_INCLUDE_FUNC(sl_FsOpen)
IanBenzMaxim 0:33d4e66780c0 110
IanBenzMaxim 0:33d4e66780c0 111 static const _SlCmdCtrl_t _SlFsOpenCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 112 {
IanBenzMaxim 0:33d4e66780c0 113 SL_OPCODE_NVMEM_FILEOPEN,
IanBenzMaxim 0:33d4e66780c0 114 (_SlArgSize_t)sizeof(_FsOpenCommand_t),
IanBenzMaxim 0:33d4e66780c0 115 (_SlArgSize_t)sizeof(_FsOpenResponse_t)
IanBenzMaxim 0:33d4e66780c0 116 };
IanBenzMaxim 0:33d4e66780c0 117
IanBenzMaxim 0:33d4e66780c0 118 _i32 sl_FsOpen(const _u8 *pFileName,const _u32 AccessModeAndMaxSize, _u32 *pToken,_i32 *pFileHandle)
IanBenzMaxim 0:33d4e66780c0 119 {
IanBenzMaxim 0:33d4e66780c0 120 _SlReturnVal_t RetVal;
IanBenzMaxim 0:33d4e66780c0 121 _SlFsOpenMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 122 _SlCmdExt_t CmdExt;
IanBenzMaxim 0:33d4e66780c0 123
IanBenzMaxim 0:33d4e66780c0 124 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 125 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 126 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 127
IanBenzMaxim 0:33d4e66780c0 128 CmdExt.TxPayloadLen = (_u16)((_sl_Strlen(pFileName)+4) & (~3)); /* add 4: 1 for NULL and the 3 for align */
IanBenzMaxim 0:33d4e66780c0 129 CmdExt.RxPayloadLen = 0;
IanBenzMaxim 0:33d4e66780c0 130 CmdExt.pTxPayload = (_u8*)pFileName;
IanBenzMaxim 0:33d4e66780c0 131 CmdExt.pRxPayload = NULL;
IanBenzMaxim 0:33d4e66780c0 132
IanBenzMaxim 0:33d4e66780c0 133 Msg.Cmd.Mode = AccessModeAndMaxSize;
IanBenzMaxim 0:33d4e66780c0 134
IanBenzMaxim 0:33d4e66780c0 135 if(pToken != NULL)
IanBenzMaxim 0:33d4e66780c0 136 {
IanBenzMaxim 0:33d4e66780c0 137 Msg.Cmd.Token = *pToken;
IanBenzMaxim 0:33d4e66780c0 138 }
IanBenzMaxim 0:33d4e66780c0 139 else
IanBenzMaxim 0:33d4e66780c0 140 {
IanBenzMaxim 0:33d4e66780c0 141 Msg.Cmd.Token = 0;
IanBenzMaxim 0:33d4e66780c0 142 }
IanBenzMaxim 0:33d4e66780c0 143
IanBenzMaxim 0:33d4e66780c0 144 RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsOpenCmdCtrl, &Msg, &CmdExt);
IanBenzMaxim 0:33d4e66780c0 145 *pFileHandle = (_i32)Msg.Rsp.FileHandle;
IanBenzMaxim 0:33d4e66780c0 146 if (pToken != NULL)
IanBenzMaxim 0:33d4e66780c0 147 {
IanBenzMaxim 0:33d4e66780c0 148 *pToken = Msg.Rsp.Token;
IanBenzMaxim 0:33d4e66780c0 149 }
IanBenzMaxim 0:33d4e66780c0 150
IanBenzMaxim 0:33d4e66780c0 151 /* in case of an error, return the erros file handler as an error code */
IanBenzMaxim 0:33d4e66780c0 152 if( *pFileHandle < 0 )
IanBenzMaxim 0:33d4e66780c0 153 {
IanBenzMaxim 0:33d4e66780c0 154 return *pFileHandle;
IanBenzMaxim 0:33d4e66780c0 155 }
IanBenzMaxim 0:33d4e66780c0 156 return (_i32)RetVal;
IanBenzMaxim 0:33d4e66780c0 157 }
IanBenzMaxim 0:33d4e66780c0 158 #endif
IanBenzMaxim 0:33d4e66780c0 159
IanBenzMaxim 0:33d4e66780c0 160 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 161 /* sl_FsClose */
IanBenzMaxim 0:33d4e66780c0 162 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 163 typedef union
IanBenzMaxim 0:33d4e66780c0 164 {
IanBenzMaxim 0:33d4e66780c0 165 _FsCloseCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 166 _BasicResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 167 }_SlFsCloseMsg_u;
IanBenzMaxim 0:33d4e66780c0 168
IanBenzMaxim 0:33d4e66780c0 169
IanBenzMaxim 0:33d4e66780c0 170 #if _SL_INCLUDE_FUNC(sl_FsClose)
IanBenzMaxim 0:33d4e66780c0 171
IanBenzMaxim 0:33d4e66780c0 172 static const _SlCmdCtrl_t _SlFsCloseCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 173 {
IanBenzMaxim 0:33d4e66780c0 174 SL_OPCODE_NVMEM_FILECLOSE,
IanBenzMaxim 0:33d4e66780c0 175 (_SlArgSize_t)sizeof(_FsCloseCommand_t),
IanBenzMaxim 0:33d4e66780c0 176 (_SlArgSize_t)sizeof(_FsCloseResponse_t)
IanBenzMaxim 0:33d4e66780c0 177 };
IanBenzMaxim 0:33d4e66780c0 178
IanBenzMaxim 0:33d4e66780c0 179
IanBenzMaxim 0:33d4e66780c0 180 _i16 sl_FsClose(const _i32 FileHdl, const _u8* pCeritificateFileName,const _u8* pSignature ,const _u32 SignatureLen)
IanBenzMaxim 0:33d4e66780c0 181 {
IanBenzMaxim 0:33d4e66780c0 182 _SlFsCloseMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 183 _SlCmdExt_t ExtCtrl;
IanBenzMaxim 0:33d4e66780c0 184
IanBenzMaxim 0:33d4e66780c0 185 _SlDrvMemZero(&Msg, (_u16)sizeof(_FsCloseCommand_t));
IanBenzMaxim 0:33d4e66780c0 186
IanBenzMaxim 0:33d4e66780c0 187 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 188 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 189 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 190
IanBenzMaxim 0:33d4e66780c0 191 Msg.Cmd.FileHandle = (_u32)FileHdl;
IanBenzMaxim 0:33d4e66780c0 192 if( pCeritificateFileName != NULL )
IanBenzMaxim 0:33d4e66780c0 193 {
IanBenzMaxim 0:33d4e66780c0 194 Msg.Cmd.CertificFileNameLength = (_u32)((_sl_Strlen(pCeritificateFileName)+4) & (~3)); /* add 4: 1 for NULL and the 3 for align */
IanBenzMaxim 0:33d4e66780c0 195 }
IanBenzMaxim 0:33d4e66780c0 196 Msg.Cmd.SignatureLen = SignatureLen;
IanBenzMaxim 0:33d4e66780c0 197
IanBenzMaxim 0:33d4e66780c0 198 ExtCtrl.TxPayloadLen = (_u16)(((SignatureLen+3) & (~3))); /* align */
IanBenzMaxim 0:33d4e66780c0 199 ExtCtrl.pTxPayload = (_u8*)pSignature;
IanBenzMaxim 0:33d4e66780c0 200 ExtCtrl.RxPayloadLen = (_i16)Msg.Cmd.CertificFileNameLength;
IanBenzMaxim 0:33d4e66780c0 201 ExtCtrl.pRxPayload = (_u8*)pCeritificateFileName; /* Add signature */
IanBenzMaxim 0:33d4e66780c0 202
IanBenzMaxim 0:33d4e66780c0 203 if(ExtCtrl.pRxPayload != NULL && ExtCtrl.RxPayloadLen != 0)
IanBenzMaxim 0:33d4e66780c0 204 {
IanBenzMaxim 0:33d4e66780c0 205 ExtCtrl.RxPayloadLen = ExtCtrl.RxPayloadLen * (-1);
IanBenzMaxim 0:33d4e66780c0 206 }
IanBenzMaxim 0:33d4e66780c0 207
IanBenzMaxim 0:33d4e66780c0 208 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsCloseCmdCtrl, &Msg, &ExtCtrl));
IanBenzMaxim 0:33d4e66780c0 209
IanBenzMaxim 0:33d4e66780c0 210 return (_i16)((_i16)Msg.Rsp.status);
IanBenzMaxim 0:33d4e66780c0 211 }
IanBenzMaxim 0:33d4e66780c0 212 #endif
IanBenzMaxim 0:33d4e66780c0 213
IanBenzMaxim 0:33d4e66780c0 214
IanBenzMaxim 0:33d4e66780c0 215 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 216 /* sl_FsRead */
IanBenzMaxim 0:33d4e66780c0 217 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 218 typedef union
IanBenzMaxim 0:33d4e66780c0 219 {
IanBenzMaxim 0:33d4e66780c0 220 _FsReadCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 221 _FsReadResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 222 }_SlFsReadMsg_u;
IanBenzMaxim 0:33d4e66780c0 223
IanBenzMaxim 0:33d4e66780c0 224 #if _SL_INCLUDE_FUNC(sl_FsRead)
IanBenzMaxim 0:33d4e66780c0 225
IanBenzMaxim 0:33d4e66780c0 226
IanBenzMaxim 0:33d4e66780c0 227 static const _SlCmdCtrl_t _SlFsReadCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 228 {
IanBenzMaxim 0:33d4e66780c0 229 SL_OPCODE_NVMEM_FILEREADCOMMAND,
IanBenzMaxim 0:33d4e66780c0 230 (_SlArgSize_t)sizeof(_FsReadCommand_t),
IanBenzMaxim 0:33d4e66780c0 231 (_SlArgSize_t)sizeof(_FsReadResponse_t)
IanBenzMaxim 0:33d4e66780c0 232 };
IanBenzMaxim 0:33d4e66780c0 233
IanBenzMaxim 0:33d4e66780c0 234 _i32 sl_FsRead(const _i32 FileHdl,_u32 Offset, _u8* pData,_u32 Len)
IanBenzMaxim 0:33d4e66780c0 235 {
IanBenzMaxim 0:33d4e66780c0 236 _SlFsReadMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 237 _SlCmdExt_t ExtCtrl;
IanBenzMaxim 0:33d4e66780c0 238 _u16 ChunkLen;
IanBenzMaxim 0:33d4e66780c0 239 _SlReturnVal_t RetVal =0;
IanBenzMaxim 0:33d4e66780c0 240 _i32 RetCount = 0;
IanBenzMaxim 0:33d4e66780c0 241
IanBenzMaxim 0:33d4e66780c0 242 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 243 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 244 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 245
IanBenzMaxim 0:33d4e66780c0 246 ExtCtrl.TxPayloadLen = 0;
IanBenzMaxim 0:33d4e66780c0 247 ExtCtrl.pTxPayload = NULL;
IanBenzMaxim 0:33d4e66780c0 248
IanBenzMaxim 0:33d4e66780c0 249 ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
IanBenzMaxim 0:33d4e66780c0 250 ExtCtrl.RxPayloadLen = (_i16)ChunkLen;
IanBenzMaxim 0:33d4e66780c0 251 ExtCtrl.pRxPayload = (_u8 *)(pData);
IanBenzMaxim 0:33d4e66780c0 252 Msg.Cmd.Offset = Offset;
IanBenzMaxim 0:33d4e66780c0 253 Msg.Cmd.Len = ChunkLen;
IanBenzMaxim 0:33d4e66780c0 254 Msg.Cmd.FileHandle = (_u32)FileHdl;
IanBenzMaxim 0:33d4e66780c0 255 do
IanBenzMaxim 0:33d4e66780c0 256 {
IanBenzMaxim 0:33d4e66780c0 257 RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsReadCmdCtrl, &Msg, &ExtCtrl);
IanBenzMaxim 0:33d4e66780c0 258 if(SL_OS_RET_CODE_OK == RetVal)
IanBenzMaxim 0:33d4e66780c0 259 {
IanBenzMaxim 0:33d4e66780c0 260 if( Msg.Rsp.status < 0)
IanBenzMaxim 0:33d4e66780c0 261 {
IanBenzMaxim 0:33d4e66780c0 262 if( RetCount > 0)
IanBenzMaxim 0:33d4e66780c0 263 {
IanBenzMaxim 0:33d4e66780c0 264 return RetCount;
IanBenzMaxim 0:33d4e66780c0 265 }
IanBenzMaxim 0:33d4e66780c0 266 else
IanBenzMaxim 0:33d4e66780c0 267 {
IanBenzMaxim 0:33d4e66780c0 268 return Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 269 }
IanBenzMaxim 0:33d4e66780c0 270 }
IanBenzMaxim 0:33d4e66780c0 271 RetCount += (_i32)Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 272 Len -= ChunkLen;
IanBenzMaxim 0:33d4e66780c0 273 Offset += ChunkLen;
IanBenzMaxim 0:33d4e66780c0 274 Msg.Cmd.Offset = Offset;
IanBenzMaxim 0:33d4e66780c0 275 ExtCtrl.pRxPayload += ChunkLen;
IanBenzMaxim 0:33d4e66780c0 276 ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
IanBenzMaxim 0:33d4e66780c0 277 ExtCtrl.RxPayloadLen = (_i16)ChunkLen;
IanBenzMaxim 0:33d4e66780c0 278 Msg.Cmd.Len = ChunkLen;
IanBenzMaxim 0:33d4e66780c0 279 Msg.Cmd.FileHandle = (_u32)FileHdl;
IanBenzMaxim 0:33d4e66780c0 280 }
IanBenzMaxim 0:33d4e66780c0 281 else
IanBenzMaxim 0:33d4e66780c0 282 {
IanBenzMaxim 0:33d4e66780c0 283 return RetVal;
IanBenzMaxim 0:33d4e66780c0 284 }
IanBenzMaxim 0:33d4e66780c0 285 }while(ChunkLen > 0);
IanBenzMaxim 0:33d4e66780c0 286
IanBenzMaxim 0:33d4e66780c0 287 return (_i32)RetCount;
IanBenzMaxim 0:33d4e66780c0 288 }
IanBenzMaxim 0:33d4e66780c0 289 #endif
IanBenzMaxim 0:33d4e66780c0 290
IanBenzMaxim 0:33d4e66780c0 291 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 292 /* sl_FsWrite */
IanBenzMaxim 0:33d4e66780c0 293 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 294 typedef union
IanBenzMaxim 0:33d4e66780c0 295 {
IanBenzMaxim 0:33d4e66780c0 296 _FsWriteCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 297 _FsWriteResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 298 }_SlFsWriteMsg_u;
IanBenzMaxim 0:33d4e66780c0 299
IanBenzMaxim 0:33d4e66780c0 300
IanBenzMaxim 0:33d4e66780c0 301 #if _SL_INCLUDE_FUNC(sl_FsWrite)
IanBenzMaxim 0:33d4e66780c0 302
IanBenzMaxim 0:33d4e66780c0 303 static const _SlCmdCtrl_t _SlFsWriteCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 304 {
IanBenzMaxim 0:33d4e66780c0 305 SL_OPCODE_NVMEM_FILEWRITECOMMAND,
IanBenzMaxim 0:33d4e66780c0 306 (_SlArgSize_t)sizeof(_FsWriteCommand_t),
IanBenzMaxim 0:33d4e66780c0 307 (_SlArgSize_t)sizeof(_FsWriteResponse_t)
IanBenzMaxim 0:33d4e66780c0 308 };
IanBenzMaxim 0:33d4e66780c0 309
IanBenzMaxim 0:33d4e66780c0 310 _i32 sl_FsWrite(const _i32 FileHdl,_u32 Offset, _u8* pData,_u32 Len)
IanBenzMaxim 0:33d4e66780c0 311 {
IanBenzMaxim 0:33d4e66780c0 312 _SlFsWriteMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 313 _SlCmdExt_t ExtCtrl;
IanBenzMaxim 0:33d4e66780c0 314 _u16 ChunkLen;
IanBenzMaxim 0:33d4e66780c0 315 _SlReturnVal_t RetVal;
IanBenzMaxim 0:33d4e66780c0 316 _i32 RetCount = 0;
IanBenzMaxim 0:33d4e66780c0 317
IanBenzMaxim 0:33d4e66780c0 318 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 319 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 320 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 321
IanBenzMaxim 0:33d4e66780c0 322 ExtCtrl.RxPayloadLen = 0;
IanBenzMaxim 0:33d4e66780c0 323 ExtCtrl.pRxPayload = NULL;
IanBenzMaxim 0:33d4e66780c0 324
IanBenzMaxim 0:33d4e66780c0 325 ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
IanBenzMaxim 0:33d4e66780c0 326 ExtCtrl.TxPayloadLen = ChunkLen;
IanBenzMaxim 0:33d4e66780c0 327 ExtCtrl.pTxPayload = (_u8 *)(pData);
IanBenzMaxim 0:33d4e66780c0 328 Msg.Cmd.Offset = Offset;
IanBenzMaxim 0:33d4e66780c0 329 Msg.Cmd.Len = ChunkLen;
IanBenzMaxim 0:33d4e66780c0 330 Msg.Cmd.FileHandle = (_u32)FileHdl;
IanBenzMaxim 0:33d4e66780c0 331
IanBenzMaxim 0:33d4e66780c0 332 do
IanBenzMaxim 0:33d4e66780c0 333 {
IanBenzMaxim 0:33d4e66780c0 334
IanBenzMaxim 0:33d4e66780c0 335 RetVal = _SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsWriteCmdCtrl, &Msg, &ExtCtrl);
IanBenzMaxim 0:33d4e66780c0 336 if(SL_OS_RET_CODE_OK == RetVal)
IanBenzMaxim 0:33d4e66780c0 337 {
IanBenzMaxim 0:33d4e66780c0 338 if( Msg.Rsp.status < 0)
IanBenzMaxim 0:33d4e66780c0 339 {
IanBenzMaxim 0:33d4e66780c0 340 if( RetCount > 0)
IanBenzMaxim 0:33d4e66780c0 341 {
IanBenzMaxim 0:33d4e66780c0 342 return RetCount;
IanBenzMaxim 0:33d4e66780c0 343 }
IanBenzMaxim 0:33d4e66780c0 344 else
IanBenzMaxim 0:33d4e66780c0 345 {
IanBenzMaxim 0:33d4e66780c0 346 return Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 347 }
IanBenzMaxim 0:33d4e66780c0 348 }
IanBenzMaxim 0:33d4e66780c0 349
IanBenzMaxim 0:33d4e66780c0 350 RetCount += (_i32)Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 351 Len -= ChunkLen;
IanBenzMaxim 0:33d4e66780c0 352 Offset += ChunkLen;
IanBenzMaxim 0:33d4e66780c0 353 Msg.Cmd.Offset = Offset;
IanBenzMaxim 0:33d4e66780c0 354 ExtCtrl.pTxPayload += ChunkLen;
IanBenzMaxim 0:33d4e66780c0 355 ChunkLen = (_u16)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
IanBenzMaxim 0:33d4e66780c0 356 ExtCtrl.TxPayloadLen = ChunkLen;
IanBenzMaxim 0:33d4e66780c0 357 Msg.Cmd.Len = ChunkLen;
IanBenzMaxim 0:33d4e66780c0 358 Msg.Cmd.FileHandle = (_u32)FileHdl;
IanBenzMaxim 0:33d4e66780c0 359 }
IanBenzMaxim 0:33d4e66780c0 360 else
IanBenzMaxim 0:33d4e66780c0 361 {
IanBenzMaxim 0:33d4e66780c0 362 return RetVal;
IanBenzMaxim 0:33d4e66780c0 363 }
IanBenzMaxim 0:33d4e66780c0 364 }while(ChunkLen > 0);
IanBenzMaxim 0:33d4e66780c0 365
IanBenzMaxim 0:33d4e66780c0 366 return (_i32)RetCount;
IanBenzMaxim 0:33d4e66780c0 367 }
IanBenzMaxim 0:33d4e66780c0 368 #endif
IanBenzMaxim 0:33d4e66780c0 369
IanBenzMaxim 0:33d4e66780c0 370 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 371 /* sl_FsGetInfo */
IanBenzMaxim 0:33d4e66780c0 372 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 373 typedef union
IanBenzMaxim 0:33d4e66780c0 374 {
IanBenzMaxim 0:33d4e66780c0 375 _FsGetInfoCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 376 _FsGetInfoResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 377 }_SlFsGetInfoMsg_u;
IanBenzMaxim 0:33d4e66780c0 378
IanBenzMaxim 0:33d4e66780c0 379
IanBenzMaxim 0:33d4e66780c0 380 #if _SL_INCLUDE_FUNC(sl_FsGetInfo)
IanBenzMaxim 0:33d4e66780c0 381
IanBenzMaxim 0:33d4e66780c0 382
IanBenzMaxim 0:33d4e66780c0 383 static const _SlCmdCtrl_t _SlFsGetInfoCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 384 {
IanBenzMaxim 0:33d4e66780c0 385 SL_OPCODE_NVMEM_FILEGETINFOCOMMAND,
IanBenzMaxim 0:33d4e66780c0 386 (_SlArgSize_t)sizeof(_FsGetInfoCommand_t),
IanBenzMaxim 0:33d4e66780c0 387 (_SlArgSize_t)sizeof(_FsGetInfoResponse_t)
IanBenzMaxim 0:33d4e66780c0 388 };
IanBenzMaxim 0:33d4e66780c0 389
IanBenzMaxim 0:33d4e66780c0 390 _i16 sl_FsGetInfo(const _u8 *pFileName,const _u32 Token,SlFsFileInfo_t* pFsFileInfo)
IanBenzMaxim 0:33d4e66780c0 391 {
IanBenzMaxim 0:33d4e66780c0 392 _SlFsGetInfoMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 393 _SlCmdExt_t CmdExt;
IanBenzMaxim 0:33d4e66780c0 394
IanBenzMaxim 0:33d4e66780c0 395 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 396 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 397 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 398
IanBenzMaxim 0:33d4e66780c0 399 CmdExt.TxPayloadLen = (_u16)((_sl_Strlen(pFileName)+4) & (~3)); /* add 4: 1 for NULL and the 3 for align */
IanBenzMaxim 0:33d4e66780c0 400 CmdExt.RxPayloadLen = 0;
IanBenzMaxim 0:33d4e66780c0 401 CmdExt.pTxPayload = (_u8*)pFileName;
IanBenzMaxim 0:33d4e66780c0 402 CmdExt.pRxPayload = NULL;
IanBenzMaxim 0:33d4e66780c0 403 Msg.Cmd.Token = Token;
IanBenzMaxim 0:33d4e66780c0 404
IanBenzMaxim 0:33d4e66780c0 405 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsGetInfoCmdCtrl, &Msg, &CmdExt));
IanBenzMaxim 0:33d4e66780c0 406
IanBenzMaxim 0:33d4e66780c0 407 pFsFileInfo->flags = Msg.Rsp.flags;
IanBenzMaxim 0:33d4e66780c0 408 pFsFileInfo->FileLen = Msg.Rsp.FileLen;
IanBenzMaxim 0:33d4e66780c0 409 pFsFileInfo->AllocatedLen = Msg.Rsp.AllocatedLen;
IanBenzMaxim 0:33d4e66780c0 410 pFsFileInfo->Token[0] = Msg.Rsp.Token[0];
IanBenzMaxim 0:33d4e66780c0 411 pFsFileInfo->Token[1] = Msg.Rsp.Token[1];
IanBenzMaxim 0:33d4e66780c0 412 pFsFileInfo->Token[2] = Msg.Rsp.Token[2];
IanBenzMaxim 0:33d4e66780c0 413 pFsFileInfo->Token[3] = Msg.Rsp.Token[3];
IanBenzMaxim 0:33d4e66780c0 414 return (_i16)((_i16)Msg.Rsp.Status);
IanBenzMaxim 0:33d4e66780c0 415 }
IanBenzMaxim 0:33d4e66780c0 416 #endif
IanBenzMaxim 0:33d4e66780c0 417
IanBenzMaxim 0:33d4e66780c0 418 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 419 /* sl_FsDel */
IanBenzMaxim 0:33d4e66780c0 420 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 421 typedef union
IanBenzMaxim 0:33d4e66780c0 422 {
IanBenzMaxim 0:33d4e66780c0 423 _FsDeleteCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 424 _FsDeleteResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 425 }_SlFsDeleteMsg_u;
IanBenzMaxim 0:33d4e66780c0 426
IanBenzMaxim 0:33d4e66780c0 427
IanBenzMaxim 0:33d4e66780c0 428 #if _SL_INCLUDE_FUNC(sl_FsDel)
IanBenzMaxim 0:33d4e66780c0 429
IanBenzMaxim 0:33d4e66780c0 430 static const _SlCmdCtrl_t _SlFsDeleteCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 431 {
IanBenzMaxim 0:33d4e66780c0 432 SL_OPCODE_NVMEM_FILEDELCOMMAND,
IanBenzMaxim 0:33d4e66780c0 433 (_SlArgSize_t)sizeof(_FsDeleteCommand_t),
IanBenzMaxim 0:33d4e66780c0 434 (_SlArgSize_t)sizeof(_FsDeleteResponse_t)
IanBenzMaxim 0:33d4e66780c0 435 };
IanBenzMaxim 0:33d4e66780c0 436
IanBenzMaxim 0:33d4e66780c0 437 _i16 sl_FsDel(const _u8 *pFileName,const _u32 Token)
IanBenzMaxim 0:33d4e66780c0 438 {
IanBenzMaxim 0:33d4e66780c0 439 _SlFsDeleteMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 440 _SlCmdExt_t CmdExt;
IanBenzMaxim 0:33d4e66780c0 441
IanBenzMaxim 0:33d4e66780c0 442 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 443 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 444 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 445 CmdExt.TxPayloadLen = (_u16)((_sl_Strlen(pFileName)+4) & (~3)); /* add 4: 1 for NULL and the 3 for align */
IanBenzMaxim 0:33d4e66780c0 446 CmdExt.RxPayloadLen = 0;
IanBenzMaxim 0:33d4e66780c0 447 CmdExt.pTxPayload = (_u8*)pFileName;
IanBenzMaxim 0:33d4e66780c0 448 CmdExt.pRxPayload = NULL;
IanBenzMaxim 0:33d4e66780c0 449 Msg.Cmd.Token = Token;
IanBenzMaxim 0:33d4e66780c0 450
IanBenzMaxim 0:33d4e66780c0 451
IanBenzMaxim 0:33d4e66780c0 452 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsDeleteCmdCtrl, &Msg, &CmdExt));
IanBenzMaxim 0:33d4e66780c0 453
IanBenzMaxim 0:33d4e66780c0 454 return (_i16)((_i16)Msg.Rsp.status);
IanBenzMaxim 0:33d4e66780c0 455 }
IanBenzMaxim 0:33d4e66780c0 456 #endif