SimpleLink CC32xx OTA Library
Simplifies the implementation of Internet connectivity
OTA

Functions

int16_t OTA_init (OTA_runningMode runningMode, OTA_memBlock *pMemBlock, OTA_eventHandler eventHandler)
 Initialize the OTA application. More...
 
int16_t OTA_run ()
 Run the OTA App state machine. More...
 
int16_t OTA_set (OTA_option option, int32_t optionLen, uint8_t *pOptionVal, int32_t flags)
 Set OTA command/parameter. More...
 
int16_t OTA_get (OTA_option option, int32_t *pOptionLen, uint8_t *pOptionVal)
 Get the current OTA status. More...
 

Variables

uint8_t Buff [OTA_BLOCK_SIZE]
 
uint32_t IpAddress
 
uint32_t SecuredConnection
 
uint8_t ServerName [MAX_SERVER_NAME]
 
uint8_t VendorToken [MAX_VENDOR_TOKEN_SIZE]
 
uint8_t CurrentVersion [VERSION_STR_SIZE+1]
 
uint8_t NewVersion [VERSION_STR_SIZE+1]
 

Detailed Description

Function Documentation

§ OTA_get()

int16_t OTA_get ( OTA_option  option,
int32_t *  pOptionLen,
uint8_t *  pOptionVal 
)

Get the current OTA status.

Parameters
[in]pOtaLibOTA control block pointer
[in]OptionSelects the option
[in]OptionLenoption structure length
[in]pOptionValpointer to the option structure

This function gets the current OTA of active or Idle. The parameter option, could be one of the following:

EXTLIB_OTA_GET_OPT_IS_ACTIVE - Check if OTA process is active or idle
EXTLIB_OTA_GET_OPT_VERSIONS - return the current OTA version and the new update version for the user to compare
EXTLIB_OTA_GET_OPT_IS_PENDING_COMMIT - Check if the new image is in the state BUNDLE_STATE_WAITING_FOR_COMMIT
Value at pOptionVal will be set to 1 if OTA process is active, 0 if Idle

Returns
Return 0 on success, -1 otherwise.
See also
Note
Warning
Example:
For example: check if pending commit
int32_t isPendingCommit;
int32_t isPendingCommit_len;
int32_t Status;
Status = Ota_get(EXTLIB_OTA_GET_OPT_IS_PENDING_COMMIT, &isPendingCommit_len, (uint8_t *)&isPendingCommit);

Definition at line 183 of file OtaLib.c.

184 {
185  Ota_optVersionsInfo *pVersionsInfo;
186  int16_t Status = OTA_STATUS_OK;
187 
188  switch (option)
189  {
190  case EXTLIB_OTA_GET_OPT_IS_ACTIVE:
191  *(int32_t *)pOptionVal = (pOtaLib->State != OTA_STATE_IDLE);
192  *pOptionLen = sizeof(int32_t);
193  break;
194 
195  case EXTLIB_OTA_GET_OPT_VERSIONS:
196 
197  pVersionsInfo = (Ota_optVersionsInfo *)pOptionVal;
198  /* get the current version from ota.dat file */
199  OtaArchive_getCurrentVersion(pVersionsInfo->CurrentVersion);
200  /* extract the new version from OtaFileName if exists */
201  if(pOtaLib->pOtaFileName == NULL)
202  {
203  /* can be if the OTA not in the right state and still didn't read the file name */
204  /* OTA file not exists (no upadte or state before reading the ota new update */
205  memset(pVersionsInfo->NewVersion, '0', VERSION_STR_SIZE);
206  }
207  else
208  {
209  uint8_t *pVersionFileName = _ExtractFileVersion(pOtaLib->pOtaFileName, MAX_CDN_FILE_NAME_SIZE);
210  /* extract version from file */
211  memcpy(pVersionsInfo->NewVersion, pVersionFileName, VERSION_STR_SIZE);
212  }
213  pVersionsInfo->NewVersion[VERSION_STR_SIZE] = 0; /* null terminated string */
214  break;
215 
216  case EXTLIB_OTA_GET_OPT_IS_PENDING_COMMIT:
217 
218  *(int32_t *)pOptionVal = OtaArchive_getPendingCommit();
219  break;
220 
221  default:
222  _SlOtaLibTrace(("OTA_get: option %ld is not implemented\r\n", option));
223  Status = OTA_OPT_ERROR_OPTION_CODE;
224  }
225 
226  return Status;
227 }

