1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 #include "securevirtualresourcetypes.h"
25 #include "srmresourcestrings.h"
26 #include "cainterface.h"
27 #include "oxmverifycommon.h"
29 #define TAG "OIC_VERIFY_COMMON"
31 static VerifyOptionBitmask_t gVerifyOption = (DISPLAY_NUM | USER_CONFIRM);
33 static DisplayNumContext_t gDisplayNumContext = { .callback = NULL, .context = NULL };
34 static UserConfirmContext_t gUserConfirmContext = { .callback = NULL, .context = NULL };
35 static InputStateContext_t gInputStateContext = { .callback = NULL, .context = NULL };
37 void SetDisplayNumCB(void * ptr, DisplayNumCallback displayNumCB)
39 OIC_LOG(DEBUG, TAG, "IN SetDisplayNumCB");
40 if (NULL == displayNumCB)
42 OIC_LOG(ERROR, TAG, "Failed to set callback for displaying mutualVerifNum");
45 gDisplayNumContext.callback = displayNumCB;
46 gDisplayNumContext.context = ptr;
47 OIC_LOG(DEBUG, TAG, "OUT SetDisplayNumCB");
50 void* UnsetDisplayNumCB()
52 OIC_LOG(DEBUG, TAG, "IN UnsetDisplayNumCB");
53 void *prevctx = gDisplayNumContext.context;
54 gDisplayNumContext.callback = NULL;
55 gDisplayNumContext.context= NULL;
56 OIC_LOG(DEBUG, TAG, "OUT UnsetDisplayNumCB");
60 void SetUserConfirmCB(void * ptr, UserConfirmCallback userConfirmCB)
62 OIC_LOG(DEBUG, TAG, "IN SetUserConfirmCB");
63 if (NULL == userConfirmCB)
65 OIC_LOG(ERROR, TAG, "Failed to set callback to confirm mutualVerifNum");
68 gUserConfirmContext.callback = userConfirmCB;
69 gUserConfirmContext.context = ptr;
70 OIC_LOG(DEBUG, TAG, "OUT SetUserConfirmCB");
73 void* UnsetUserConfirmCB()
75 OIC_LOG(DEBUG, TAG, "IN UnsetUserConfirmCB");
76 void *prevctx = gUserConfirmContext.context;
77 gUserConfirmContext.callback = NULL;
78 gUserConfirmContext.context = NULL;
79 OIC_LOG(DEBUG, TAG, "OUT UnsetUserConfirmCB");
83 void SetInputStateCB(void * ptr, InputStateCallback inputStateCB)
85 OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
86 if (NULL == inputStateCB)
88 OIC_LOG(ERROR, TAG, "Failed to set callback to notify user input state");
91 gInputStateContext.callback = inputStateCB;
92 gInputStateContext.context = ptr;
93 OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
96 void* UnsetInputStateCB()
98 OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
99 void *prevctx = gInputStateContext.context;
100 gInputStateContext.callback = NULL;
101 gInputStateContext.context = NULL;
102 OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
106 void SetVerifyOption(VerifyOptionBitmask_t verifyOption)
108 OIC_LOG(DEBUG, TAG, "IN SetVerifyOption");
109 gVerifyOption = verifyOption;
110 OIC_LOG_V(DEBUG, TAG, "VerifyOption set to %d", (int) gVerifyOption);
111 OIC_LOG(DEBUG, TAG, "OUT SetVerifyOption");
114 OCStackResult VerifyOwnershipTransfer(uint8_t mutualVerifNum [MUTUAL_VERIF_NUM_LEN],
115 VerifyOptionBitmask_t verifyOption)
117 OIC_LOG(DEBUG, TAG, "IN VerifyOwnershipTransfer");
118 OIC_LOG_V(DEBUG, TAG, "gVerifyOption: %d", (int) gVerifyOption);
119 verifyOption = (VerifyOptionBitmask_t)(verifyOption & gVerifyOption);
120 if (verifyOption & DISPLAY_NUM)
122 if (!gDisplayNumContext.callback)
124 OIC_LOG(ERROR, TAG, "Callback for displaying verification PIN not registered");
125 return OC_STACK_ERROR;
127 OIC_LOG(DEBUG, TAG, "calling displayNumCallback");
128 if (OC_STACK_OK != gDisplayNumContext.callback(gDisplayNumContext.context, mutualVerifNum))
130 OIC_LOG(ERROR, TAG, "Failed to display verification PIN");
131 return OC_STACK_ERROR;
134 if (verifyOption & USER_CONFIRM)
136 if (!gUserConfirmContext.callback)
138 OIC_LOG(ERROR, TAG, "Callback to get user confirmation not registered");
139 return OC_STACK_ERROR;
141 OIC_LOG(DEBUG, TAG, "calling userConfirmCallback");
142 if (OC_STACK_OK != gUserConfirmContext.callback(gUserConfirmContext.context))
144 OIC_LOG(ERROR, TAG, "Failed to get user confirmation");
145 return OC_STACK_USER_DENIED_REQ;
148 OIC_LOG(DEBUG, TAG, "OUT VerifyOwnershipTransfer");
152 OCStackResult NotifyInputState(void)
154 OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
156 if (!gInputStateContext.callback)
158 OIC_LOG(INFO, TAG, "Callback for notifying user input state not registered");
161 OIC_LOG(INFO, TAG, "calling inputStateCallback");
162 if (OC_STACK_OK != gInputStateContext.callback(gInputStateContext.context))
164 OIC_LOG(ERROR, TAG, "Failed to notify user input state");
165 return OC_STACK_ERROR;
167 OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);