1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DSLM_CORE_DEFINES_H 17 #define DSLM_CORE_DEFINES_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #include "utils_dslm_list.h" 23 #include "utils_mutex.h" 24 #include "utils_state_machine.h" 25 #include "utils_timer.h" 26 27 #include "device_security_defines.h" 28 #include "dslm_cred.h" 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #define VERSION_MAJOR 3U 35 #define VERSION_MINOR 0U 36 #define VERSION_PATCH 0U 37 38 typedef struct DslmDeviceInfo { 39 ListNode linkNode; 40 StateMachine machine; 41 DeviceIdentify identity; 42 uint32_t version; 43 uint32_t onlineStatus; 44 uint64_t nonce; 45 uint64_t nonceTimeStamp; 46 uint64_t lastOnlineTime; 47 uint64_t lastOfflineTime; 48 uint64_t lastRequestTime; 49 uint64_t lastResponseTime; 50 uint64_t lastVerifyTime; 51 uint64_t transNum; 52 TimerHandle timeHandle; 53 uint32_t queryTimes; 54 uint32_t result; 55 DslmCredInfo credInfo; 56 uint32_t notifyListSize; 57 ListHead notifyList; 58 uint32_t historyListSize; 59 ListHead historyList; 60 } DslmDeviceInfo; 61 GetCurrentVersion(void)62static inline uint32_t GetCurrentVersion(void) 63 { 64 // shift major 16 bit, shift minor 8 bit 65 return (VERSION_MAJOR << 16U) + (VERSION_MINOR << 8U) + VERSION_PATCH; 66 } 67 VersionToMajor(uint32_t version)68static inline uint8_t VersionToMajor(uint32_t version) 69 { 70 // shift 16 bit to get version first 8 bit data as the main version 71 return (version & 0xFF0000U) >> 16U; 72 } 73 VersionToMinor(uint32_t version)74static inline uint8_t VersionToMinor(uint32_t version) 75 { 76 // get version middle 8 bit data as the minor version 77 return (version & 0xFF00U) >> 8U; 78 } 79 VersionToPatch(uint32_t version)80static inline uint8_t VersionToPatch(uint32_t version) 81 { 82 // get version last 8 bit data as the patch version 83 return version & 0xFF; 84 } 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif // DSLM_CORE_DEFINES_H 91