SimpleLink CC32xx OTA Library
Simplifies the implementation of Internet connectivity
ota.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_H__
33 #define __OTA_H__
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <stdint.h>
40 
41 #define OTA_LIB_VERSION "OTA_LIB_2.0.0.7"
42 
43 /* Configurable numbers */
44 #define MAX_CONSECUTIVE_OTA_ERRORS 5
45 
46 
47 /* !Not Configurable numbers */
48 #define MAX_URL_SIZE 512
49 #define NET_BUF_SIZE 1440
50 
51 /* check in sl_OtaInit if this buffer is enough for OTA lib */
52 #define OTA_BLOCK_SIZE 7800
53 
54 typedef struct
55 {
56  uint8_t Buff[OTA_BLOCK_SIZE];
58 
59 typedef enum
60 {
61  OTA_RUN_NON_BLOCKING/* not supported , OTA_RUN_BLOCKING */
62 } OTA_runningMode;
63 
64 typedef void (*OTA_eventHandler) (void *);
65 
66 #define MAX_SERVER_NAME 64
67 #define MAX_VENDOR_TOKEN_SIZE 96
68 #define VERSION_STR_SIZE 14 /* sizeof "YYYYMMDDHHMMSS" */
69 
70 /******************************************************************************
71  * Server info Structure
72 ******************************************************************************/
73 typedef struct
74 {
75  uint32_t IpAddress; /* 0x0 – no, ip address, use server name */
76  uint32_t SecuredConnection; /* 1 - secured, use port 443 0 - not secured, use port 80 */
77  uint8_t ServerName[MAX_SERVER_NAME];
78  uint8_t VendorToken[MAX_VENDOR_TOKEN_SIZE];
80 
81 typedef struct
82 {
83  uint8_t CurrentVersion[VERSION_STR_SIZE+1];
84  uint8_t NewVersion[VERSION_STR_SIZE+1];
86 
87 /******************************************************************************
88  * Enumerations
89 ******************************************************************************/
90 typedef enum
91 {
92  EXTLIB_OTA_SET_OPT_SERVER_INFO = 0, /* see Ota_optServerInfo */
93  EXTLIB_OTA_SET_OPT_FILE_SERVER_URL,
94  EXTLIB_OTA_SET_OPT_VENDOR_ID,
95  EXTLIB_OTA_SET_OPT_ACCEPT_UPDATE,
96  EXTLIB_OTA_SET_OPT_DECLINE_UPDATE,
97  EXTLIB_OTA_SET_OPT_IMAGE_COMMIT,
98  EXTLIB_OTA_SET_OPT_IMAGE_ROLLBACK,
99  EXTLIB_OTA_GET_OPT_IS_ACTIVE,
100  EXTLIB_OTA_GET_OPT_VERSIONS,
101  EXTLIB_OTA_GET_OPT_IS_PENDING_COMMIT
102 } OTA_option;
103 
104 /******************************************************************************
105  * Macros
106 ******************************************************************************/
107 /* sl_OtaRun error codes */
108 #define OTA_RUN_STATUS_DOWNLOAD_DONE (104L)
109 #define OTA_RUN_STATUS_CHECK_OLDER_VERSION (103L)
110 #define OTA_RUN_STATUS_CHECK_NEWER_VERSION (102L)
111 #define OTA_RUN_STATUS_NO_UPDATES (101L)
112 #define OTA_RUN_STATUS_OK (0L)
113 
114 #define OTA_RUN_STATUS_CONTINUE (+20001L)
115 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_CONNECT_OTA_SERVER (+20002L)
116 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_RECV_APPEND (+20003L)
117 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_REQ_OTA_DIR (+20004L)
118 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_REQ_FILE_URL (+20005L)
119 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_CONNECT_FILE_SERVER (+20006L)
120 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_REQ_FILE_CONTENT (+20007L)
121 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_FILE_HDR (+20008L)
122 #define OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_DOWNLOAD_AND_SAVE (+20009L)
123 
124 #define OTA_RUN_ERROR_NO_SERVER_NO_VENDOR (-21001L)
125 #define OTA_RUN_ERROR_UNEXPECTED_STATE (-21002L)
126 #define OTA_RUN_ERROR_CONSECUTIVE_OTA_ERRORS (-21003L)
127 #define OTA_RUN_ERROR_SECURITY_ALERT (-21004L)
128 
129 /* sl_OtaGet error codes */
130 #define OTA_STATUS_OK (0L)
131 #define OTA_OPT_ERROR_WRONG_STATE (-20601L)
132 #define OTA_OPT_ERROR_COMMIT (-20602L)
133 #define OTA_OPT_ERROR_ROLLBACK (-20603L)
134 #define OTA_OPT_ERROR_OPTION_CODE (-20604L)
135 #define OTA_OPT_ERROR_VENDOR_DIR_SIZE (-20605L)
136 #define OTA_INIT_ERROR (-20701L)
137 
138 /*****************************************************************************
139  * API Prototypes
140  *****************************************************************************/
141 
175 int16_t OTA_init(OTA_runningMode runningMode, OTA_memBlock* pMemBlock, OTA_eventHandler eventHandler);
176 
219 int16_t OTA_run();
220 
260 int16_t OTA_set(OTA_option option, int32_t optionLen, uint8_t *pOptionVal, int32_t flags);
261 
298 int16_t OTA_get(OTA_option option, int32_t *pOptionLen, uint8_t *pOptionVal);
299 
300 #ifdef __cplusplus
301 }
302 #endif /* __cplusplus */
303 
304 #endif /* __OTA_H__ */
int16_t OTA_set(OTA_option option, int32_t optionLen, uint8_t *pOptionVal, int32_t flags)
Set OTA command/parameter.
Definition: OtaLib.c:99
int16_t OTA_get(OTA_option option, int32_t *pOptionLen, uint8_t *pOptionVal)
Get the current OTA status.
Definition: OtaLib.c:176
int16_t OTA_run()
Run the OTA App state machine.
Definition: OtaLib.c:249
int16_t OTA_init(OTA_runningMode runningMode, OTA_memBlock *pMemBlock, OTA_eventHandler eventHandler)
Initialize the OTA application.
Definition: OtaLib.c:45