2 * Copyright (C) 2012 Samsung Electronics Co., LTD
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "tlc_communication.h"
21 #define LOG_TAG "tlc_communication"
24 mcResult_t
tlc_open(mc_comm_ctx
*comm_ctx
) {
27 LOG_I("open() called");
29 // -------------------------------------------------------------
30 // Step 1: Open the MobiCore device
31 LOG_I("Opening MobiCore device");
32 mcRet
= mcOpenDevice(comm_ctx
->device_id
);
33 if (MC_DRV_OK
!= mcRet
)
34 LOG_I("mcOpenDevice result: %d", mcRet
);
37 // -------------------------------------------------------------
38 // Step 2: Allocate WSM buffer for the TCI
39 LOG_I("Allocating WSM for TCI");
40 mcRet
= mcMallocWsm(comm_ctx
->device_id
, 0, sizeof(tciMessage_t
), (uint8_t **)&(comm_ctx
->tci_msg
), 0);
41 if (MC_DRV_OK
!= mcRet
) {
42 LOG_E("Allocation of TCI WSM failed: %d", mcRet
);
46 // -------------------------------------------------------------
47 // Step 3: Open session with the Trustlet
48 LOG_I("Opening the session");
49 bzero(&(comm_ctx
->handle
), sizeof(mcSessionHandle_t
)); // Clear the session handle
51 comm_ctx
->handle
.deviceId
= comm_ctx
->device_id
; // The device ID (default device is used)
53 mcRet
= mcOpenSession(&(comm_ctx
->handle
), &(comm_ctx
->uuid
), (uint8_t *)(comm_ctx
->tci_msg
),
54 (uint32_t) sizeof(tciMessage_t
));
55 if (MC_DRV_OK
!= mcRet
) {
56 LOG_E("Open session failed: %d", mcRet
);
60 LOG_I("tlc_open() succeeded");
66 mcResult_t
tlc_close(mc_comm_ctx
*comm_ctx
) {
69 LOG_I("close() called");
72 // -------------------------------------------------------------
75 mcRet
= mcFreeWsm((comm_ctx
->device_id
), (uint8_t *)(comm_ctx
->tci_msg
));
76 if (MC_DRV_OK
!= mcRet
) {
77 LOG_E("Free WSM failed: %d", mcRet
);
81 // -------------------------------------------------------------
82 // Step 2: Close session with the Trustlet
83 LOG_I("Closing the session");
84 mcRet
= mcCloseSession(&(comm_ctx
->handle
));
85 if (MC_DRV_OK
!= mcRet
) {
86 LOG_E("Closing session failed: %d", mcRet
);
90 // -------------------------------------------------------------
91 // Step 3: Close the MobiCore device
92 LOG_I("Closing MobiCore device");
93 mcRet
= mcCloseDevice(comm_ctx
->device_id
);
94 if (MC_DRV_OK
!= mcRet
) {
95 LOG_E("Closing MobiCore device failed: %d", mcRet
);
99 LOG_I("tlc_close() succeeded");
105 mcResult_t
tlc_communicate(mc_comm_ctx
*comm_ctx
) {
109 // -------------------------------------------------------------
110 // Step 1: signal the Trustlet
111 mcRet
= mcNotify(&(comm_ctx
->handle
));
112 if (MC_DRV_OK
!= mcRet
) {
113 LOG_E("Notify failed: %d", mcRet
);
116 LOG_I("mcNotify is completed\n");
118 // -------------------------------------------------------------
119 // Step 2: Wait for the Trustlet response
120 mcRet
= mcWaitNotification(&(comm_ctx
->handle
), -1);
121 if (MC_DRV_OK
!= mcRet
) {
122 LOG_E("Wait for response notification failed: %d", mcRet
);
126 LOG_I("mcWaitNotification is completed");