• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
17 #include "plugin_adapter.h"
18 
19 #include "ext_plugin_manager.h"
20 #include "dev_auth_module_manager.h"
21 #include "device_auth_defines.h"
22 #include "hc_log.h"
23 
24 #ifdef __CC_ARM                         /* ARM Compiler */
25     #define DEV_AUTH_WEAK               __weak
26 #elif defined (__IAR_SYSTEMS_ICC__)     /* for IAR Compiler */
27     #define DEV_AUTH_WEAK               __weak
28 #elif defined (__GNUC__)                /* GNU GCC Compiler */
29     #define DEV_AUTH_WEAK               __attribute__((weak))
30 #else
31     #define DEV_AUTH_WEAK
32 #endif
33 
GetExtendCredPlugin(void)34 DEV_AUTH_WEAK const CredPlugin *GetExtendCredPlugin(void)
35 {
36     return NULL;
37 }
38 
GetExtendAuthModulePlugin(void)39 DEV_AUTH_WEAK const AuthModuleBase *GetExtendAuthModulePlugin(void)
40 {
41     return NULL;
42 }
43 
LoadExtendPlugin(void)44 void LoadExtendPlugin(void)
45 {
46     const CredPlugin *credPlugin = GetExtendCredPlugin();
47     const AuthModuleBase *authModulePlugin = GetExtendAuthModulePlugin();
48     if (credPlugin == NULL || authModulePlugin == NULL) {
49         LOGI("[Plugin]: no need to load plugins.");
50         return;
51     }
52     int32_t res = AddCredPlugin(credPlugin);
53     if (res != HC_SUCCESS) {
54         LOGE("[Plugin]: init cred plugin fail. [Res]: %" LOG_PUB "d", res);
55         return;
56     }
57     res = AddAuthModulePlugin(authModulePlugin);
58     if (res != HC_SUCCESS) {
59         LOGE("[Plugin]: init auth module plugin fail. [Res]: %" LOG_PUB "d", res);
60         DelCredPlugin(credPlugin->pluginName);
61         return;
62     }
63     LOGI("[Plugin]: load extend plugin success.");
64 }
65 
UnloadExtendPlugin(void)66 void UnloadExtendPlugin(void)
67 {
68     const CredPlugin *credPlugin = GetExtendCredPlugin();
69     const AuthModuleBase *authModulePlugin = GetExtendAuthModulePlugin();
70     if (credPlugin == NULL || authModulePlugin == NULL) {
71         LOGI("[Plugin]: no need to unload plugins.");
72         return;
73     }
74     DelAuthModulePlugin(authModulePlugin->moduleType);
75     DelCredPlugin(credPlugin->pluginName);
76     LOGI("[Plugin]: unload extend plugin success.");
77 }