From fe2caefcaa1ece2e7b163741184c3fc834440a48 Mon Sep 17 00:00:00 2001 From: ToshikazuOhiwa Date: Mon, 30 Mar 2020 09:31:31 +0900 Subject: ns-backupmanager branch --- backup_manager/client/Makefile | 53 +++ backup_manager/client/include/bkup_api.h | 60 +++ .../client/include/native_service/backup_manager.h | 42 ++ .../client/include/native_service/ns_backup.h | 497 +++++++++++++++++++++ backup_manager/client/libns_backup.ver | 34 ++ backup_manager/client/src/bkup_api.cpp | 343 ++++++++++++++ 6 files changed, 1029 insertions(+) create mode 100644 backup_manager/client/Makefile create mode 100644 backup_manager/client/include/bkup_api.h create mode 100644 backup_manager/client/include/native_service/backup_manager.h create mode 100644 backup_manager/client/include/native_service/ns_backup.h create mode 100644 backup_manager/client/libns_backup.ver create mode 100644 backup_manager/client/src/bkup_api.cpp (limited to 'backup_manager/client') diff --git a/backup_manager/client/Makefile b/backup_manager/client/Makefile new file mode 100644 index 00000000..66a2a67c --- /dev/null +++ b/backup_manager/client/Makefile @@ -0,0 +1,53 @@ +# +# @copyright Copyright (c) 2017-2019 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +######### libraries to be installed(*.so)############# +INST_SHLIBS := libns_backup + +######### headers to be installed(*.h) ############# +INST_HEADERS := backup_manager.h ns_backup.h + +######### sources to be compiled ############# +libns_backup_SRCS := bkup_api.cpp + +######### search paths ############# +VPATH += ./src ./include/$(COMPONENT_NAME) ../server/include + +######### include paths ############# +CPPFLAGS += -I./include +CPPFLAGS += -I../server/include + +######### frameworkunifiedlog options ############# +CPPFLAGS += -DFRAMEWORKUNIFIEDLOGOPTIONS=0x08 -DFRAMEWORKUNIFIEDLOGAPPZONES=31,30,29,28,27,26,9,8,3 + +LDFLAGS += -Wl,--no-as-needed +LDFLAGS += -Wl,--no-undefined + +######### libraries to be linked(dynamic)############# +LDLIBS += -Wl,-Bdynamic -lNS_FrameworkUnified + +######### other unit specific options ############# +LINK_CXX=Y + +CPPFLAGS += -Werror=implicit-function-declaration +CPPFLAGS += -Werror=format-security + +CPPFLAGS += -Wconversion +CPPFLAGS += -Wint-to-pointer-cast +CPPFLAGS += -Wpointer-arith +CPPFLAGS += -Wformat + +include ../../native_service.mk diff --git a/backup_manager/client/include/bkup_api.h b/backup_manager/client/include/bkup_api.h new file mode 100644 index 00000000..b372dd49 --- /dev/null +++ b/backup_manager/client/include/bkup_api.h @@ -0,0 +1,60 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BACKUP_MANAGER_CLIENT_INCLUDE_BKUP_API_H_ +#define BACKUP_MANAGER_CLIENT_INCLUDE_BKUP_API_H_ + +#define BACKUP_CID 0xBACC1D00 + +#define BKUP_MAX_ITEM_NAME 64 + +/** + * media + */ +//#include + +/** + * command + */ +typedef enum { + BKUP_CMD_READ = 0, + BKUP_CMD_WRITE, + BKUP_CMD_FILL, + BKUP_CMD_SIZE, + BKUP_CMD_READ_NUM, + BKUP_CMD_SIZE_NUM, + BKUP_CMD_CHECK, + BKUP_CMD_DELETE, + BKUP_CMD_COPY_INNER, + BKUP_CMD_MAX, +} bkup_protocol_command_t; + +/** + * api/process protocol + */ +typedef struct { + bkup_protocol_command_t command; + char item_name[64]; + uint32_t num_id; + uint32_t offset; + uint32_t size; + char fill_patern; +// enum NvHalMedia src_media; +} bkup_protocol_header_t; + +#define SERVICE_BACKUP_MANAGER_MSG_HANDLE_THREAD "bkupmanagerthr" + +#endif // BACKUP_MANAGER_CLIENT_INCLUDE_BKUP_API_H_ diff --git a/backup_manager/client/include/native_service/backup_manager.h b/backup_manager/client/include/native_service/backup_manager.h new file mode 100644 index 00000000..abd670b0 --- /dev/null +++ b/backup_manager/client/include/native_service/backup_manager.h @@ -0,0 +1,42 @@ +/* + * @copyright Copyright (c) 2017-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file backup_manager.h + * @brief backup_manager unit common header file. + */ + +#ifndef NATIVESERVICE_BACKUPMANAGER_H_ // NOLINT(build/header_guard) +#define NATIVESERVICE_BACKUPMANAGER_H_ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup backup_manager + * @ingroup native_service + * @{ + */ + +#include + +/**@}*/ // end of backup_manager +/**@}*/ // end of native_service +/**@}*/ // end of BaseSystem + +#endif // NATIVESERVICE_BACKUPMANAGER_H_ diff --git a/backup_manager/client/include/native_service/ns_backup.h b/backup_manager/client/include/native_service/ns_backup.h new file mode 100644 index 00000000..b007a23d --- /dev/null +++ b/backup_manager/client/include/native_service/ns_backup.h @@ -0,0 +1,497 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file ns_backup.h + * @brief backup_manager function header file + */ + +#ifndef BACKUP_MANAGER_CLIENT_INCLUDE_NATIVE_SERVICE_NS_BACKUP_H_ +#define BACKUP_MANAGER_CLIENT_INCLUDE_NATIVE_SERVICE_NS_BACKUP_H_ + +#include + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup backup_manager + * @ingroup native_service + * @{ + */ + +/** + * \~english Service availability notify + */ +#define NTFY_BackupMgr_Availability "NS_BackupMgr/Availability" + +/** + * \~english Return value: terminated normally + */ +#define BKUP_RET_NORMAL 0 + +/** + * \~english Return value: abnormal termination(content not specified) + */ +#define BKUP_RET_ERROR -1 + +/** + * \~english Return value: parameter error + */ +#define BKUP_RET_ERRPARAM -2 + +/** + * \~english Return value: initializing + */ +#define BKUP_RET_ERRINIT -3 + +/** + * \~english Return value: terminating + */ +#define BKUP_RET_ERRTERM -4 + +/** + * \~english Return value: data does not exist + */ +#define BKUP_RET_ERRNOENT -5 + +/** + * \~english Return value: data size error + */ +#define BKUP_RET_ERRSIZE -6 + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \ingroup Backup_DataRd + * \~english @par Brief + * Read data from backup area + * \~english @param [in] tagID + * PCSTR - Area ID(character string of less than 64 bytes) + * \~english @param [in] uiOffset + * uint32_t - Offset from the beginning of the area(0~size of backup area identified by area ID) + * \~english @param [out] pvBuf + * void * - A pointer which point to buffer used to storage read data + * \~english @param [in] uiSize + * uint32_t - Read data size(0~size of backup area identified by area ID) + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If the buffer point(pvBuf) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * - If the size specified by the argument does not match the actual read size [BKUP_RET_ERROR] + * \~english @par Detail + - Judge the type and access destination according to specified area ID and then read data. + * + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * Backup_DataWt + */ +int32_t Backup_DataRd(PCSTR tag_id, uint32_t ui_offset, void *pv_buf, uint32_t ui_size); +/** + * \ingroup Backup_DataWt + * \~english @par Brief + * Write data to backup area + * \~english @param [in] tagID + * PCSTR - Area ID(character string of less than 64 bytes) + * \~english @param [in] pvBuf + * void * - A pointer which point to buffer used to storage write data + * \~english @param [in] uiOffset + * uint32_t - Offset from the beginning of the area(0~size of backup area identified by area ID) + * \~english @param [in] uiSize + * uint32_t - Write data size(0~size of backup area identified by area ID) + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If the buffer point(pvBuf) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If system call(mmap()) is error [BKUP_RET_ERROR] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * - If the size specified by the argument does not match the actual read size [BKUP_RET_ERROR] + * \~english @par Detail + * Judge the storage media type and access destination according to specified area ID and then write data. + * Calling @ref Backup_DataWt more than once for the same ID when writing data separately. + * Data integrity can not be guaranteed at power interruption. + * Data should be written at one time to guarantee data consistency. + * The work life of writing times depends on how the user writes,NS_BackupMgr doesn't guaranteed. + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * Backup_DataRd + */ +int32_t Backup_DataWt(PCSTR tag_id, void *pv_buf, uint32_t ui_offset, uint32_t ui_size); + + +/** + * \ingroup Backup_DataFil + * \~english @par Brief + * Write data to backup area with the specified pattern + * \~english @param [in] tagID + * PCSTR - Area ID(character string of less than 64 bytes) + * \~english @param [in] uiOffset + * uint32_t - Offset from the beginning of the area(0~size of backup area identified by area ID) + * \~english @param [in] ucPat + * uint8_t - Write pattern data(0x00~0xff) + * \~english @param [in] uiSize + * uint32_t - Write data size(0~size of backup area identified by area ID) + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * - If the size specified by the argument does not match the actual read size [BKUP_RET_ERROR] + * \~english @par Detail + * Judge the type and access destination according to specified area ID and then fill it with the specified pattern. + * The work life of writing times depends on how the usrs writes,NS_BackupMgr doesn't guaranteed. + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * none + */ +int32_t Backup_DataFil(PCSTR tag_id, uint32_t ui_offset, uint8_t uc_pat, uint32_t ui_size); + + +/** + * \ingroup Backup_DataSz + * \~english @par Brief + * Get the size of the backup area. + * \~english @param [in] tagID + * PCSTR - Area ID(character string of less than 64 bytes) + * \~english @param [out] puiSize + * uint32_t * - A pointer which point to storage size + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If the pointer(puiSize) that stores the size specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * - If the size specified by the argument does not match the actual size [BKUP_RET_ERROR] + * \~english @par Detail + * Judge the type and access destination according to specified area ID and acquire the size of the target data. + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * none + */ +int32_t Backup_DataSz(PCSTR tag_id, uint32_t *pui_size); + +/** + * \ingroup Backup_DataRdByNumID + * \~english @par Brief + * Read data from backup area + * \~english @param [in] numID + * uint32_t - Area ID specified by number + * \~english @param [in] uiOffset + * uint32_t - Offset from the beginning of the area(0~size of backup area identified by area ID) + * \~english @param [out] pvBuf + * void * - A pointer which point to buffer used to storage read data + * \~english @param [in] uiSize + * uint32_t - Read data size(0~size of backup area identified by area ID) + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If the buffer point(pvBuf) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * - If the size specified by the argument does not match the actual read size [BKUP_RET_ERROR] + * \~english @par Detail + * Judge the type and access destination according to specified area ID and then read data. + * Backup Non-volatile Data Read API for DIAG + * Use from the module other than DIAG is prohibited. + * + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * Backup_DataRd + */ +int32_t Backup_DataRdByNumID(uint32_t num_id, uint32_t ui_offset, void *pv_buf, uint32_t ui_size); + + +/** + * \ingroup Backup_DataSzByNumID + * \~english @par Brief + * Get the size of the backup area. + * \~english @param [in] numID + * uint32_t - Area ID specified by number + * \~english @param [out] puiSize + * uint32_t * - A pointer which point to storage size + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If the pointer(puiSize) that stores the size specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * - If the size specified by the argument does not match the actual size [BKUP_RET_ERROR] + * \~english @par Detail + * Judge the type and access destination according to specified area ID and acquire the size of the target data. + * Get Non-volatile backup data size API for DIAG + * Use from the module other than DIAG is prohibited. + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * Backup_DataSz + */ +int32_t Backup_DataSzByNumID(uint32_t num_id, uint32_t *pui_size); + +/** + * \ingroup Backup_DataChk + * \~english @par Brief + * Check backup data. + * \~english @param [in] tagID + * PCSTR - Area ID(character string of less than 64 bytes) + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * - If the size specified by the argument does not match the actual read size [BKUP_RET_ERROR] + * \~english @par Detail + * Judge the type and access destination according to specified area ID and check the target data. + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * none + */ +int32_t Backup_DataChk(PCSTR tag_id); + +/** + * \ingroup Backup_DataDel + * \~english @par Brief + * Delete backup data. + * \~english @param [in] tag_id + * PCSTR - Area ID(character string of less than 64 bytes) + * \~english @retval BKUP_RET_NORMAL Terminated normally + * \~english @retval BKUP_RET_ERRPARAM Parameter error(Sync message transmission or reception(@ref McInvokeSync) error[eFrameworkunifiedStatusInvldParam]) + * \~english @retval BKUP_RET_ERRINIT Initializing(Sync message send or receive(@ref McInvokeSync) error [eFrameworkunifiedStatusErrOther]) + * \~english @retval BKUP_RET_ERRTERM Terminating(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusExit]) + * \~english @retval BKUP_RET_ERRNOENT Data dose not exist(Sync message transmission or reception(@ref McInvokeSync) fails [eFrameworkunifiedStatusFileLoadError]) + * \~english @retval BKUP_RET_ERRSIZE Data size error(Sync message transmission or reception(@ref McInvokeSync) error [eFrameworkunifiedStatusAccessError]) + * \~english @retval BKUP_RET_ERROR Abnormal termination(@ref McOpenSender failed, or sync message transmission or reception(@ref McInvokeSync) error other than the above) + * \~english @par Prerequisite + * - None. + * \~english @par Change of internal state + * - Change of internal state according to the API does not occur. + * \~english @par Conditions of processing failure + * - If the area ID(tagID) specified by the argument is NULL [BKUP_RET_ERRPARAM] + * - If the area ID(tagID) specified by the argument is 64 bytes or more than 64 bytes [BKUP_RET_ERRPARAM] + * - If system call(pctrl(PR_GET_NAME)) is error [BKUP_RET_ERROR] + * - If failed to open the message queue for transmission [BKUP_RET_ERROR] + * - If failed to genarate message queue name for synchronous communication [BKUP_RET_ERROR] + * - If failed to open the reception message queue for synchronous communication [BKUP_RET_ERROR] + * - Sync message transmission or reception(@ref McInvokeSync) error + * - If the return value is eFrameworkunifiedStatusInvldParam [BKUP_RET_ERRPARAM] + * - If the return value is eFrameworkunifiedStatusErrOther [BKUP_RET_ERRINIT] + * - If the return value is eFrameworkunifiedStatusExit [BKUP_RET_ERRTERM] + * - If the return value is eFrameworkunifiedStatusFileLoadError [BKUP_RET_ERRNOENT] + * - If the return value is eFrameworkunifiedStatusAccessError [BKUP_RET_ERRSIZE] + * - If the return value is eFrameworkunifiedStatusFail, it call will synchronization message transmission(@ref McInvokeSync) again after 100 milliseconds later + * If the return value is eFrameworkunifiedStatusFail, it will retry BKUP_RETRY_MAX(10) times + * - If the return value is other value [BKUP_RET_ERROR] + * \~english @par Detail + * Judge the type and access destination according to specified area ID and delete the target data. + * \~english @par Classification + * Public + * \~english @par Type + * Sync + * \~english @see + * none + */ +int32_t Backup_DataDel(PCSTR tag_id); + +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +/**@}*/ // end of backup_manager +/**@}*/ // end of native_service +/**@}*/ // end of BaseSystem + +#endif // BACKUP_MANAGER_CLIENT_INCLUDE_NATIVE_SERVICE_NS_BACKUP_H_ diff --git a/backup_manager/client/libns_backup.ver b/backup_manager/client/libns_backup.ver new file mode 100644 index 00000000..4ad02dfb --- /dev/null +++ b/backup_manager/client/libns_backup.ver @@ -0,0 +1,34 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +# +# backup version script +# +{ + global: + ### .text section ### + Backup_DataRd; + Backup_DataWt; + Backup_DataFil; + Backup_DataSz; + Backup_DataRdByNumID; + Backup_DataSzByNumID; + Backup_DataChk; + Backup_DataDel; + ### .data section ### + local: + *; +}; diff --git a/backup_manager/client/src/bkup_api.cpp b/backup_manager/client/src/bkup_api.cpp new file mode 100644 index 00000000..1372ba8d --- /dev/null +++ b/backup_manager/client/src/bkup_api.cpp @@ -0,0 +1,343 @@ +/* + * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "bkup_api.h" +#include "bkup_backupmanagerlog.h" +#include "bkup_util.h" + +#define BKUP_RETRY_MAX (10) +#define BKUP_RETRY_TIMER (100 * 1000) + +static __thread HANDLE g_bkup_msg_handle; +static __thread HANDLE g_bkup_response_handle; + +static int32_t BkupApiCheckTagid(PCSTR tag_id) { + if (tag_id == NULL) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "tag_id is NULL"); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + return BKUP_RET_ERRPARAM; + } + if (strlen(tag_id) >= BKUP_MAX_ITEM_NAME) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "tag_id is long:%zd", strlen(tag_id)); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + return BKUP_RET_ERRPARAM; + } + return BKUP_RET_NORMAL; +} + +static int32_t BkupApiCall(void *snd_buf, size_t snd_size, void *rcv_buf, uint32_t rcv_size) { + int32_t ret = BKUP_RET_ERROR; + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusFail; + uint32_t real_rcvlen = 0; + static __thread char thread_name[16]; + + if (g_bkup_msg_handle == NULL) { + char invoker_name[24]; + + if (prctl(PR_GET_NAME, thread_name) < 0) { // LCOV_EXCL_BR_LINE 5:prctl's error case. + // LCOV_EXCL_START 5:prctl's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "prctl(PR_GET_NAME):%s", strerror(errno)); + goto exit; + // LCOV_EXCL_STOP 5:prctl's error case. + } + + g_bkup_msg_handle = McOpenSender(SERVICE_BACKUP_MANAGER_MSG_HANDLE_THREAD); + if (g_bkup_msg_handle == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case + // LCOV_EXCL_START 4: NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "McOpenSender"); + goto exit; + // LCOV_EXCL_STOP 4: NSFW error case + } + + // LCOV_EXCL_BR_START 4: NSFW error case + if ((e_status = McCreateInvokerName(thread_name, 0, invoker_name, sizeof(invoker_name))) != eFrameworkunifiedStatusOK) { + // LCOV_EXCL_BR_STOP 4: NSFW error case + // LCOV_EXCL_START 4: NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "McCreateInvokerName:%d", e_status); + McClose(g_bkup_msg_handle); + g_bkup_msg_handle = NULL; + goto exit; + // LCOV_EXCL_STOP 4: NSFW error case + } + + g_bkup_response_handle = McOpenSyncReceiver(invoker_name); + if (g_bkup_response_handle == NULL) { // LCOV_EXCL_BR_LINE 4: NSFW error case + // LCOV_EXCL_START 4: NSFW error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "McOpenSyncReceiver"); + McClose(g_bkup_msg_handle); + g_bkup_msg_handle = NULL; + goto exit; + // LCOV_EXCL_STOP 4: NSFW error case + } + } + + for (int retry_cnt = 0; retry_cnt < BKUP_RETRY_MAX; retry_cnt++) { // LCOV_EXCL_BR_LINE 4: NSFW error case + e_status = McInvokeSync(g_bkup_msg_handle, thread_name, BACKUP_CID, static_cast(snd_size), snd_buf, 0, + g_bkup_response_handle, rcv_size, rcv_buf, &real_rcvlen); + if (e_status != eFrameworkunifiedStatusFail) { // LCOV_EXCL_BR_LINE 4: NSFW error case + break; + } + usleep(BKUP_RETRY_TIMER); + } + + if (e_status != eFrameworkunifiedStatusOK) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "McInvokeSync:%d", e_status); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + if (e_status == eFrameworkunifiedStatusInvldParam) { + ret = BKUP_RET_ERRPARAM; + } else if (e_status == eFrameworkunifiedStatusErrOther) { + ret = BKUP_RET_ERRINIT; + } else if (e_status == eFrameworkunifiedStatusExit) { + ret = BKUP_RET_ERRTERM; + } else if (e_status == eFrameworkunifiedStatusFileLoadError) { + ret = BKUP_RET_ERRNOENT; + } else if (e_status == eFrameworkunifiedStatusAccessError) { + ret = BKUP_RET_ERRSIZE; + } else { + ret = BKUP_RET_ERROR; + } + goto exit; + } + if (rcv_size != real_rcvlen) { + goto exit; + } + ret = BKUP_RET_NORMAL; + +exit: + return ret; +} + +int32_t Backup_DataRd(PCSTR tag_id, uint32_t ui_offset, void *pv_buf, uint32_t ui_size) { + int32_t ret = BKUP_RET_NORMAL; + bkup_protocol_header_t hdr; + + if ((ret = BkupApiCheckTagid(tag_id)) != BKUP_RET_NORMAL) { + goto exit; + } + if (pv_buf == NULL) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Buf is NULL"); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + ret = BKUP_RET_ERRPARAM; + goto exit; + } + + memset(&hdr, 0, sizeof(hdr)); + hdr.command = BKUP_CMD_READ; + BkupStrlcpy(hdr.item_name, tag_id, sizeof(hdr.item_name)); + hdr.offset = ui_offset; + hdr.size = ui_size; + + ret = BkupApiCall(&hdr, sizeof(hdr), pv_buf, ui_size); + +exit: + return ret; +} + +int32_t Backup_DataWt(PCSTR tag_id, void *pv_buf, uint32_t ui_offset, uint32_t ui_size) { + int32_t ret; + char *snd_buf = NULL; + size_t snd_buf_size = 0; + bkup_protocol_header_t *hdr; + + if ((ret = BkupApiCheckTagid(tag_id)) != BKUP_RET_NORMAL) { + goto exit; + } + if (pv_buf == NULL) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Buf is NULL"); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + ret = BKUP_RET_ERRPARAM; + goto exit; + } + + // LCOV_EXCL_BR_START 5:mmap's error case. + if ((snd_buf = BkupAnonMmap(sizeof(bkup_protocol_header_t) + ui_size)) == MAP_FAILED) { + // LCOV_EXCL_BR_STOP 5:mmap's error case. + // LCOV_EXCL_START 5:mmap's error case. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "mmap:%s", strerror(errno)); + ret = BKUP_RET_ERROR; + goto exit; + // LCOV_EXCL_STOP 5:mmap's error case. + } + snd_buf_size = sizeof(bkup_protocol_header_t) + ui_size; + + hdr = reinterpret_cast(snd_buf); + hdr->command = BKUP_CMD_WRITE; + BkupStrlcpy(hdr->item_name, tag_id, sizeof(hdr->item_name)); + hdr->offset = ui_offset; + hdr->size = ui_size; + memcpy(snd_buf + sizeof(bkup_protocol_header_t), pv_buf, ui_size); + + ret = BkupApiCall(snd_buf, snd_buf_size, NULL, 0); + +exit: + if (snd_buf) { + munmap(snd_buf, snd_buf_size); + } + return ret; +} + +int32_t Backup_DataFil(PCSTR tag_id, uint32_t ui_offset, uint8_t uc_pat, uint32_t ui_size) { + int32_t ret; + bkup_protocol_header_t hdr; + + if ((ret = BkupApiCheckTagid(tag_id)) != BKUP_RET_NORMAL) { + goto exit; + } + + memset(&hdr, 0, sizeof(hdr)); + hdr.command = BKUP_CMD_FILL; + BkupStrlcpy(hdr.item_name, tag_id, sizeof(hdr.item_name)); + hdr.offset = ui_offset; + hdr.size = ui_size; + hdr.fill_patern = uc_pat; + + ret = BkupApiCall(&hdr, sizeof(hdr), NULL, 0); + +exit: + return ret; +} + +int32_t Backup_DataSz(PCSTR tag_id, uint32_t *pui_size) { + int32_t ret; + bkup_protocol_header_t hdr; + + if ((ret = BkupApiCheckTagid(tag_id)) != BKUP_RET_NORMAL) { + goto exit; + } + if (pui_size == NULL) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Buf is NULL"); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + ret = BKUP_RET_ERRPARAM; + goto exit; + } + + memset(&hdr, 0, sizeof(hdr)); + hdr.command = BKUP_CMD_SIZE; + BkupStrlcpy(hdr.item_name, tag_id, sizeof(hdr.item_name)); + + ret = BkupApiCall(&hdr, sizeof(hdr), pui_size, sizeof(uint32_t)); + +exit: + return ret; +} + +int32_t Backup_DataRdByNumID(uint32_t num_id, uint32_t ui_offset, void *pv_buf, uint32_t ui_size) { + int32_t ret = BKUP_RET_NORMAL; + bkup_protocol_header_t hdr; + + if (pv_buf == NULL) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Buf is NULL"); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + ret = BKUP_RET_ERRPARAM; + goto exit; + } + + memset(&hdr, 0, sizeof(hdr)); + hdr.command = BKUP_CMD_READ_NUM; + hdr.num_id = num_id; + hdr.offset = ui_offset; + hdr.size = ui_size; + + ret = BkupApiCall(&hdr, sizeof(hdr), pv_buf, ui_size); + +exit: + return ret; +} + +int32_t Backup_DataSzByNumID(uint32_t num_id, uint32_t *pui_size) { + int32_t ret; + bkup_protocol_header_t hdr; + + if (pui_size == NULL) { + // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h" + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Buf is NULL"); + // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h" + ret = BKUP_RET_ERRPARAM; + goto exit; + } + + memset(&hdr, 0, sizeof(hdr)); + hdr.command = BKUP_CMD_SIZE_NUM; + hdr.num_id = num_id; + + ret = BkupApiCall(&hdr, sizeof(hdr), pui_size, sizeof(uint32_t)); + +exit: + return ret; +} + +int32_t Backup_DataChk(PCSTR tag_id) { + int32_t ret; + bkup_protocol_header_t hdr; + + if ((ret = BkupApiCheckTagid(tag_id)) != BKUP_RET_NORMAL) { + goto exit; + } + + memset(&hdr, 0, sizeof(hdr)); + hdr.command = BKUP_CMD_CHECK; + BkupStrlcpy(hdr.item_name, tag_id, sizeof(hdr.item_name)); + + ret = BkupApiCall(&hdr, sizeof(hdr), NULL, 0); + +exit: + return ret; +} + +int32_t Backup_DataDel(PCSTR tag_id) { + int32_t ret; + bkup_protocol_header_t hdr; + + ret = BkupApiCheckTagid(tag_id); + if (ret != BKUP_RET_NORMAL) { + FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "tag_id is invalid"); + goto exit; + } + + memset(&hdr, 0, sizeof(hdr)); + hdr.command = BKUP_CMD_DELETE; + BkupStrlcpy(hdr.item_name, tag_id, sizeof(hdr.item_name)); + + ret = BkupApiCall(&hdr, sizeof(hdr), NULL, 0); + +exit: + return ret; +} -- cgit 1.2.3-korg