SimpleLink CC32xx OTA Library
Simplifies the implementation of Internet connectivity
CdnClient.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 __CDN_CLIENT_H__
33 #define __CDN_CLIENT_H__
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #define MAX_DIR_FILES 4
40 #define MAX_CDN_FILE_NAME_SIZE 128
41 
42 typedef struct
43 {
44  uint8_t OtaFileName[MAX_CDN_FILE_NAME_SIZE+1];
45  int32_t OtaFileSize;
46 } OtaFileInfo_t;
47 
48 typedef struct
49 {
50  int16_t NumFiles;
51  OtaFileInfo_t OtaFileInfo[MAX_DIR_FILES];
52 } OtaDirData_t;
53 
54 typedef struct
55 {
56  /* Keep OTA parameters */
57  Ota_optServerInfo *pOtaServerInfo;
58 
59  /* Keep OTA dir info */
60  int32_t CurrDirFileIndex;
61  OtaDirData_t OtaDirData;
62 
63  /* CdnDirServer connection info */
64  int16_t ServerSockId;
65  int32_t PortNum;
66  int16_t FileSockId;
67  uint8_t *pRecvChunk;
68  uint8_t *pNetBuf;
69 
70 } CdnClient_t;
71 
72 /* Internal return values */
73 #define CDN_STATUS_OK (0L)
74 #define CDN_STATUS_ERROR_SL_SEND (-20201L)
75 #define CDN_STATUS_ERROR_SL_RECV_HDR_EAGAIN (-20202L)
76 #define CDN_STATUS_ERROR_PARSE_URL_NOT_FOUND (-20203L)
77 #define CDN_STATUS_ERROR_PARSE_DIR_NO_ARRAY (-20204L)
78 #define CDN_STATUS_ERROR_PARSE_DIR_NO_OBJECT (-20205L)
79 #define CDN_STATUS_ERROR_PARSE_DIR_NO_FILE_SIZE (-20206L)
80 #define CDN_STATUS_ERROR_PARSE_DIR_NO_FILE_NAME (-20207L)
81 
82 int16_t CdnClient_Init(CdnClient_t *pCdnClient, uint8_t *pNetBuf);
83 int16_t CdnClient_ConnectServer(CdnClient_t *pCdnClient, Ota_optServerInfo *pOtaServerInfo);
84 int16_t CdnClient_CloseServer(CdnClient_t *pCdnClient);
85 int16_t CdnClient_ReqOtaDir(CdnClient_t *pCdnClient, uint8_t *pVendorDir);
86 uint8_t *CdnClient_GetNextDirFile(CdnClient_t *pCdnClient, int32_t *OtaFileSize);
87 int16_t CdnClient_ReqFileUrl(CdnClient_t *pCdnClient, uint8_t *pOtaFileName, uint8_t *pFileUrlBuf, uint32_t FileUrlBufSize);
88 int16_t CdnClient_ConnectFileServer(CdnClient_t *pCdnClient, uint8_t *pFileUrl, int32_t SecuredConnection);
89 int16_t CdnClient_ReqFileContent(CdnClient_t *pCdnClient, uint8_t *pFileUrl);
90 int16_t CdnClient_CloseFileServer(CdnClient_t *pCdnClient);
91 int16_t CdnClient_RecvSkipHdr(int16_t SockId, uint8_t *pRespBuf, int16_t RespBufSize);
92 int16_t CdnClient_RecvAppend(int16_t SockId, uint8_t *pRecvBuf, int16_t RecvBufSize, int16_t RecvLen, int16_t RecvOffset);
93 
94 #ifdef __cplusplus
95 }
96 #endif /* __cplusplus */
97 
98 #endif /* __CDN_CLIENT_H__ */