SimpleLink CC31xx/CC32xx Host Driver  Version 3.0.1.55
Simplifies the implementation of Internet connectivity
fs.h
1 /*
2  * fs.h - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
5  *
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35 */
36 
37 
38 
39 /*****************************************************************************/
40 /* Include files */
41 /*****************************************************************************/
42 #include <ti/drivers/net/wifi/simplelink.h>
43 
44 #ifndef __FS_H__
45 #define __FS_H__
46 
47 
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
66 /*****************************************************************************/
67 /* Macro declarations */
68 /*****************************************************************************/
69 
70 /* Create file max size mode */
71 #define SL_FS_OPEN_MODE_BIT_MASK (0xF8000000)
72 #define SL_NUM_OF_MODE_BIT (5)
73 
74 #define SL_FS_OPEN_FLAGS_BIT_MASK (0x07FE0000)
75 #define SL_NUM_OF_FLAGS_BIT (10)
76 
77 #define SL_FS_OPEN_MAXSIZE_BIT_MASK (0x1FFFF)
78 #define SL_NUM_OF_MAXSIZE_BIT (17)
79 
80 
81 /*
82  sl_FsGetInfo and sl_FsGetFileList flags
83  ------------------
84 */
85 
86 #define SL_FS_INFO_OPEN_WRITE 0x1000 /* File is opened for write */
87 #define SL_FS_INFO_OPEN_READ 0x800 /* File is opened for read */
88 
89 #define SL_FS_INFO_MUST_COMMIT 0x1 /* File is currently open with SL_FS_WRITE_MUST_COMMIT */
90 #define SL_FS_INFO_BUNDLE_FILE 0x2 /* File is currently open with SL_FS_WRITE_BUNDLE_FILE */
91 
92 #define SL_FS_INFO_PENDING_COMMIT 0x4 /* File that was open with SL_FS_WRITE_MUST_COMMIT is closed */
93 #define SL_FS_INFO_PENDING_BUNDLE_COMMIT 0x8 /* File that was open with SL_FS_WRITE_BUNDLE_FILE is closed */
94 
95 #define SL_FS_INFO_NOT_FAILSAFE 0x20 /* File was not created with SL_FS_CREATE_FAILSAFE */
96 #define SL_FS_INFO_NOT_VALID 0x100 /* No valid image exists for the file */
97 #define SL_FS_INFO_SYS_FILE 0x40 /* File is system file */
98 #define SL_FS_INFO_SECURE 0x10 /* File is secured */
99 #define SL_FS_INFO_NOSIGNATURE 0x2000 /* File is unsigned, the flag is returns only for sl_FsGetInfo function and not for sl_FsGetFileList */
100 #define SL_FS_INFO_PUBLIC_WRITE 0x200 /* File is open for public write */
101 #define SL_FS_INFO_PUBLIC_READ 0x400 /* File is open for public read */
102 
103 
104 /*
105  fs_Open flags
106  --------------
107 */
108 
109 /* mode */
110 #define SL_FS_CREATE ((_u32)0x1<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
111 #define SL_FS_WRITE ((_u32)0x2<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
112 #define SL_FS_OVERWRITE ((_u32)0x4<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
113 #define SL_FS_READ ((_u32)0x8<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
114 /* creation flags */
115 #define SL_FS_CREATE_FAILSAFE ((_u32)0x1<<SL_NUM_OF_MAXSIZE_BIT) /* Fail safe */
116 #define SL_FS_CREATE_SECURE ((_u32)0x2<<SL_NUM_OF_MAXSIZE_BIT) /* SECURE */
117 #define SL_FS_CREATE_NOSIGNATURE ((_u32)0x4<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only */
118 #define SL_FS_CREATE_STATIC_TOKEN ((_u32)0x8<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only */
119 #define SL_FS_CREATE_VENDOR_TOKEN ((_u32)0x10<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only */
120 #define SL_FS_CREATE_PUBLIC_WRITE ((_u32)0x20<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only, the file can be opened for write without Token */
121 #define SL_FS_CREATE_PUBLIC_READ ((_u32)0x40<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only, the file can be opened for read without Token */
122 
123 #define SL_FS_CREATE_MAX_SIZE( MaxFileSize ) ((((_u32)MaxFileSize + 255) / 256 ) & SL_FS_OPEN_MAXSIZE_BIT_MASK )
124 
125 /* open for write flags */
126 #define SL_FS_WRITE_MUST_COMMIT ((_u32)0x80<<SL_NUM_OF_MAXSIZE_BIT) /* The file is locked for changes */
127 #define SL_FS_WRITE_BUNDLE_FILE ((_u32)0x100<<SL_NUM_OF_MAXSIZE_BIT) /* The file is locked for changes as part of Bundle */
128 #define SL_FS_WRITE_ENCRYPTED ((_u32)0x200<<SL_NUM_OF_MAXSIZE_BIT) /* This indicates the start of a secured content write session */
129 
130 /*****************************************************************************/
131 /* Structure/Enum declarations */
132 /*****************************************************************************/
133 
134 typedef enum
135 {
136  SL_FS_TOKEN_MASTER = 0,
137  SL_FS_TOKEN_WRITE_READ = 1,
138  SL_FS_TOKEN_WRITE_ONLY = 2,
139  SL_FS_TOKEN_READ_ONLY = 3
140 }SlFsTokenId_e;
141 
142 typedef struct
143 {
144  _u16 Flags; /* see Flags options */
145  _u32 Len; /* In bytes, The actual size of the copy which is used for read*/
146  _u32 MaxSize; /* In bytes, The max file size */
147  _u32 Token[4]; /* see SlFsTokenId_e */
148  _u32 StorageSize; /* In bytes, The total size that the file required on the storage including the mirror */
149  _u32 WriteCounter; /* Number of times in which the file have been written successfully */
151 
152 
153 /*
154  sl_FsCtl
155  --------
156 */
157 typedef enum
158 {
159  SL_FS_CTL_RESTORE = 0, /* restores the factory default */
160  SL_FS_CTL_ROLLBACK = 1,
161  SL_FS_CTL_COMMIT = 2,
162  SL_FS_CTL_RENAME = 3,
163  SL_FS_CTL_GET_STORAGE_INFO = 5,
164  SL_FS_CTL_BUNDLE_ROLLBACK = 6,
165  SL_FS_CTL_BUNDLE_COMMIT = 7
166 }SlFsCtl_e;
167 
168 typedef enum
169 {
170  SL_FS_BUNDLE_STATE_STOPPED = 0,
171  SL_FS_BUNDLE_STATE_STARTED = 1,
172  SL_FS_BUNDLE_STATE_PENDING_COMMIT = 3
173 }SlFsBundleState_e;
174 
175 typedef struct
176 {
177  _u32 Key[4];/*16 bytes*/
178 }SlFsKey_t;
179 
180 typedef struct
181 {
182  _u8 Index;
184 
185 typedef union
186 {
187  SlFsFileNameIndex_t Index;
188  _i32 ErrorNumber;
190 
191 /* File control helper structures */
192 
193 /*SL_FS_CTL_RESTORE*/
194 typedef enum
195 {
196  SL_FS_FACTORY_RET_TO_IMAGE = 0,/*The system will be back to the production image.*/
197  SL_FS_FACTORY_RET_TO_DEFAULT = 2 /*return to factory default*/
198 }SlFsRetToFactoryOper_e;
199 
200 typedef struct
201 {
202  _u32 Operation;/*see _SlFsRetToFactoryOper_e*/
204 
205 /******************* Input flags end *****************************************/
206 
207 typedef struct
208 {
209  _u32 IncludeFilters;
210 
212 
213 typedef struct
214 {
215  _u16 DeviceBlockSize;
216  _u16 DeviceBlocksCapacity;
217  _u16 NumOfAllocatedBlocks;
218  _u16 NumOfReservedBlocks;
219  _u16 NumOfReservedBlocksForSystemfiles;
220  _u16 LargestAllocatedGapInBlocks;
221  _u16 NumOfAvailableBlocksForUserFiles;
222  _u8 Padding[2];
224 
225 typedef struct
226 {
227  _u8 MaxFsFiles;
228  _u8 IsDevlopmentFormatType;
229  _u8 Bundlestate; /*see SlFsBundleState_e*/
230  _u8 Reserved;
231  _u8 MaxFsFilesReservedForSysFiles;
232  _u8 ActualNumOfUserFiles;
233  _u8 ActualNumOfSysFiles;
234  _u8 Padding;
235  _u32 NumOfAlerts;
236  _u32 NumOfAlertsThreshold;
237  _u16 FATWriteCounter;/*Though it is increased during the programming, the programming and ret to factory takes only 1- write to the FAT, independ of the number of the programming files */
238  _u16 Padding2;
240 
241 /*SL_FS_CTL_GET_STORAGE_INFO*/
242 typedef struct
243 {
244  SlFsControlDeviceUsage_t DeviceUsage;
245  SlFsControlFilesUsage_t FilesUsage;
247 
248 typedef struct
249 {
250  _u32 IncludeFilters; /* see SlFsControlFilterCounterFlags_e*/
251  _u8 OpenedForWriteCnt;
252  _u8 OpeneForReadCnt;
253  _u8 ClosedFilesCnt;
254  _u8 OpenedForWriteCntWithValidFailSafeImage;
255  _u8 OpeneForReadCntWithValidFailSafeImage;
256  _u8 ClosedFilesCntWithValidFailSafeImage;
257  _u8 padding[2];
259 
260 /* GetFileList */
261 #define SL_FS_MAX_FILE_NAME_LENGTH 180
262 
263 typedef enum
264 {
265  SL_FS_GET_FILE_ATTRIBUTES = 0x1
266 }SlFileListFlags_t;
267 
268 
269 
270 
271 typedef struct
272 {
273  _u32 FileMaxSize;
274  _u32 Properties; /* see SL_FS_INFO_ flags */
275  _u32 FileAllocatedBlocks;/*1 block = 4096 bytes*/
280 /*****************************************************************************/
281 /* external Function prototypes */
282 /*****************************************************************************/
283 
284 /*****************************************************************************/
285 /* Function prototypes */
286 /*****************************************************************************/
358 #if _SL_INCLUDE_FUNC(sl_FsOpen)
359 _i32 sl_FsOpen(const _u8 *pFileName,const _u32 AccessModeAndMaxSize,_u32 *pToken);
360 #endif
361 
393 #if _SL_INCLUDE_FUNC(sl_FsClose)
394 _i16 sl_FsClose(const _i32 FileHdl,const _u8* pCeritificateFileName,const _u8* pSignature,const _u32 SignatureLen);
395 #endif
396 
417 #if _SL_INCLUDE_FUNC(sl_FsRead)
418 _i32 sl_FsRead(const _i32 FileHdl,_u32 Offset ,_u8* pData,_u32 Len);
419 #endif
420 
441 #if _SL_INCLUDE_FUNC(sl_FsWrite)
442 _i32 sl_FsWrite(const _i32 FileHdl,_u32 Offset,_u8* pData,_u32 Len);
443 #endif
444 
471 #if _SL_INCLUDE_FUNC(sl_FsGetInfo)
472 _i16 sl_FsGetInfo(const _u8 *pFileName,const _u32 Token,SlFsFileInfo_t* pFsFileInfo);
473 #endif
474 
492 #if _SL_INCLUDE_FUNC(sl_FsDel)
493 _i16 sl_FsDel(const _u8 *pFileName,const _u32 Token);
494 #endif
495 
496 
497 
614 #if _SL_INCLUDE_FUNC(sl_FsCtl)
615 _i32 sl_FsCtl( SlFsCtl_e Command, _u32 Token, _u8 *pFileName, const _u8 *pData, _u16 DataLen, _u8 *pOutputData, _u16 OutputDataLen,_u32 *pNewToken );
616 #endif
617 
747 #if _SL_INCLUDE_FUNC(sl_FsProgram)
748 _i32 sl_FsProgram(const _u8* pData , _u16 Len , const _u8 * pKey , _u32 Flags );
749 #endif
750 
834 #if _SL_INCLUDE_FUNC(sl_FsGetFileList)
835 _i32 sl_FsGetFileList(_i32* pIndex, _u8 Count, _u8 MaxEntryLen , _u8* pBuff, SlFileListFlags_t Flags );
836 #endif
837 
845 #ifdef __cplusplus
846 }
847 #endif /* __cplusplus */
848 
849 #endif /* __FS_H__ */
850 
_i32 sl_FsOpen(const _u8 *pFileName, const _u32 AccessModeAndMaxSize, _u32 *pToken)
open file for read or write from/to storage device
Definition: fs.c:157
_i32 sl_FsCtl(SlFsCtl_e Command, _u32 Token, _u8 *pFileName, const _u8 *pData, _u16 DataLen, _u8 *pOutputData, _u16 OutputDataLen, _u32 *pNewToken)
Controls various file system operations.
Definition: fs.c:585
_i16 sl_FsGetInfo(const _u8 *pFileName, const _u32 Token, SlFsFileInfo_t *pFsFileInfo)
Get information of a file.
Definition: fs.c:475
_i16 sl_FsClose(const _i32 FileHdl, const _u8 *pCeritificateFileName, const _u8 *pSignature, const _u32 SignatureLen)
Close file in storage device.
Definition: fs.c:250
_i32 sl_FsProgram(const _u8 *pData, _u16 Len, const _u8 *pKey, _u32 Flags)
Enables to format and configure the device with pre-prepared configuration.
Definition: fs.c:689
_i16 sl_FsDel(const _u8 *pFileName, const _u32 Token)
Delete specific file from a storage or all files from a storage (format)
Definition: fs.c:541
_i32 sl_FsGetFileList(_i32 *pIndex, _u8 Count, _u8 MaxEntryLen, _u8 *pBuff, SlFileListFlags_t Flags)
The list of file names, the files are retrieve in chunks.
Definition: fs.c:791
_i32 sl_FsWrite(const _i32 FileHdl, _u32 Offset, _u8 *pData, _u32 Len)
Write block of data to a file in storage device.
Definition: fs.c:379
_i32 sl_FsRead(const _i32 FileHdl, _u32 Offset, _u8 *pData, _u32 Len)
Read block of data from a file in storage device.
Definition: fs.c:305
Definition: fs.h:175