§ OTA_init()

int16_t OTA_init ( OTA_runningMode  runningMode,
OTA_memBlock pMemBlock,
OTA_eventHandler  eventHandler 
)

Initialize the OTA application.

Parameters
[in]runningModeSupported only OTA_RUN_NON_BLOCKING
[in]pMemBlockIs the OTA library control block allocated by the application
[in]eventHandlerCallback to the app, currently not supported, need to be NULL

This function initializes the OTA application and modules. The size of the control block parameter should be enough for OTA init (currently 7800 bytes) otherwize the init will failed

Returns
Return zero ot -ve otherwise.

-OTA_INIT_ERROR - when the size of the OTA control block OtaCB_t is not enough for the OTA lib

See also
Warning
Example:
For example: To initialize OTA from host invoke
OTA_memBlock otaMemBlock;
int16_t Status;
Status = OTA_init(OTA_RUN_NON_BLOCKING, &otaMemBlock, NULL);

Definition at line 45 of file OtaLib.c.

46 {
47  _SlOtaLibTrace(("OTA_init: sizeof CdnClient=%d, sizeof OtaArchive=%d\r\n", sizeof(pOtaLib->CdnClient), sizeof(pOtaLib->OtaArchive)));
48  _SlOtaLibTrace(("OTA_init: sizeof OtaLib_t=%d, sizeof OTA_memBlock=%d\r\n", sizeof(OtaLib_t), sizeof(OTA_memBlock)));
49  if (sizeof(OtaLib_t) > sizeof(OTA_memBlock))
50  {
51  _SlOtaLibTrace(("OTA_init: ERROR buffer size OtaLib_t=%d < OTA_memBlock=%d\r\n", sizeof(OtaLib_t), sizeof(OTA_memBlock)));
52  return OTA_INIT_ERROR;
53  }
54  pOtaLib = (OtaLib_t *)pMemBlock;
55 
56  memset(pOtaLib, 0, sizeof(OtaLib_t));
57  pOtaLib->State = OTA_STATE_IDLE;
58 
59  _SlOtaLibTrace(("OTA_init: OTA lib version = %s\r\n", OTA_LIB_VERSION));
60 
61  CdnClient_Init(&pOtaLib->CdnClient, pOtaLib->NetBuf);
62  OtaArchive_init(&pOtaLib->OtaArchive);
63 
64  /* init statistics */
65  return OTA_STATUS_OK;
66 }

§ OTA_run()

int16_t OTA_run ( )

Run the OTA App state machine.

Parameters
[in]pOtaLibPointer to OTA application pointer

Run one step from the OTA application state machine. Host should repeat calling this function and examine the return value in order to check if OTA completed or got error or just need to be continued. This pattern is useful in host with NON-OS. In host with OS, host should start OTA task and continuously calling this function till OTA completed.

Returns
Return zero or +ve bitmap number on success, -ve otherwise.

-OTA_RUN_STATUS_CONTINUE - Host should continue calling sl_OtaRun
-OTA_RUN_STATUS_CONTINUE_WARNING_... - group of OTA WARNINGS, actually those are errors but the OTA will retry the process 5 times so user should continue run the OTA
-OTA_RUN_STATUS_NO_UPDATES - No updates for now, host can retry after another period of time
-OTA_RUN_STATUS_CHECK_NEWER_VERSION - OTA found newer update version, user can accept the new version by calling sl_OtaSet with option _ ACCEPT_UPDATE , or just continue running, or do another check before continue
-OTA_RUN_STATUS_CHECK_OLDER_VERSION - OTA found older update version, user can stop the OTA by calling sl_OtaSet with option _DECLINE_UPDATE , or continue running, or do another check before continue
-OTA_RUN_STATUS_DOWNLOAD_DONE - Current OTA update completed, host should move the image to BUNDLE_STATE_TESTING by calling sl_Stop and then ro reset the MCU
-OTA_RUN_ERROR_... - group of OTA ERRORS, user should stop the OTA process -OTA_RUN_ERROR_CONSECUTIVE_OTA_ERRORS - OTA process failed 5 consecutive times -OTA_RUN_ERROR_NO_SERVER_NO_VENDOR - user didn't call sl_OtaSet with EXTLIB_OTA_OPT_VENDOR_ID and EXTLIB_OTA_OPT_SERVER_INFO before running the OTA -OTA_RUN_ERROR_SECURITY_ALERT - security alert from file system, user must stop trying downloading current OTA update -OTA_RUN_ERROR_UNEXPECTED_STATE - OTA state error, must init the OTA before continue

