SimpleLink CC32xx OTA Library
Simplifies the implementation of Internet connectivity
OtaLib.h
1 /*
2  * Copyright (c) 2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #ifndef __OTA_LIB_H__
33 #define __OTA_LIB_H__
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /******************************************************************************
40  * OTA states
41 ******************************************************************************/
42 typedef enum
43 {
44  OTA_STATE_IDLE = 0,
45  OTA_STATE_CONNECT_SERVER,
46  OTA_STATE_REQ_OTA_DIR,
47  OTA_STATE_CHECK_ARCHIVE_NEW_UPDATE,
48  OTA_STATE_REQ_FILE_URL,
49  OTA_STATE_CONNECT_FILE_SERVER,
50  OTA_STATE_REQ_FILE_CONTENT,
51  OTA_STATE_PREPARE_DOWNLOAD,
52  OTA_STATE_DOWNLOADING,
53  OTA_STATE_WAIT_CONFIRM,
54  OTA_STATE_NUMBER_OF_STATES
55 } OtaState_e;
56 
57 #define MAX_VENDIR_DIR_SIZE 50
58 
59 typedef struct
60 {
61  OtaState_e State;
62  uint32_t Options;
63 
64  /* Keep OTA parameters */
65  uint8_t VendorDir[MAX_VENDIR_DIR_SIZE];
66  Ota_optServerInfo OtaServerInfo;
67 
68  /* OTA objects */
69  CdnClient_t CdnClient;
70  OtaArchive_t OtaArchive;
71 
72  /* OtaDir and FileUrl info */
73  uint8_t *pOtaFileName;
74  int32_t OtaFileSize;
75  uint8_t FileUrlBuf[MAX_URL_SIZE];
76 
77  /* file content buffer */
78  uint8_t *pRecvChunk;
79  int16_t RecvChunkSize;
80  int16_t RecvChunkOffset;
81  int16_t RecvChunkForceReadMode;
82  int16_t RecvChunkReserved;
83 
84  /* send/recv buffer - must be 4 bytes alignment */
85  uint8_t NetBuf[NET_BUF_SIZE+1];
86 
87  /* Retries */
88  int8_t ConsecutiveOtaErrors;
89 
90 } OtaLib_t;
91 
92 #ifdef __cplusplus
93 }
94 #endif /* __cplusplus */
95 
96 #endif /* __OTA_LIB_H__ */