SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.15
Simplifies the implementation of Internet connectivity
fs.h
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated
3  *
4  * All rights reserved. Property of Texas Instruments Incorporated.
5  * Restricted rights to use, duplicate or disclose this code are
6  * granted through contract.
7  *
8  * The program may not be used without the written permission of
9  * Texas Instruments Incorporated or against the terms and conditions
10  * stipulated in the agreement under which this program has been supplied,
11  * and under no circumstances can it be used with non-TI connectivity device.
12  *
13  */
14 
15 
16 /*****************************************************************************/
17 /* Include files */
18 /*****************************************************************************/
19 #include <ti/drivers/net/wifi/simplelink.h>
20 
21 #ifndef __FS_H__
22 #define __FS_H__
23 
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
43 /*****************************************************************************/
44 /* Macro declarations */
45 /*****************************************************************************/
46 
47 
48 
49 /* Create file max size mode */
50 #define SL_FS_OPEN_MODE_BIT_MASK (0xF8000000)
51 #define SL_NUM_OF_MODE_BIT (5)
52 
53 #define SL_FS_OPEN_FLAGS_BIT_MASK (0x07FE0000)
54 #define SL_NUM_OF_FLAGS_BIT (10)
55 
56 #define SL_FS_OPEN_MAXSIZE_BIT_MASK (0x1FFFF)
57 #define SL_NUM_OF_MAXSIZE_BIT (17)
58 
59 
60 
61 
62 
63 /*****************************************************************************/
64 /* Structure/Enum declarations */
65 /*****************************************************************************/
66 
67 
68 
69 
70 typedef enum
71 {
72  SL_FS_TOKEN_MASTER = 0,
73  SL_FS_TOKEN_WRITE_READ = 1,
74  SL_FS_TOKEN_WRITE_ONLY = 2,
75  SL_FS_TOKEN_READ_ONLY = 3
76 }SlFsTokenId_e;
77 
78 
79 
80 typedef struct
81 {
82  _u16 Flags; /* see Flags options */
83  _u32 Len; /* In bytes, The actual size of the copy which is used for read*/
84  _u32 MaxSize; /* In bytes, The max file size */
85  _u32 Token[4]; /* see SlFsTokenId_e */
86  _u32 StorageSize; /* In bytes, The total size that the file required on the storage including the mirror */
87  _u32 WriteCounter; /* Number of times in which the file have been written successfully */
89 
90 
91 
92 /*
93  sl_FsGetInfo and sl_FsGetFileList flags
94  ------------------
95 */
96 
97 #define SL_FS_INFO_OPEN_WRITE 0x1000 /* File is opened for write */
98 #define SL_FS_INFO_OPEN_READ 0x800 /* File is opened for read */
99 
100 #define SL_FS_INFO_MUST_COMMIT 0x1 /* File is currently open with SL_FS_FILE_OPEN_FLAG_COMMIT_MODE */
101 #define SL_FS_INFO_BUNDLE_FILE 0x2 /* File is currently open with SL_FS_FILE_OPEN_FLAG_BUNDLE_COMMIT_MODE */
102 
103 #define SL_FS_INFO_PENDING_COMMIT 0x4 /* File is currently closed with SL_FS_FILE_OPEN_FLAG_COMMIT_MODE */
104 #define SL_FS_INFO_PENDING_BUNDLE_COMMIT 0x8 /* File is currently closed with SL_FS_FILE_OPEN_FLAG_BUNDLE_COMMIT_MODE */
105 
106 #define SL_FS_INFO_NOT_FAILSAFE 0x20 /* File was created with SL_FS_FILE_OPEN_FLAG_FAILSAFE */
107 #define SL_FS_INFO_NOT_VALID 0x100 /* No valid image exists for the file */
108 #define SL_FS_INFO_SYS_FILE 0x40 /* File is system file */
109 #define SL_FS_INFO_SECURE 0x10 /* File is secured */
110 #define SL_FS_INFO_NOSIGNATURE 0x2000 /* File is unsigned, the flag is returns only for sl_FsGetInfo function and not for sl_FsGetFileList */
111 #define SL_FS_INFO_PUBLIC_WRITE 0x200 /* File is open for public write */
112 #define SL_FS_INFO_PUBLIC_READ 0x400 /* File is open for public read */
113 
114 
115 
116 /*
117  fs_Open flags
118  --------------
119 */
120 
121 /* mode */
122 #define SL_FS_CREATE ((_u32)0x1<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
123 #define SL_FS_WRITE ((_u32)0x2<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
124 #define SL_FS_OVERWRITE ((_u32)0x4<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
125 #define SL_FS_READ ((_u32)0x8<<(SL_NUM_OF_MAXSIZE_BIT+SL_NUM_OF_FLAGS_BIT))
126 /* creation flags */
127 #define SL_FS_CREATE_FAILSAFE ((_u32)0x1<<SL_NUM_OF_MAXSIZE_BIT) /* Fail safe */
128 #define SL_FS_CREATE_SECURE ((_u32)0x2<<SL_NUM_OF_MAXSIZE_BIT) /* SECURE */
129 #define SL_FS_CREATE_NOSIGNATURE ((_u32)0x4<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only */
130 #define SL_FS_CREATE_STATIC_TOKEN ((_u32)0x8<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only */
131 #define SL_FS_CREATE_VENDOR_TOKEN ((_u32)0x10<<SL_NUM_OF_MAXSIZE_BIT) /* Relevant to secure file only */
132 #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 */
133 #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 */
134 
135 #define SL_FS_CREATE_MAX_SIZE( MaxFileSize ) ((((_u32)MaxFileSize + 255) / 256 ) & SL_FS_OPEN_MAXSIZE_BIT_MASK )
136 
137 /* write flags */
138 #define SL_FS_WRITE_MUST_COMMIT ((_u32)0x80<<SL_NUM_OF_MAXSIZE_BIT) /* The file is locked for changes */
139 #define SL_FS_WRITE_BUNDLE_FILE ((_u32)0x100<<SL_NUM_OF_MAXSIZE_BIT) /* The file is locked for changes as part of Bundle */
140 #define SL_FS_WRITE_ENCRYPTED ((_u32)0x200<<SL_NUM_OF_MAXSIZE_BIT) /* This indicates the start of a secured content write session */
141 
142 
143 
144 /*
145  sl_FsCtl
146  --------
147 */
148 typedef enum
149 {
150  SL_FS_CTL_RESTORE = 0, /* restores the factory default */
151  SL_FS_CTL_ROLLBACK = 1,
152  SL_FS_CTL_COMMIT = 2,
153  SL_FS_CTL_RENAME = 3,
154  SL_FS_CTL_GET_STORAGE_INFO = 5,
155  SL_FS_CTL_BUNDLE_ROLLBACK = 6,
156  SL_FS_CTL_BUNDLE_COMMIT = 7
157 }SlFsCtl_e;
158 
159 
160 
161 typedef enum
162 {
163  SL_FS_BUNDLE_STATE_STOPPED = 0,
164  SL_FS_BUNDLE_STATE_STARTED = 1,
165  SL_FS_BUNDLE_STATE_PENDING_COMMIT = 3
166 }SlFsBundleState_e;
167 
168 
169 
170 typedef struct
171 {
172  _u32 Key[4];/*16 bytes*/
173 }SlFsKey_t;
174 
175 
176 
177 typedef struct
178 {
179  _u8 Index;
181 
182 typedef union
183 {
184  SlFsFileNameIndex_t Index;
185  _i32 ErrorNumber;
187 
188 
189 /* File control helper structures */
190 
191 
192 /*SL_FS_CTL_RESTORE*/
193 typedef enum
194 {
195  SL_FS_FACTORY_RET_TO_IMAGE = 0,/*The system will be back to the production image.*/
196  SL_FS_FACTORY_RET_TO_DEFAULT = 2 /*return to factory default*/
197 }SlFsRetToFactoryOper_e;
198 
199 typedef struct
200 {
201  _u32 Operation;/*see _SlFsRetToFactoryOper_e*/
203 
204 
205 
206 
207 
208 
209 
210 /******************* Input flags end *****************************************/
211 
212 typedef struct
213 {
214  _u32 IncludeFilters;
215 
217 
218 
219 
220 typedef struct
221 {
222  _u16 DeviceBlockSize;
223  _u16 DeviceBlocksCapacity;
224  _u16 NumOfAllocatedBlocks;
225  _u16 NumOfReservedBlocks;
226  _u16 NumOfReservedBlocksForSystemfiles;
227  _u16 LargestAllocatedGapInBlocks;
228  _u16 NumOfAvailableBlocksForUserFiles;
229  _u8 Padding[2];
231 
232 typedef struct
233 {
234  _u8 MaxFsFiles;
235  _u8 IsDevlopmentFormatType;
236  _u8 Bundlestate; /*see SlFsBundleState_e*/
237  _u8 Reserved;
238  _u8 MaxFsFilesReservedForSysFiles;
239  _u8 ActualNumOfUserFiles;
240  _u8 ActualNumOfSysFiles;
241  _u8 Padding;
242  _u32 NumOfAlerts;
243  _u32 NumOfAlertsThreshold;
244  _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 */
245  _u16 Padding2;
247 
248 
249 
250 
251 /*SL_FS_CTL_GET_STORAGE_INFO*/
252 typedef struct
253 {
254  SlFsControlDeviceUsage_t DeviceUsage;
255  SlFsControlFilesUsage_t FilesUsage;
257 
258 
259 typedef struct
260 {
261  _u32 IncludeFilters; /* see SlFsControlFilterCounterFlags_e*/
262  _u8 OpenedForWriteCnt;
263  _u8 OpeneForReadCnt;
264  _u8 ClosedFilesCnt;
265  _u8 OpenedForWriteCntWithValidFailSafeImage;
266  _u8 OpeneForReadCntWithValidFailSafeImage;
267  _u8 ClosedFilesCntWithValidFailSafeImage;
268  _u8 padding[2];
270 
271 
272 
273 /* GetFileList */
274 #define SL_FS_MAX_FILE_NAME_LENGTH 180
275 
276 
277 typedef enum
278 {
279  SL_FS_GET_FILE_ATTRIBUTES = 0x1
280 }SlFileListFlags_t;
281 
282 
283 
284 
285 typedef struct
286 {
287  _u32 FileMaxSize;
288  _u32 Properties; /* see SL_FS_INFO_ flags */
289  _u32 FileAllocatedBlocks;/*1 block = 4096 bytes*/
294 /*****************************************************************************/
295 /* external Function prototypes */
296 /*****************************************************************************/
297 
298 /*****************************************************************************/
299 /* Function prototypes */
300 /*****************************************************************************/
373 #if _SL_INCLUDE_FUNC(sl_FsOpen)
374 _i32 sl_FsOpen(const _u8 *pFileName,const _u32 AccessModeAndMaxSize,_u32 *pToken);
375 #endif
376 
410 #if _SL_INCLUDE_FUNC(sl_FsClose)
411 _i16 sl_FsClose(const _i32 FileHdl,const _u8* pCeritificateFileName,const _u8* pSignature,const _u32 SignatureLen);
412 #endif
413 
434 #if _SL_INCLUDE_FUNC(sl_FsRead)
435 _i32 sl_FsRead(const _i32 FileHdl,_u32 Offset ,_u8* pData,_u32 Len);
436 #endif
437 
458 #if _SL_INCLUDE_FUNC(sl_FsWrite)
459 _i32 sl_FsWrite(const _i32 FileHdl,_u32 Offset,_u8* pData,_u32 Len);
460 #endif
461 
488 #if _SL_INCLUDE_FUNC(sl_FsGetInfo)
489 _i16 sl_FsGetInfo(const _u8 *pFileName,const _u32 Token,SlFsFileInfo_t* pFsFileInfo);
490 #endif
491 
509 #if _SL_INCLUDE_FUNC(sl_FsDel)
510 _i16 sl_FsDel(const _u8 *pFileName,const _u32 Token);
511 #endif
512 
513 
514 
632 #if _SL_INCLUDE_FUNC(sl_FsCtl)
633 _i32 sl_FsCtl( SlFsCtl_e Command, _u32 Token, _u8 *pFileName, const _u8 *pData, _u16 DataLen, _u8 *pOutputData, _u16 OutputDataLen,_u32 *pNewToken );
634 #endif
635 
768 #if _SL_INCLUDE_FUNC(sl_FsProgram)
769 _i32 sl_FsProgram(const _u8* pData , _u16 Len , const _u8 * pKey , _u32 Flags );
770 #endif
771 
855 #if _SL_INCLUDE_FUNC(sl_FsGetFileList)
856 _i32 sl_FsGetFileList(_i32* pIndex, _u8 Count, _u8 MaxEntryLen , _u8* pBuff, SlFileListFlags_t Flags );
857 #endif
858 
859 
860 
861 
869 #ifdef __cplusplus
870 }
871 #endif /* __cplusplus */
872 
873 #endif /* __FS_H__ */
874 
_i32 sl_FsOpen(const _u8 *pFileName, const _u32 AccessModeAndMaxSize, _u32 *pToken)
open file for read or write from/to storage device
Definition: fs.c:149
_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:597
_i16 sl_FsGetInfo(const _u8 *pFileName, const _u32 Token, SlFsFileInfo_t *pFsFileInfo)
Get information of a file.
Definition: fs.c:482
_i16 sl_FsClose(const _i32 FileHdl, const _u8 *pCeritificateFileName, const _u8 *pSignature, const _u32 SignatureLen)
Close file in storage device.
Definition: fs.c:247
_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:709
_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:549
_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:814
_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:304
Definition: fs.h:170