See also
Note
Warning
Example:
For example: Run OTA from host
Status = Ota_run();

Definition at line 256 of file OtaLib.c.

257 {
258  CdnClient_t *pCdnClient = (CdnClient_t *)&pOtaLib->CdnClient;
259  int16_t Status;
260  int16_t ProcessedBytes;
261 
262  switch (pOtaLib->State)
263  {
264  case OTA_STATE_IDLE:
265 #if OTA_SERVER_TYPE == OTA_FILE_DOWNLOAD
266  /* File Server URL must be initialized before running OTA */
267  if(pOtaLib->FileUrlBuf[0] == 0)
268  {
269  return OTA_RUN_ERROR_NO_SERVER_NO_VENDOR;
270  }
271  pOtaLib->State = OTA_STATE_CONNECT_FILE_SERVER;
272 #else
273  /* serverInfo and vendorDir must be init before running OTA */
274  if /*(*/(pOtaLib->OtaServerInfo.ServerName[0] == 0) /*|| (pOtaLib->VendorDir[0] == 0))*/
275  {
276  return OTA_RUN_ERROR_NO_SERVER_NO_VENDOR;
277  }
278 
279  pOtaLib->State = OTA_STATE_CONNECT_SERVER;
280 #endif
281  break;
282 #if OTA_SERVER_TYPE != OTA_FILE_DOWNLOAD
283  case OTA_STATE_CONNECT_SERVER:
284  _SlOtaLibTrace(("OTA_run: call CdnClient_ConnectServer OTA server=%s\r\n", pOtaLib->OtaServerInfo.ServerName));
285  Status = CdnClient_ConnectServer(pCdnClient, &pOtaLib->OtaServerInfo);
286  if( Status < 0)
287  {
288  _SlOtaLibTrace(("OTA_run: ERROR CdnClient_ConnectServer, Status=%ld\r\n", Status));
289  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_CONNECT_FILE_SERVER, BACK_TO_IDLE);
290  return Status;
291  }
292  pOtaLib->State = OTA_STATE_REQ_OTA_DIR;
293  break;
294 
295  case OTA_STATE_REQ_OTA_DIR:
296  {
297  int32_t NumDirFiles;
298  _SlOtaLibTrace(("OTA_run: CdnClient_ReqOtaDir, VendorDir=%s\r\n", pOtaLib->VendorDir));
299  NumDirFiles = CdnClient_ReqOtaDir(pCdnClient, pOtaLib->VendorDir);
300  if (NumDirFiles < 0)
301  {
302  _SlOtaLibTrace(("OTA_run: ERROR CdnClient_ReqOtaDir, Status=%d\r\n", NumDirFiles));
303  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_REQ_OTA_DIR, BACK_TO_IDLE);
304  return Status;
305  }
306  if (NumDirFiles == 0)
307  {
308  _SlOtaLibTrace(("OTA_run: ERROR CdnClient_ReqOtaDir - no updates\r\n"));
309  pOtaLib->ConsecutiveOtaErrors = 0;
310  pOtaLib->State = OTA_STATE_IDLE;
311  _OtaCleanToIdle(pOtaLib);
312  return OTA_RUN_STATUS_NO_UPDATES;
313  }
314  _SlOtaLibTrace(("OTA_run: CdnClient_ReqOtaDir, NumDirFiles=%ld\r\n", NumDirFiles));
315  pOtaLib->State = OTA_STATE_CHECK_ARCHIVE_NEW_UPDATE;
316  }
317  break;
318 
319  case OTA_STATE_CHECK_ARCHIVE_NEW_UPDATE:
320  {
321  uint8_t *pVersionFileName;
322  _SlOtaLibTrace(("OTA_run: CdnClient_GetNextDirFile\r\n"));
323  pOtaLib->pOtaFileName = CdnClient_GetNextDirFile(pCdnClient, &pOtaLib->OtaFileSize);
324 
325  /* check if last file in the list, still without tar file */
326  if( pOtaLib->pOtaFileName == NULL)
327  {
328  /* tar file not found, return no updates */
329  _SlOtaLibTrace(("OTA_run: ERROR CdnClient_ReqOtaDir - tar not found, no updates\r\n"));
330  pOtaLib->ConsecutiveOtaErrors = 0;
331  pOtaLib->State = OTA_STATE_IDLE;
332  _OtaCleanToIdle(pOtaLib);
333  return OTA_RUN_STATUS_NO_UPDATES;
334  }
335 
336  _SlOtaLibTrace(("OTA_run: CdnClient_GetNextDirFile: file=%s, size=%ld\r\n", pOtaLib->pOtaFileName, pOtaLib->OtaFileSize));
337 
338  if (strstr((const char *)pOtaLib->pOtaFileName, ".tar") == NULL)
339  {
340  _SlOtaLibTrace(("OTA_run: WARNING, not a tar file, filename=%s\r\n", pOtaLib->pOtaFileName));
341  /* Stay on state, check next file version */
342  pOtaLib->State = OTA_STATE_CHECK_ARCHIVE_NEW_UPDATE;
343  return OTA_RUN_STATUS_CONTINUE;
344  }
345 
346  /* Init the Tar parser module */
347  OtaArchive_init(&pOtaLib->OtaArchive);
348 
349  /* host should check the version */
350  pVersionFileName = _ExtractFileVersion(pOtaLib->pOtaFileName, MAX_CDN_FILE_NAME_SIZE);
351  if (OtaArchive_checkVersion(&pOtaLib->OtaArchive, pVersionFileName))
352  {
353  return OTA_RUN_STATUS_CHECK_NEWER_VERSION;
354  }
355  else
356  {
357  return OTA_RUN_STATUS_CHECK_OLDER_VERSION;
358  }
359  }
360 
361  case OTA_STATE_REQ_FILE_URL:
362 
363  _SlOtaLibTrace(("OTA_run: Call CdnClient_ReqFileUrl, filename = %s\r\n", pOtaLib->pOtaFileName));
364  Status = CdnClient_ReqFileUrl(pCdnClient, pOtaLib->pOtaFileName, pOtaLib->FileUrlBuf, sizeof(pOtaLib->FileUrlBuf));
365  if( Status < 0)
366  {
367  _SlOtaLibTrace(("OTA_run: ERROR CdnClient_ReqFileUrl, Status=%d\r\n", Status));
368  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_REQ_FILE_URL, BACK_TO_IDLE);
369  return Status;
370  }
371 
372  /* In this stage the CDN server can be closed */
373  CdnClient_CloseServer(&pOtaLib->CdnClient);
374 
375  pOtaLib->State = OTA_STATE_CONNECT_FILE_SERVER;
376  break;
377 #endif
378  case OTA_STATE_CONNECT_FILE_SERVER:
379 
380  _SlOtaLibTrace(("OTA_run: Call CdnClient_ConnectFileServer, url = %s\r\n", pOtaLib->FileUrlBuf));
381  Status = CdnClient_ConnectFileServer(&pOtaLib->CdnClient, pOtaLib->FileUrlBuf, pOtaLib->OtaServerInfo.SecuredConnection);
382  if( Status < 0)
383  {
384  /* stay on this state for another retry */
385  _SlOtaLibTrace(("OTA_run: ERROR CdnClient_ConnectFileServer, Status=%d\r\n", Status));
386  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_CONNECT_FILE_SERVER, BACK_TO_IDLE);
387  return Status;
388  }
389  pOtaLib->State = OTA_STATE_REQ_FILE_CONTENT;
390  break;
391 
392  case OTA_STATE_REQ_FILE_CONTENT:
393 
394  _SlOtaLibTrace(("OTA_run: Call CdnClient_ReqFileContent, url = %s\r\n", pOtaLib->FileUrlBuf));
395  Status = CdnClient_ReqFileContent(&pOtaLib->CdnClient, pOtaLib->FileUrlBuf);
396  if( Status < 0)
397  {
398  _SlOtaLibTrace(("OTA_run: ERROR CdnClient_ReqFileContent, Status=%d\r\n", Status));
399  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_REQ_FILE_CONTENT, BACK_TO_IDLE);
400  return Status;
401  }
402 
403  pOtaLib->State = OTA_STATE_PREPARE_DOWNLOAD;
404  break;
405 
406  case OTA_STATE_PREPARE_DOWNLOAD:
407 
408  /* prepare receive buffer */
409  pOtaLib->pRecvChunk = pOtaLib->NetBuf;
410  pOtaLib->RecvChunkOffset = 0;
411  pOtaLib->RecvChunkForceReadMode = 0;
412 
413  pOtaLib->RecvChunkSize = CdnClient_RecvSkipHdr(pCdnClient->FileSockId, pOtaLib->pRecvChunk, NET_BUF_SIZE);
414  if (0 >= pOtaLib->RecvChunkSize)
415  {
416  _SlOtaLibTrace(("OTA_run: ERROR downloading, CdnClient_RecvSkipHdr Status=%ld\r\n", pOtaLib->RecvChunkSize));
417  /* Stop the parsing of the archive file */
418  OtaArchive_abort(&pOtaLib->OtaArchive);
419  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_FILE_HDR, BACK_TO_IDLE);
420  return Status;
421  }
422 
423  pOtaLib->State = OTA_STATE_DOWNLOADING;
424  break;
425 
426  case OTA_STATE_DOWNLOADING:
427 
428  /* Check if to read more chunk */
429  if ((pOtaLib->RecvChunkOffset != 0) || (pOtaLib->RecvChunkSize == 0) || pOtaLib->RecvChunkForceReadMode)
430  {
431  int16_t UnprocessedSize = pOtaLib->RecvChunkSize-pOtaLib->RecvChunkOffset;
432  int16_t Len;
433 
434  if (UnprocessedSize >= TAR_HDR_SIZE)
435  {
436  /* No need to read more, enough unprocessed bytes to decode next TAR file header */
437  memcpy(&pOtaLib->pRecvChunk[0], &pOtaLib->pRecvChunk[pOtaLib->RecvChunkOffset], UnprocessedSize);
438  Len = UnprocessedSize;
439  }
440  else
441  {
442  Len = CdnClient_RecvAppend(pCdnClient->FileSockId, pOtaLib->pRecvChunk, NET_BUF_SIZE, pOtaLib->RecvChunkSize, pOtaLib->RecvChunkOffset);
443  }
444  if (0 >= Len)
445  {
446  _SlOtaLibTrace(("OTA_run: ERROR downloading, CdnClient_RecvAppend Status=%ld\r\n", Len));
447  /* Stop the parsing of the archive file */
448  OtaArchive_abort(&pOtaLib->OtaArchive);
449  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_RECV_APPEND, BACK_TO_IDLE);
450  return Status;
451  }
452  pOtaLib->RecvChunkOffset = 0;
453  pOtaLib->RecvChunkSize = Len;
454  pOtaLib->RecvChunkForceReadMode = 0;
455  }
456 
457  Status = OtaArchive_process(&pOtaLib->OtaArchive, pOtaLib->pRecvChunk, pOtaLib->RecvChunkSize, &ProcessedBytes);
458  pOtaLib->RecvChunkForceReadMode = (Status == ARCHIVE_STATUS_FORCE_READ_MORE);
459  pOtaLib->RecvChunkOffset += ProcessedBytes;
460  if( Status < 0)
461  {
462  if (Status == ARCHIVE_STATUS_ERROR_SECURITY_ALERT)
463  {
464  _SlOtaLibTrace(("OTA_run: SECURITY ALERT OtaArchive_RunParse, Status=%d\r\n", Status));
465  /* On SECURITY ALERT, stop all, no consecutive errors check */
466  pOtaLib->State = OTA_STATE_IDLE;
467  _OtaCleanToIdle(pOtaLib);
468  Status = OTA_RUN_ERROR_SECURITY_ALERT;
469  }
470  else
471  {
472  _SlOtaLibTrace(("OTA_run: ERROR OtaArchive_RunParse, Status=%d\r\n", Status));
473  Status = _OtaCheckConsecutiveErrors(pOtaLib, OTA_RUN_STATUS_CONTINUE_WARNING_FAILED_DOWNLOAD_AND_SAVE, BACK_TO_IDLE);
474  }
475  return Status;
476  }
477  else if (Status == ARCHIVE_STATUS_DOWNLOAD_DONE)
478  {
479  _SlOtaLibTrace(("OTA_run: ---- Download file completed %s\r\n", pOtaLib->pOtaFileName));
480  CdnClient_CloseFileServer(&pOtaLib->CdnClient);
481  pOtaLib->State = OTA_STATE_WAIT_CONFIRM; /* not real state, cannot go to idle, user app should reset */
482  pOtaLib->ConsecutiveOtaErrors = 0;
483 
484  return OTA_RUN_STATUS_DOWNLOAD_DONE;
485  }
486  break;
487 
488  case OTA_STATE_WAIT_CONFIRM:
489  /* not real state, cannot go to idle, user app should reset */
490  _SlOtaLibTrace(("sl_OtaRun ERROR: unexpected state %d\r\n", pOtaLib->State));
491  return OTA_RUN_STATUS_DOWNLOAD_DONE;
492 
493  default:
494  _SlOtaLibTrace(("sl_OtaRun ERROR: unexpected state %d\r\n", pOtaLib->State));
495  return OTA_RUN_ERROR_UNEXPECTED_STATE;
496 
497  }
498 
499  return OTA_RUN_STATUS_CONTINUE;
500 }

