• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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     uint32_t deviceType;
45     uint64_t nonce;
46     uint64_t nonceTimeStamp;
47     uint64_t lastOnlineTime;
48     uint64_t lastOfflineTime;
49     uint64_t lastRequestTime;
50     uint64_t lastResponseTime;
51     uint64_t lastVerifyTime;
52     uint64_t transNum;
53     TimerHandle timeHandle;
54     uint32_t queryTimes;
55     uint32_t result;
56     DslmCredInfo credInfo;
57     uint32_t notifyListSize;
58     ListHead notifyList;
59     uint32_t historyListSize;
60     ListHead historyList;
61 } DslmDeviceInfo;
62 
GetCurrentVersion(void)63 static inline uint32_t GetCurrentVersion(void)
64 {
65     // shift major 16 bit, shift minor 8 bit
66     return (VERSION_MAJOR << 16U) + (VERSION_MINOR << 8U) + VERSION_PATCH;
67 }
68 
VersionToMajor(uint32_t version)69 static inline uint8_t VersionToMajor(uint32_t version)
70 {
71     // shift 16 bit to get version first 8 bit data as the main version
72     return (version & 0xFF0000U) >> 16U;
73 }
74 
VersionToMinor(uint32_t version)75 static inline uint8_t VersionToMinor(uint32_t version)
76 {
77     // get version middle 8 bit data as the minor version
78     return (version & 0xFF00U) >> 8U;
79 }
80 
VersionToPatch(uint32_t version)81 static inline uint8_t VersionToPatch(uint32_t version)
82 {
83     // get version last 8 bit data as the patch version
84     return version & 0xFF;
85 }
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif // DSLM_CORE_DEFINES_H
92