§ OTA_set()

int16_t OTA_set ( OTA_option  option,
int32_t  optionLen,
uint8_t *  pOptionVal,
int32_t  flags 
)

Set OTA command/parameter.

Parameters
[in]pOtaLibOTA control block pointer
[in]OptionSelect the option
[in]OptionLenOption structure length
[in]pOptionValpointer to the option structure

This function sets OTA command/parameter. The parameter Option can be one of the following:

EXTLIB_OTA_SET_OPT_SERVER_INFO - Set the Server information
EXTLIB_OTA_SET_OPT_VENDOR_ID - Set the Vendor DIR string
EXTLIB_OTA_SET_OPT_ACCEPT_UPDATE - Accept the new image
EXTLIB_OTA_SET_OPT_DECLINE_UPDATE - Decline the new image
EXTLIB_OTA_SET_OPT_IMAGE_COMMIT - Commit the currnet image in testing mode
EXTLIB_OTA_SET_OPT_IMAGE_ROLLBACK - decline the currnet image in testing mode and rollback to the previous image

Returns
On success, zero is returned. On error, -1 is returned
See also
Note
Warning
Example:
For example: Set OTA server info from host
Ota_optServerInfo g_otaOptServerInfo;
g_otaOptServerInfo.IpAddress = OTA_SERVER_IP_ADDRESS;
g_otaOptServerInfo.SecuredConnection = OTA_SERVER_SECURED;
strcpy((char *)g_otaOptServerInfo.ServerName, OTA_SERVER_NAME);
strcpy((char *)g_otaOptServerInfo.VendorToken, OTA_VENDOR_TOKEN);
Status = Ota_set(EXTLIB_OTA_SET_OPT_SERVER_INFO, sizeof(g_otaOptServerInfo), (uint8_t *)&g_otaOptServerInfo);
Ota_set(EXTLIB_OTA_SET_OPT_SERVER_INFO, sizeof(g_otaOptServerInfo), (uint8_t *)&g_otaOptServerInfo, 0);

Definition at line 99 of file OtaLib.c.

100 {
101  int16_t Status = OTA_STATUS_OK;
102 
103  switch (option)
104  {
105  case EXTLIB_OTA_SET_OPT_SERVER_INFO:
106  memcpy(&pOtaLib->OtaServerInfo, pOptionVal, sizeof(Ota_optServerInfo));
107  break;
108 
109  case EXTLIB_OTA_SET_OPT_FILE_SERVER_URL:
110  strcpy((char *)pOtaLib->FileUrlBuf, (char *)pOptionVal);
111  pOtaLib->OtaServerInfo.SecuredConnection = OTA_SERVER_SECURED;
112  break;
113 
114  case EXTLIB_OTA_SET_OPT_VENDOR_ID:
115  if (strlen((const char *)pOptionVal) >= MAX_VENDIR_DIR_SIZE)
116  {
117  return OTA_OPT_ERROR_VENDOR_DIR_SIZE;
118  }
119  strcpy((char *)pOtaLib->VendorDir, (const char *)pOptionVal);
120  break;
121 
122  case EXTLIB_OTA_SET_OPT_ACCEPT_UPDATE:
123  /* check if after OTA_STATE_CHECK_ARCHIVE_NEW_UPDATE state */
124  if (pOtaLib->State != OTA_STATE_CHECK_ARCHIVE_NEW_UPDATE)
125  {
126  _SlOtaLibTrace(("OTA_set: ERROR EXTLIB_OTA_SET_OPT_ACCEPT_UPDATE in wrong state = %d\r\n", pOtaLib->State));
127  return OTA_OPT_ERROR_WRONG_STATE;
128  }
129 
130  pOtaLib->State = OTA_STATE_REQ_FILE_URL;
131  break;
132 
133  case EXTLIB_OTA_SET_OPT_DECLINE_UPDATE:
134 
135  /* check if after OTA_STATE_CHECK_ARCHIVE_NEW_UPDATE state */
136  if (pOtaLib->State != OTA_STATE_REQ_FILE_URL)
137  {
138  _SlOtaLibTrace(("OTA_set: ERROR EXTLIB_OTA_SET_OPT_DECLINE_UPDATE in wrong state = %d\r\n", pOtaLib->State));
139  return OTA_OPT_ERROR_WRONG_STATE;
140  }
141 
142  /* close all connection from last OTA updates and back to IDLE */
143  pOtaLib->ConsecutiveOtaErrors = 0;
144  _OtaCleanToIdle(pOtaLib);
145  break;
146 
147  case EXTLIB_OTA_SET_OPT_IMAGE_COMMIT:
148 
149  Status = OtaArchive_commit();
150  if (Status < 0)
151  {
152  _SlOtaLibTrace(("OTA_set: ERROR OtaArchive_Commit, status=%d\r\n", Status));
153  return OTA_OPT_ERROR_COMMIT;
154  }
155 
156 
157  break;
158 
159  case EXTLIB_OTA_SET_OPT_IMAGE_ROLLBACK:
160 
161  Status = OtaArchive_rollback();
162  if (Status < 0)
163  {
164  if (Status == SL_ERROR_FS_BUNDLE_NOT_IN_CORRECT_STATE)
165  {
166  _SlOtaLibTrace(("OTA_set: ERROR OtaArchive_Rollback, status=%d - ignored SL_ERROR_FS_BUNDLE_NOT_IN_CORRECT_STATE\r\n", Status));
167  /* Ignore error calling rollback in the incorrect state */
168  return OTA_STATUS_OK;
169  }
170  _SlOtaLibTrace(("OTA_set: ERROR OtaArchive_Rollback, status=%d\r\n", Status));
171  return OTA_OPT_ERROR_ROLLBACK;
172  }
173  break;
174 
175  default:
176  _SlOtaLibTrace(("OTA_set: option %ld is not implemented\r\n", option));
177  return OTA_OPT_ERROR_OPTION_CODE;
178  }
179 
180  return Status;
181 }

Variable Documentation

§ Buff

uint8_t Buff[OTA_BLOCK_SIZE]

Definition at line 56 of file ota.h.

§ CurrentVersion

uint8_t CurrentVersion[VERSION_STR_SIZE+1]

Definition at line 83 of file ota.h.

§ IpAddress

uint32_t IpAddress

Definition at line 75 of file ota.h.

§ NewVersion

uint8_t NewVersion[VERSION_STR_SIZE+1]

Definition at line 84 of file ota.h.

§ SecuredConnection

uint32_t SecuredConnection

Definition at line 76 of file ota.h.

§ ServerName

uint8_t ServerName[MAX_SERVER_NAME]

Definition at line 77 of file ota.h.

§ VendorToken

uint8_t VendorToken[MAX_VENDOR_TOKEN_SIZE]

Definition at line 78 of file ota.h.