├── MODULE_LICENSE_BSD ├── MobiCoreDriverLib ├── Android.mk ├── Application.mk ├── CleanSpec.mk ├── ClientLib │ ├── Android.mk │ ├── ClientLib.cpp │ ├── Device.cpp │ ├── Device.h │ ├── GP │ │ └── tee_client_api.cpp │ ├── Session.cpp │ ├── Session.h │ └── public │ │ ├── GP │ │ ├── tee_client_api.h │ │ ├── tee_client_api_imp.h │ │ ├── tee_error.h │ │ ├── tee_type.h │ │ └── uuid_attestation.h │ │ └── MobiCoreDriverApi.h ├── Common │ ├── Android.mk │ ├── CMutex.cpp │ ├── CMutex.h │ ├── CSemaphore.cpp │ ├── CSemaphore.h │ ├── CThread.cpp │ ├── CThread.h │ ├── CWsm.h │ ├── Connection.cpp │ ├── Connection.h │ ├── McTypes.h │ ├── NOTICE │ ├── NetlinkConnection.cpp │ └── NetlinkConnection.h ├── Daemon │ ├── Android.mk │ ├── Device │ │ ├── Android.mk │ │ ├── DeviceIrqHandler.cpp │ │ ├── DeviceIrqHandler.h │ │ ├── DeviceScheduler.cpp │ │ ├── DeviceScheduler.h │ │ ├── MobiCoreDevice.cpp │ │ ├── NotificationQueue.cpp │ │ ├── NotificationQueue.h │ │ ├── Platforms │ │ │ ├── Android.mk │ │ │ └── Generic │ │ │ │ ├── Android.mk │ │ │ │ ├── TrustZoneDevice.cpp │ │ │ │ └── TrustZoneDevice.h │ │ ├── TAExitHandler.cpp │ │ ├── TAExitHandler.h │ │ ├── TrustletSession.cpp │ │ ├── TrustletSession.h │ │ └── public │ │ │ └── MobiCoreDevice.h │ ├── FSD │ │ ├── Android.mk │ │ ├── FSD.cpp │ │ └── public │ │ │ ├── FSD.h │ │ │ ├── dci.h │ │ │ └── drSecureStorage_Api.h │ ├── MobiCoreDriverDaemon.cpp │ ├── MobiCoreDriverDaemon.h │ ├── Server │ │ ├── Android.mk │ │ ├── Client.h │ │ ├── NetlinkServer.cpp │ │ ├── Queue.h │ │ ├── Server.cpp │ │ └── public │ │ │ ├── ConnectionHandler.h │ │ │ ├── NetlinkServer.h │ │ │ └── Server.h │ └── public │ │ ├── MobiCoreDriverCmd.h │ │ └── mcVersion.h ├── Kernel │ ├── Android.mk │ ├── CKMod.cpp │ ├── CKMod.h │ └── Platforms │ │ └── Generic │ │ ├── Android.mk │ │ ├── CMcKMod.cpp │ │ └── CMcKMod.h ├── MODULE_LICENSE_BSD ├── NOTICE ├── Registry │ ├── Android.mk │ ├── PrivateRegistry.cpp │ ├── PrivateRegistry.h │ ├── Public │ │ └── MobiCoreRegistry.h │ └── Registry.cpp └── buildTag.h ├── README.md ├── common ├── LogWrapper │ ├── Android.mk │ └── log.h └── MobiCore │ └── inc │ ├── McLib │ └── GpTci.h │ ├── Mci │ ├── mci.h │ ├── mcifc.h │ ├── mcimcp.h │ ├── mcinq.h │ └── version.h │ ├── TlCm │ ├── 2.0 │ │ ├── cmp.h │ │ └── tlCmApi.h │ ├── 3.0 │ │ ├── cmp.h │ │ ├── cmpMap.h │ │ └── tlCmApi.h │ ├── cmpCommon.h │ ├── tlCmApiCommon.h │ ├── tlCmError.h │ ├── tlCmUuid.h │ └── version.h │ ├── mcContainer.h │ ├── mcDriverId.h │ ├── mcLoadFormat.h │ ├── mcRootid.h │ ├── mcSo.h │ ├── mcSpid.h │ ├── mcSuid.h │ ├── mcUuid.h │ ├── mcVersionHelper.h │ ├── mcVersionInfo.h │ └── version.md5 └── include └── Public ├── mc_linux.h └── version.h /MODULE_LICENSE_BSD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trustonic/trustonic-tee-user-space/e3b0b06025605b06fc1e19588098e5011f6afc83/MODULE_LICENSE_BSD -------------------------------------------------------------------------------- /MobiCoreDriverLib/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # MobiCore Android build components 4 | # 5 | # ============================================================================= 6 | 7 | LOCAL_PATH := $(call my-dir) 8 | 9 | # Client Library 10 | # ============================================================================= 11 | include $(CLEAR_VARS) 12 | LOCAL_MODULE := libMcClient 13 | LOCAL_MODULE_TAGS := debug eng optional 14 | LOCAL_C_INCLUDES += $(GLOBAL_INCLUDES) 15 | LOCAL_SHARED_LIBRARIES += $(GLOBAL_LIBRARIES) 16 | 17 | LOCAL_CFLAGS := -fvisibility=hidden -fvisibility-inlines-hidden 18 | LOCAL_CFLAGS += -include buildTag.h 19 | LOCAL_CFLAGS += -DLOG_TAG=\"McClient\" 20 | LOCAL_CFLAGS += -DTBASE_API_LEVEL=5 21 | 22 | # Add new source files here 23 | LOCAL_SRC_FILES += \ 24 | ClientLib/Device.cpp \ 25 | ClientLib/ClientLib.cpp \ 26 | ClientLib/Session.cpp \ 27 | Common/CMutex.cpp \ 28 | Common/Connection.cpp \ 29 | ClientLib/GP/tee_client_api.cpp 30 | 31 | LOCAL_C_INCLUDES +=\ 32 | $(LOCAL_PATH)/Common \ 33 | $(LOCAL_PATH)/ClientLib/public \ 34 | $(LOCAL_PATH)/ClientLib/public/GP \ 35 | $(MOBICORE_PROJECT_PATH)/include/GPD_TEE_Internal_API \ 36 | $(MOBICORE_PROJECT_PATH)/include/public \ 37 | $(COMP_PATH_MobiCore)/inc \ 38 | $(COMP_PATH_MobiCore)/inc/McLib 39 | 40 | LOCAL_EXPORT_C_INCLUDE_DIRS +=\ 41 | $(COMP_PATH_MobiCore)/inc \ 42 | $(LOCAL_PATH)/ClientLib/public 43 | 44 | include $(LOCAL_PATH)/Kernel/Android.mk 45 | # Import logwrapper 46 | include $(COMP_PATH_Logwrapper)/Android.mk 47 | 48 | include $(BUILD_SHARED_LIBRARY) 49 | 50 | # Daemon Application 51 | # ============================================================================= 52 | include $(CLEAR_VARS) 53 | 54 | LOCAL_MODULE := mcDriverDaemon 55 | LOCAL_MODULE_TAGS := debug eng optional 56 | LOCAL_CFLAGS += -include buildTag.h 57 | LOCAL_CFLAGS += -DLOG_TAG=\"McDaemon\" 58 | LOCAL_CFLAGS += -DTBASE_API_LEVEL=3 59 | LOCAL_C_INCLUDES += $(GLOBAL_INCLUDES) 60 | LOCAL_SHARED_LIBRARIES += $(GLOBAL_LIBRARIES) libMcClient libMcRegistry 61 | 62 | include $(LOCAL_PATH)/Daemon/Android.mk 63 | 64 | # Common Source files required for building the daemon 65 | LOCAL_SRC_FILES += Common/CMutex.cpp \ 66 | Common/Connection.cpp \ 67 | Common/NetlinkConnection.cpp \ 68 | Common/CSemaphore.cpp \ 69 | Common/CThread.cpp 70 | 71 | # Includes required for the Daemon 72 | LOCAL_C_INCLUDES +=\ 73 | $(LOCAL_PATH)/Common \ 74 | $(LOCAL_PATH)/common/MobiCore/inc \ 75 | $(LOCAL_PATH)/ClientLib/public \ 76 | $(LOCAL_PATH)/ClientLib/public/GP \ 77 | $(MOBICORE_PROJECT_PATH)/include/public \ 78 | $(COMP_PATH_MobiCore)/inc \ 79 | $(COMP_PATH_MobiCore)/inc/McLib 80 | 81 | # Private Registry components 82 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/Registry/Public \ 83 | $(LOCAL_PATH)/Registry 84 | 85 | LOCAL_SRC_FILES += Registry/PrivateRegistry.cpp 86 | 87 | # Common components 88 | include $(LOCAL_PATH)/Kernel/Android.mk 89 | # Logwrapper 90 | include $(COMP_PATH_Logwrapper)/Android.mk 91 | 92 | include $(BUILD_EXECUTABLE) 93 | 94 | # Registry Shared Library 95 | # ============================================================================= 96 | include $(CLEAR_VARS) 97 | 98 | LOCAL_MODULE := libMcRegistry 99 | LOCAL_MODULE_TAGS := debug eng optional 100 | LOCAL_CFLAGS += -DLOG_TAG=\"McRegistry\" 101 | LOCAL_C_INCLUDES += $(GLOBAL_INCLUDES) 102 | LOCAL_SHARED_LIBRARIES += $(GLOBAL_LIBRARIES) 103 | 104 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/Common \ 105 | $(LOCAL_PATH)/Daemon/public \ 106 | $(LOCAL_PATH)/ClientLib/public 107 | 108 | # Common Source files required for building the daemon 109 | LOCAL_SRC_FILES += Common/CMutex.cpp \ 110 | Common/Connection.cpp \ 111 | Common/CSemaphore.cpp 112 | 113 | #LOCAL_LDLIBS := -lthread_db 114 | 115 | include $(LOCAL_PATH)/Registry/Android.mk 116 | 117 | # Import logwrapper 118 | include $(COMP_PATH_Logwrapper)/Android.mk 119 | 120 | include $(BUILD_SHARED_LIBRARY) 121 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Application.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Main build file defining the project modules and their global variables. 4 | # 5 | # ============================================================================= 6 | 7 | # Don't remove this - mandatory 8 | APP_PROJECT_PATH := $(abspath $(call my-dir)) 9 | 10 | APP_STL := stlport_static 11 | 12 | # Application wide Cflags 13 | GLOBAL_INCLUDES := \ 14 | $(COMP_PATH_MobiCoreDriverMod)/Public \ 15 | $(COMP_PATH_TlSdk)/Public/MobiCore/inc \ 16 | $(COMP_PATH_MobiCore)/inc \ 17 | $(COMP_PATH_TlCm)/Public \ 18 | $(COMP_PATH_TlCm)/Public/TlCm 19 | 20 | # Show all warnings 21 | APP_CFLAGS += -Wall 22 | 23 | LOG_WRAPPER := $(COMP_PATH_Logwrapper) 24 | 25 | APP_PLATFORM := android-9 26 | 27 | # Position Independent Executable 28 | APP_PIE := true 29 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 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 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/EXECUTABLES/openssl_intermediates) 47 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/EXECUTABLES/openssl_intermediates) 48 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libcrypto_intermediates $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/openssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/ssltest_intermediates) 49 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libcrypto_intermediates $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/openssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/ssltest_intermediates) 50 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libcrypto_intermediates $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/openssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/ssltest_intermediates) 51 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libcrypto_intermediates $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/openssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/ssltest_intermediates) 52 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libcrypto_intermediates $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/openssl_intermediates $(PRODUCT_OUT)/obj/EXECUTABLES/ssltest_intermediates) 53 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libssl_intermediates) 54 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libcrypto_intermediates) 55 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libssl_static_intermediates) 56 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libcrypto_static_intermediates) 57 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/EXECUTABLES/*ssl*_intermediates $(PRODUCT_OUT)/obj/*/libssl_*intermediates $(PRODUCT_OUT)/obj/*/libcrypto_*intermediates) 58 | 59 | # ************************************************ 60 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 61 | # ************************************************ 62 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Module: libMcClient.so - Client Lib for TLC's 4 | # 5 | # ============================================================================= 6 | 7 | LOCAL_PATH := $(call my-dir) 8 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/Device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Client library device management. 33 | * 34 | * Device and Trustlet Session management Functions. 35 | */ 36 | #ifndef DEVICE_H_ 37 | #define DEVICE_H_ 38 | 39 | #include 40 | #include 41 | 42 | #include "public/MobiCoreDriverApi.h" 43 | #include "Session.h" 44 | #include "CWsm.h" 45 | 46 | 47 | class Device 48 | { 49 | 50 | private: 51 | sessionList_t sessionList; /**< MobiCore Trustlet session associated with the device */ 52 | wsmList_t wsmL2List; /**< WSM L2 Table */ 53 | 54 | 55 | public: 56 | uint32_t deviceId; /**< Device identifier */ 57 | Connection *connection; /**< The device connection */ 58 | CMcKMod_ptr pMcKMod; 59 | uint32_t openCount; 60 | 61 | Device( 62 | uint32_t deviceId, 63 | Connection *connection 64 | ); 65 | 66 | virtual ~Device( 67 | void 68 | ); 69 | 70 | /** 71 | * Open the device. 72 | * @param deviceName Name of the kernel modules device file. 73 | * @return true if the device has been opened successfully 74 | */ 75 | bool open( 76 | const char *deviceName 77 | ); 78 | 79 | /** 80 | * Closes the device. 81 | */ 82 | void close( 83 | void 84 | ); 85 | 86 | /** 87 | * Check if the device has open sessions. 88 | * @return true if the device has one or more open sessions. 89 | */ 90 | bool hasSessions( 91 | void 92 | ); 93 | 94 | /** 95 | * Add a session to the device. 96 | * @param sessionId session ID 97 | * @param connection session connection 98 | * @return Session object created 99 | */ 100 | Session *createNewSession( 101 | uint32_t sessionId, 102 | Connection *connection 103 | ); 104 | 105 | /** 106 | * Remove the specified session from the device. 107 | * The session object will be destroyed and all resources associated with it will be freed. 108 | * 109 | * @param sessionId Session of the session to remove. 110 | * @return true if a session has been found and removed. 111 | */ 112 | bool removeSession( 113 | uint32_t sessionId 114 | ); 115 | 116 | /** 117 | * Get as session object for a given session ID. 118 | * @param sessionId Identified of a previously opened session. 119 | * @return Session object if available or NULL if no session has been found. 120 | */ 121 | Session *resolveSessionId( 122 | uint32_t sessionId 123 | ); 124 | 125 | /** 126 | * Allocate a block of contiguous WSM. 127 | * @param len The virtual address to be registered. 128 | * @param wsm The CWsm object of the allocated memory. 129 | * @return MC_DRV_OK if successful. 130 | */ 131 | mcResult_t allocateContiguousWsm( 132 | uint32_t len, 133 | CWsm **wsm 134 | ); 135 | 136 | /** 137 | * Unregister a vaddr from a device. 138 | * @param vaddr The virtual address to be registered. 139 | * @param paddr The physical address to be registered. 140 | */ 141 | mcResult_t freeContiguousWsm( 142 | CWsm_ptr pWsm 143 | ); 144 | 145 | /** 146 | * Get a WSM object for a given virtual address. 147 | * @param vaddr The virtual address which has been allocate with mcMallocWsm() in advance. 148 | * @return the WSM object or NULL if no address has been found. 149 | */ 150 | CWsm_ptr findContiguousWsm( 151 | addr_t virtAddr 152 | ); 153 | 154 | /** 155 | * Map a buffer from tlc VA to TL(Create L2 table for the buffer 156 | * @param buf The virtual address of hte buffer 157 | * @param len The length of the buffer 158 | * @param blkBuf The buffer object created 159 | * @return MC_DRV_OK if successful. 160 | */ 161 | mcResult_t mapBulkBuf( 162 | addr_t buf, 163 | uint32_t len, 164 | BulkBufferDescriptor **blkBuf 165 | ); 166 | 167 | }; 168 | 169 | #endif /* DEVICE_H_ */ 170 | 171 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/Session.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef SESSION_H_ 32 | #define SESSION_H_ 33 | 34 | #include 35 | #include 36 | 37 | #include "mc_linux.h" 38 | #include "Connection.h" 39 | #include "CMcKMod.h" 40 | #include "CMutex.h" 41 | 42 | 43 | class BulkBufferDescriptor 44 | { 45 | public: 46 | addr_t virtAddr; /**< The virtual address of the Bulk buffer*/ 47 | uint32_t sVirtualAddr; /**< The secure virtual address of the Bulk buffer*/ 48 | uint32_t len; /**< Length of the Bulk buffer*/ 49 | uint32_t handle; 50 | 51 | BulkBufferDescriptor( 52 | addr_t virtAddr, 53 | uint32_t sVirtAddr, 54 | uint32_t len, 55 | uint32_t handle 56 | ) : 57 | virtAddr(virtAddr), 58 | sVirtualAddr(sVirtAddr), 59 | len(len), 60 | handle(handle) 61 | {}; 62 | 63 | }; 64 | 65 | typedef std::list bulkBufferDescrList_t; 66 | typedef bulkBufferDescrList_t::iterator bulkBufferDescrIterator_t; 67 | 68 | 69 | /** Session states. 70 | * At the moment not used !!. 71 | */ 72 | typedef enum { 73 | SESSION_STATE_INITIAL, 74 | SESSION_STATE_OPEN, 75 | SESSION_STATE_TRUSTLET_DEAD 76 | } sessionState_t; 77 | 78 | #define SESSION_ERR_NO 0 /**< No session error */ 79 | 80 | /** Session information structure. 81 | * The information structure is used to hold the state of the session, which will limit further actions for the session. 82 | * Also the last error code will be stored till it's read. 83 | */ 84 | typedef struct { 85 | sessionState_t state; /**< Session state */ 86 | int32_t lastErr; /**< Last error of session */ 87 | } sessionInformation_t; 88 | 89 | 90 | class Session 91 | { 92 | private: 93 | CMcKMod *mcKMod; 94 | CMutex workLock; 95 | bulkBufferDescrList_t bulkBufferDescriptors; /**< Descriptors of additional bulk buffer of a session */ 96 | sessionInformation_t sessionInfo; /**< Informations about session */ 97 | public: 98 | uint32_t sessionId; 99 | Connection *notificationConnection; 100 | 101 | Session(uint32_t sessionId, CMcKMod *mcKMod, Connection *connection); 102 | 103 | virtual ~Session(void); 104 | 105 | /** 106 | * Add address information of additional bulk buffer memory to session and 107 | * register virtual memory in kernel module. 108 | * 109 | * @attention The virtual address can only be added one time. If the virtual address already exist, MC_DRV_ERR_BUFFER_ALREADY_MAPPED is returned. 110 | * 111 | * @param buf The virtual address of bulk buffer. 112 | * @param len Length of bulk buffer. 113 | * @param blkBuf pointer of the actual Bulk buffer descriptor with all address information. 114 | * 115 | * @return MC_DRV_OK on success 116 | * @return MC_DRV_ERR_BUFFER_ALREADY_MAPPED 117 | */ 118 | mcResult_t addBulkBuf(addr_t buf, uint32_t len, BulkBufferDescriptor **blkBuf); 119 | 120 | /** 121 | * Just register the buffer previously created to the session 122 | * 123 | * @attention The virtual address can only be added one time. If the virtual address already exist, MC_DRV_ERR_BUFFER_ALREADY_MAPPED is returned. 124 | * 125 | * @param blkBuf pointer of the actual Bulk buffer descriptor with all address information. 126 | * 127 | */ 128 | void addBulkBuf(BulkBufferDescriptor *blkBuf); 129 | 130 | /** 131 | * Remove address information of additional bulk buffer memory from session and 132 | * unregister virtual memory in kernel module 133 | * 134 | * @param buf The virtual address of the bulk buffer. 135 | * 136 | * @return true on success. 137 | */ 138 | mcResult_t removeBulkBuf(addr_t buf); 139 | 140 | /** 141 | * Return the Kmod handle of the bulk buff 142 | * 143 | * @param buf The secure virtual address of the bulk buffer. 144 | * 145 | * @return the Handle or 0 for failure 146 | */ 147 | uint32_t getBufHandle(uint32_t sVirtAddr, uint32_t sVirtualLen); 148 | 149 | /** 150 | * Set additional error information of the last error that occured. 151 | * 152 | * @param errorCode The actual error. 153 | */ 154 | void setErrorInfo(int32_t err); 155 | 156 | /** 157 | * Get additional error information of the last error that occured. 158 | * 159 | * @attention After request the information is set to SESSION_ERR_NO. 160 | * 161 | * @return Last stored error code or SESSION_ERR_NO. 162 | */ 163 | int32_t getLastErr(void); 164 | 165 | /** 166 | * Lock session for operation 167 | */ 168 | void lock() { 169 | workLock.lock(); 170 | } 171 | 172 | /** 173 | * Unlock session for operation 174 | */ 175 | void unlock() { 176 | workLock.unlock(); 177 | } 178 | }; 179 | 180 | typedef std::list sessionList_t; 181 | typedef sessionList_t::iterator sessionIterator_t; 182 | 183 | #endif /* SESSION_H_ */ 184 | 185 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/public/GP/tee_client_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /* 33 | * This header file corresponds to V1.0 of the GlobalPlatform 34 | * TEE Client API Specification 35 | */ 36 | #ifndef __TEE_CLIENT_API_H__ 37 | #define __TEE_CLIENT_API_H__ 38 | 39 | #include "tee_type.h" 40 | #include "tee_error.h" 41 | 42 | #if TBASE_API_LEVEL >= 3 43 | 44 | #if (!defined(TEEC_EXPORT)) && __cplusplus 45 | #define TEEC_EXPORT extern "C" 46 | #else 47 | #define TEEC_EXPORT 48 | #endif // __cplusplus 49 | 50 | 51 | 52 | /* The header tee_client_api_imp.h must define implementation-dependent 53 | types, constants and macros. 54 | 55 | The implementation-dependent types are: 56 | - TEEC_Context_IMP 57 | - TEEC_Session_IMP 58 | - TEEC_SharedMemory_IMP 59 | - TEEC_Operation_IMP 60 | 61 | The implementation-dependent constants are: 62 | - TEEC_CONFIG_SHAREDMEM_MAX_SIZE 63 | The implementation-dependent macros are: 64 | - TEEC_PARAM_TYPES 65 | */ 66 | 67 | typedef struct { 68 | uint32_t a; 69 | uint32_t b; 70 | } TEEC_Value; 71 | 72 | 73 | #include "tee_client_api_imp.h" 74 | 75 | /* Type definitions */ 76 | typedef struct TEEC_Context { 77 | TEEC_Context_IMP imp; 78 | } TEEC_Context; 79 | 80 | typedef struct TEEC_Session { 81 | TEEC_Session_IMP imp; 82 | } TEEC_Session; 83 | 84 | typedef struct TEEC_SharedMemory { 85 | void *buffer; 86 | size_t size; 87 | uint32_t flags; 88 | TEEC_SharedMemory_IMP imp; 89 | } TEEC_SharedMemory; 90 | 91 | typedef struct { 92 | void *buffer; 93 | size_t size; 94 | } TEEC_TempMemoryReference; 95 | 96 | typedef struct { 97 | TEEC_SharedMemory *parent; 98 | size_t size; 99 | size_t offset; 100 | } TEEC_RegisteredMemoryReference; 101 | 102 | 103 | 104 | typedef union { 105 | TEEC_TempMemoryReference tmpref; 106 | TEEC_RegisteredMemoryReference memref; 107 | TEEC_Value value; 108 | } TEEC_Parameter; 109 | 110 | typedef struct TEEC_Operation { 111 | volatile uint32_t started; 112 | uint32_t paramTypes; 113 | TEEC_Parameter params[4]; 114 | TEEC_Operation_IMP imp; 115 | } TEEC_Operation; 116 | 117 | 118 | #define TEEC_ORIGIN_API 0x00000001 119 | #define TEEC_ORIGIN_COMMS 0x00000002 120 | #define TEEC_ORIGIN_TEE 0x00000003 121 | #define TEEC_ORIGIN_TRUSTED_APP 0x00000004 122 | 123 | #define TEEC_MEM_INPUT 0x00000001 124 | #define TEEC_MEM_OUTPUT 0x00000002 125 | 126 | #define TEEC_NONE 0x0 127 | #define TEEC_VALUE_INPUT 0x1 128 | #define TEEC_VALUE_OUTPUT 0x2 129 | #define TEEC_VALUE_INOUT 0x3 130 | #define TEEC_MEMREF_TEMP_INPUT 0x5 131 | #define TEEC_MEMREF_TEMP_OUTPUT 0x6 132 | #define TEEC_MEMREF_TEMP_INOUT 0x7 133 | #define TEEC_MEMREF_WHOLE 0xC 134 | #define TEEC_MEMREF_PARTIAL_INPUT 0xD 135 | #define TEEC_MEMREF_PARTIAL_OUTPUT 0xE 136 | #define TEEC_MEMREF_PARTIAL_INOUT 0xF 137 | 138 | #define TEEC_LOGIN_PUBLIC 0x00000000 139 | #define TEEC_LOGIN_USER 0x00000001 140 | #define TEEC_LOGIN_GROUP 0x00000002 141 | #define TEEC_LOGIN_APPLICATION 0x00000004 142 | #define TEEC_LOGIN_USER_APPLICATION 0x00000005 143 | #define TEEC_LOGIN_GROUP_APPLICATION 0x00000006 144 | 145 | #pragma GCC visibility push(default) 146 | 147 | TEEC_EXPORT TEEC_Result TEEC_InitializeContext( 148 | const char *name, 149 | TEEC_Context *context); 150 | 151 | TEEC_EXPORT void TEEC_FinalizeContext( 152 | TEEC_Context *context); 153 | 154 | TEEC_EXPORT TEEC_Result TEEC_RegisterSharedMemory( 155 | TEEC_Context *context, 156 | TEEC_SharedMemory *sharedMem); 157 | 158 | TEEC_EXPORT TEEC_Result TEEC_AllocateSharedMemory( 159 | TEEC_Context *context, 160 | TEEC_SharedMemory *sharedMem); 161 | 162 | TEEC_EXPORT void TEEC_ReleaseSharedMemory ( 163 | TEEC_SharedMemory *sharedMem); 164 | 165 | TEEC_EXPORT TEEC_Result TEEC_OpenSession ( 166 | TEEC_Context *context, 167 | TEEC_Session *session, 168 | const TEEC_UUID *destination, 169 | uint32_t connectionMethod, 170 | void *connectionData, 171 | TEEC_Operation *operation, 172 | uint32_t *returnOrigin); 173 | 174 | TEEC_EXPORT void TEEC_CloseSession ( 175 | TEEC_Session *session); 176 | 177 | TEEC_EXPORT TEEC_Result TEEC_InvokeCommand( 178 | TEEC_Session *session, 179 | uint32_t commandID, 180 | TEEC_Operation *operation, 181 | uint32_t *returnOrigin); 182 | 183 | TEEC_EXPORT void TEEC_RequestCancellation( 184 | TEEC_Operation *operation); 185 | 186 | #pragma GCC visibility pop 187 | 188 | #endif /* TBASE_API_LEVEL */ 189 | 190 | #endif /* __TEE_CLIENT_API_H__ */ 191 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/public/GP/tee_client_api_imp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /* 33 | * This header file defines the implementation-dependent types, 34 | * constants and macros for all the Trusted Foundations implementations 35 | * of the TEE Client API 36 | */ 37 | #ifndef __TEE_CLIENT_API_IMP_H__ 38 | #define __TEE_CLIENT_API_IMP_H__ 39 | 40 | #if TBASE_API_LEVEL >= 3 41 | 42 | #include 43 | 44 | #include "tee_type.h" 45 | #include "tee_error.h" 46 | #include "MobiCoreDriverApi.h" 47 | 48 | 49 | typedef struct { 50 | uint32_t reserved; 51 | } 52 | TEEC_Context_IMP; 53 | 54 | 55 | typedef struct { 56 | mcSessionHandle_t handle; 57 | void *tci; 58 | bool active; 59 | pthread_mutex_t mutex_tci; //mutex to serialize CA requests 60 | } 61 | TEEC_Session_IMP; 62 | 63 | typedef struct { 64 | bool implementation_allocated; 65 | } 66 | TEEC_SharedMemory_IMP; 67 | 68 | typedef struct { 69 | TEEC_Session_IMP *session; 70 | } 71 | TEEC_Operation_IMP; 72 | 73 | /* There is no natural, compile-time limit on the shared memory, but a specific 74 | implementation may introduce a limit (in particular on TrustZone) */ 75 | #define TEEC_CONFIG_SHAREDMEM_MAX_SIZE ((size_t)0xFFFFFFFF) 76 | 77 | #define TEEC_PARAM_TYPES(entry0Type, entry1Type, entry2Type, entry3Type) \ 78 | ((entry0Type) | ((entry1Type) << 4) | ((entry2Type) << 8) | ((entry3Type) << 12)) 79 | 80 | #endif /* TBASE_API_LEVEL */ 81 | 82 | #endif /* __TEE_CLIENT_API_IMP_H__ */ 83 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/public/GP/tee_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef __TEE_ERROR_H__ 33 | #define __TEE_ERROR_H__ 34 | 35 | #define TEEC_SUCCESS ((TEEC_Result)0x00000000) 36 | 37 | /** 38 | * Generic error code : Generic error 39 | **/ 40 | #define TEEC_ERROR_GENERIC ((TEEC_Result)0xFFFF0000) 41 | 42 | /** 43 | * Generic error code : The underlying security system denies the access to the 44 | * object 45 | **/ 46 | #define TEEC_ERROR_ACCESS_DENIED ((TEEC_Result)0xFFFF0001) 47 | 48 | /** 49 | * Generic error code : The pending operation is cancelled. 50 | **/ 51 | #define TEEC_ERROR_CANCEL ((TEEC_Result)0xFFFF0002) 52 | 53 | /** 54 | * Generic error code : The underlying system detects a conflict 55 | **/ 56 | #define TEEC_ERROR_ACCESS_CONFLICT ((TEEC_Result)0xFFFF0003) 57 | 58 | /** 59 | * Generic error code : Too much data for the operation or some data remain 60 | * unprocessed by the operation. 61 | **/ 62 | #define TEEC_ERROR_EXCESS_DATA ((TEEC_Result)0xFFFF0004) 63 | 64 | /** 65 | * Generic error code : Error of data format 66 | **/ 67 | #define TEEC_ERROR_BAD_FORMAT ((TEEC_Result)0xFFFF0005) 68 | 69 | /** 70 | * Generic error code : The specified parameters are invalid 71 | **/ 72 | #define TEEC_ERROR_BAD_PARAMETERS ((TEEC_Result)0xFFFF0006) 73 | 74 | /** 75 | * Generic error code : Illegal state for the operation. 76 | **/ 77 | #define TEEC_ERROR_BAD_STATE ((TEEC_Result)0xFFFF0007) 78 | 79 | /** 80 | * Generic error code : The item is not found 81 | **/ 82 | #define TEEC_ERROR_ITEM_NOT_FOUND ((TEEC_Result)0xFFFF0008) 83 | 84 | /** 85 | * Generic error code : The specified operation is not implemented 86 | **/ 87 | #define TEEC_ERROR_NOT_IMPLEMENTED ((TEEC_Result)0xFFFF0009) 88 | 89 | /** 90 | * Generic error code : The specified operation is not supported 91 | **/ 92 | #define TEEC_ERROR_NOT_SUPPORTED ((TEEC_Result)0xFFFF000A) 93 | 94 | /** 95 | * Generic error code : Insufficient data is available for the operation. 96 | **/ 97 | #define TEEC_ERROR_NO_DATA ((TEEC_Result)0xFFFF000B) 98 | 99 | /** 100 | * Generic error code : Not enough memory to perform the operation 101 | **/ 102 | #define TEEC_ERROR_OUT_OF_MEMORY ((TEEC_Result)0xFFFF000C) 103 | 104 | /** 105 | * Generic error code : The service is currently unable to handle the request; 106 | * try later 107 | **/ 108 | #define TEEC_ERROR_BUSY ((TEEC_Result)0xFFFF000D) 109 | 110 | /** 111 | * Generic communication error 112 | **/ 113 | #define TEEC_ERROR_COMMUNICATION ((TEEC_Result)0xFFFF000E) 114 | 115 | /** 116 | * Generic error code : security violation 117 | **/ 118 | #define TEEC_ERROR_SECURITY ((TEEC_Result)0xFFFF000F) 119 | 120 | /** 121 | * Generic error code : the buffer is too short 122 | **/ 123 | #define TEEC_ERROR_SHORT_BUFFER ((TEEC_Result)0xFFFF0010) 124 | 125 | /** 126 | * Error of communication: The target of the connection is dead 127 | **/ 128 | #define TEEC_ERROR_TARGET_DEAD ((TEEC_Result)0xFFFF3024) 129 | 130 | #endif /* __TEE_ERROR_H__ */ 131 | 132 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/public/GP/tee_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Definition of the machine-specific integer types 33 | **/ 34 | #ifndef __TEE_TYPE_H__ 35 | #define __TEE_TYPE_H__ 36 | 37 | /* C99 integer types */ 38 | #if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) &&(!defined(ANDROID)) 39 | 40 | #include 41 | 42 | /* Figure out if a 64-bit integer types is available */ 43 | #if \ 44 | defined(_MSC_VER) || \ 45 | defined(__SYMBIAN32__) || \ 46 | defined(_WIN32_WCE) || \ 47 | (defined(ULLONG_MAX) && ULLONG_MAX == 0xFFFFFFFFFFFFFFFFULL) || \ 48 | (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 0xFFFFFFFFFFFFFFFFULL) 49 | typedef unsigned long long uint64_t; 50 | typedef long long int64_t; 51 | #else 52 | #define __S_TYPE_INT64_UNDEFINED 53 | #endif 54 | 55 | #if UINT_MAX == 0xFFFFFFFF 56 | typedef unsigned int uint32_t; 57 | typedef int int32_t; 58 | #elif ULONG_MAX == 0xFFFFFFFF 59 | typedef unsigned long uint32_t; 60 | typedef long int32_t; 61 | #else 62 | #error This compiler is not supported. 63 | #endif 64 | 65 | #if USHRT_MAX == 0xFFFF 66 | typedef unsigned short uint16_t; 67 | typedef short int16_t; 68 | #else 69 | #error This compiler is not supported. 70 | #endif 71 | 72 | #if UCHAR_MAX == 0xFF 73 | typedef unsigned char uint8_t; 74 | typedef signed char int8_t; 75 | #else 76 | #error This compiler is not supported. 77 | #endif 78 | 79 | #if !defined(__cplusplus) 80 | typedef unsigned char bool; 81 | #define false ( (bool)0 ) 82 | #define true ( (bool)1 ) 83 | #endif 84 | 85 | #else /* !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L */ 86 | 87 | #include 88 | #include 89 | 90 | #endif /* !(!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) */ 91 | 92 | #include 93 | 94 | #ifndef NULL 95 | # ifdef __cplusplus 96 | # define NULL 0 97 | # else 98 | # define NULL ((void *)0) 99 | # endif 100 | #endif 101 | 102 | #define IN 103 | #define OUT 104 | 105 | typedef uint32_t TEEC_Result; 106 | 107 | /** Definition of an UUID (from RFC 4122 http://www.ietf.org/rfc/rfc4122.txt) */ 108 | typedef struct TEE_UUID { 109 | uint32_t timeLow; 110 | uint16_t timeMid; 111 | uint16_t timeHiAndVersion; 112 | uint8_t clockSeqAndNode[8]; 113 | } TEE_UUID; 114 | typedef TEE_UUID TEEC_UUID; 115 | 116 | #endif /* __TEE_TYPE_H__ */ 117 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/ClientLib/public/GP/uuid_attestation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef __TEE_UUID_ATTESTATION_H__ 33 | #define __TEE_UUID_ATTESTATION_H__ 34 | 35 | #include "tee_type.h" 36 | 37 | // Sizes of the fields of attestation structure 38 | #define AT_MAGIC_SIZE 8 39 | #define AT_SIZE_SIZE sizeof(uint32_t) 40 | #define AT_VERSION_SIZE sizeof(uint32_t) 41 | #define AT_UUID_SIZE sizeof(TEE_UUID) 42 | 43 | // Sizes of the fields used to generate signature 44 | #define AT_TAG_SIZE 20 45 | #define AT_SHA1_HASH_SIZE 20 46 | 47 | // Max size of RSA modulus supported 48 | #define AT_MODULUS_MAX_SIZE 256 49 | // Max size of RSA public exponent supported 50 | #define AT_PUBLIC_EXPO_MAX_SIZE 4 51 | 52 | // Attestation version 53 | #define AT_VERSION 1 54 | 55 | // Name space ID (the UUID of the RSA OID) 56 | const uint8_t RSA_OID_UUID[AT_UUID_SIZE] = {0x6b, 0x8e, 0x02, 0x6b, 0x63, 0xc1, 0x5d, 0x58, 0xb0, 0x64, 0x00, 0xd3, 0x51, 0x89, 0xce, 0x65}; 57 | // Magic word 58 | const char MAGIC[AT_MAGIC_SIZE] = "TAUUID\0"; 59 | 60 | // Tag for signature generation 61 | const char TAG[AT_TAG_SIZE]="Trusted Application"; 62 | 63 | // Public key structure 64 | typedef struct uuid_public_key { 65 | uint32_t type; // TEE_TYPE_RSA_PUBLIC_KEY: 0xA0000030 66 | uint16_t modulus_bytes; // Length of the modulus in bytes 67 | uint16_t exponent_bytes; // Length of the exponent in bytes 68 | uint8_t data[]; // Key material 69 | } uuid_public_key; 70 | 71 | // Attestation structure 72 | typedef struct uuid_attestation { 73 | uint8_t magic[AT_MAGIC_SIZE]; // Magic word: "TAUUID\0\0" 74 | uint32_t size; // Attestation size (4 bytes) 75 | uint32_t version; // Version number: 1 (4 bytes) 76 | uint8_t uuid[AT_UUID_SIZE]; // UUID 77 | uuid_public_key key; // Public key 78 | } uuid_attestation; 79 | 80 | #endif /* __TEE_UUID_ATTESTATION_H__ */ 81 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Module: libCommon.a - classes shared by various modules 4 | # 5 | # ============================================================================= 6 | 7 | LOCAL_PATH := $(call my-dir) 8 | 9 | include $(CLEAR_VARS) 10 | 11 | LOCAL_MODULE := Common 12 | 13 | # Add new source files here 14 | #LOCAL_SRC_FILES +=\ 15 | # CMutex.cpp\ 16 | # Connection.cpp\ 17 | # NetlinkConnection.cpp\ 18 | # CSemaphore.cpp\ 19 | # CThread.cpp 20 | 21 | # Header files required by components including this module 22 | LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH) 23 | 24 | # Import logwrapper 25 | #include $(COMP_PATH_Logwrapper)/Android.mk 26 | 27 | include $(BUILD_STATIC_LIBRARY) 28 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/CMutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Mutex implementation (pthread wrapper). 33 | */ 34 | #include "CMutex.h" 35 | #include "log.h" 36 | 37 | 38 | //------------------------------------------------------------------------------ 39 | CMutex::CMutex( 40 | void 41 | ) 42 | { 43 | pthread_mutex_init(&m_mutex, NULL); 44 | pthread_cond_init(&m_cond, NULL); 45 | } 46 | 47 | 48 | //------------------------------------------------------------------------------ 49 | CMutex::~CMutex( 50 | void 51 | ) 52 | { 53 | pthread_mutex_destroy(&m_mutex); 54 | pthread_cond_destroy(&m_cond); 55 | } 56 | 57 | 58 | //------------------------------------------------------------------------------ 59 | int32_t CMutex::lock( 60 | void 61 | ) 62 | { 63 | return pthread_mutex_lock(&m_mutex); 64 | } 65 | 66 | 67 | //------------------------------------------------------------------------------ 68 | int32_t CMutex::trylock( 69 | void 70 | ) 71 | { 72 | return pthread_mutex_trylock(&m_mutex); 73 | } 74 | 75 | 76 | //------------------------------------------------------------------------------ 77 | int32_t CMutex::unlock( 78 | void 79 | ) 80 | { 81 | return pthread_mutex_unlock(&m_mutex); 82 | } 83 | 84 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/CMutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Mutex implementation (pthread wrapper). 33 | */ 34 | #ifndef CMUTEX_H_ 35 | #define CMUTEX_H_ 36 | 37 | #include 38 | #include "pthread.h" 39 | 40 | 41 | class CMutex 42 | { 43 | 44 | public: 45 | 46 | CMutex(void); 47 | 48 | ~CMutex(void); 49 | 50 | int32_t lock(void); 51 | 52 | int32_t trylock(void); 53 | 54 | int32_t unlock(void); 55 | 56 | private: 57 | 58 | pthread_mutex_t m_mutex; 59 | pthread_cond_t m_cond; 60 | 61 | }; 62 | 63 | #endif /* CMUTEX_H_ */ 64 | 65 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/CSemaphore.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Semaphore implementation (pthread wrapper). 33 | */ 34 | #include 35 | #include 36 | #include "CSemaphore.h" 37 | #include 38 | 39 | //------------------------------------------------------------------------------ 40 | CSemaphore::CSemaphore(int size) : m_waiters_count(0), m_count(size) 41 | { 42 | pthread_mutex_init(&m_mutex, NULL); 43 | pthread_cond_init(&m_cond, NULL); 44 | } 45 | 46 | 47 | //------------------------------------------------------------------------------ 48 | CSemaphore::~CSemaphore() 49 | { 50 | pthread_mutex_destroy(&m_mutex); 51 | pthread_cond_destroy(&m_cond); 52 | } 53 | 54 | 55 | //------------------------------------------------------------------------------ 56 | void CSemaphore::wait() 57 | { 58 | pthread_mutex_lock(&m_mutex); 59 | m_waiters_count ++; 60 | while ( m_count == 0 ) 61 | pthread_cond_wait(&m_cond, &m_mutex); 62 | m_waiters_count --; 63 | m_count --; 64 | pthread_mutex_unlock(&m_mutex); 65 | } 66 | 67 | //------------------------------------------------------------------------------ 68 | bool CSemaphore::wait(int sec) 69 | { 70 | int rc = 0; 71 | struct timespec tm; 72 | if (sec < 0) 73 | sec = INT_MAX; 74 | clock_gettime(CLOCK_REALTIME, &tm); 75 | tm.tv_sec += sec; 76 | 77 | pthread_mutex_lock(&m_mutex); 78 | m_waiters_count ++; 79 | if ( m_count == 0 ) { 80 | rc = pthread_cond_timedwait(&m_cond, &m_mutex, &tm); 81 | } 82 | m_waiters_count --; 83 | // Decrement only if waiting actually succeeded, otherwise we 84 | // just timed out 85 | if (!rc) 86 | m_count --; 87 | pthread_mutex_unlock(&m_mutex); 88 | return (rc == 0); 89 | } 90 | 91 | 92 | //------------------------------------------------------------------------------ 93 | bool CSemaphore::wouldWait() 94 | { 95 | bool ret = false; 96 | pthread_mutex_lock(&m_mutex); 97 | if ( m_count == 0 ) 98 | ret = true; 99 | pthread_mutex_unlock(&m_mutex); 100 | return ret; 101 | } 102 | 103 | 104 | //------------------------------------------------------------------------------ 105 | void CSemaphore::signal() 106 | { 107 | pthread_mutex_lock(&m_mutex); 108 | if ( m_waiters_count > 0 ) 109 | pthread_cond_signal(&m_cond); 110 | m_count ++; 111 | pthread_mutex_unlock(&m_mutex); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/CSemaphore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Semaphore implementation (pthread wrapper). 33 | */ 34 | #ifndef CSEMAPHORE_H_ 35 | #define CSEMAPHORE_H_ 36 | 37 | #include "pthread.h" 38 | 39 | /** 40 | * Could inherit from CMutex, or use CMutex internally. 41 | * Semaphore is a mutex with a counter. Constructor and destructor 42 | * code is the same. 43 | */ 44 | 45 | class CSemaphore 46 | { 47 | 48 | public: 49 | 50 | CSemaphore(int size = 0); 51 | 52 | ~CSemaphore(void); 53 | 54 | void wait(void); 55 | bool wait(int sec); 56 | 57 | bool wouldWait(void); 58 | 59 | void signal(void); 60 | 61 | private: 62 | 63 | pthread_mutex_t m_mutex; 64 | pthread_cond_t m_cond; 65 | int m_waiters_count; 66 | int m_count; 67 | 68 | }; 69 | 70 | #endif /*CSEMAPHORE_H_*/ 71 | 72 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/CThread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Thread implementation (pthread abstraction). 33 | */ 34 | #include "CThread.h" 35 | 36 | #include "log.h" 37 | 38 | 39 | //------------------------------------------------------------------------------ 40 | CThread::CThread(void) : 41 | m_terminate(false), m_isExiting(false) 42 | { 43 | m_sem = new CSemaphore(); 44 | m_thread=0; 45 | } 46 | 47 | //------------------------------------------------------------------------------ 48 | CThread::~CThread( 49 | void 50 | ) 51 | { 52 | delete m_sem; 53 | } 54 | 55 | 56 | //------------------------------------------------------------------------------ 57 | void CThread::terminate( 58 | void 59 | ) 60 | { 61 | m_terminate = true; 62 | } 63 | 64 | 65 | //------------------------------------------------------------------------------ 66 | bool CThread::isExiting( 67 | void 68 | ) 69 | { 70 | return m_isExiting; 71 | } 72 | 73 | 74 | //------------------------------------------------------------------------------ 75 | void CThread::setExiting( 76 | void 77 | ) 78 | { 79 | m_isExiting = true; 80 | } 81 | 82 | 83 | //------------------------------------------------------------------------------ 84 | void CThread::exit( 85 | void* exitcode 86 | ) 87 | { 88 | setExiting(); 89 | pthread_exit(exitcode); 90 | } 91 | 92 | 93 | //------------------------------------------------------------------------------ 94 | bool CThread::shouldTerminate( 95 | void 96 | ) 97 | { 98 | return m_terminate; 99 | } 100 | 101 | 102 | //------------------------------------------------------------------------------ 103 | void CThread::start( 104 | void 105 | ) 106 | { 107 | int ret; 108 | ret = pthread_create(&m_thread, NULL, CThreadStartup, this); 109 | if (0 != ret) 110 | LOG_E("pthread_create failed with error code %d", ret); 111 | } 112 | 113 | //------------------------------------------------------------------------------ 114 | void CThread::start( 115 | const char* name 116 | ) 117 | { 118 | start(); 119 | int ret = pthread_setname_np(m_thread, name); 120 | if (0 != ret) 121 | LOG_E("pthread_setname_np failed with error code %d %s", ret, name); 122 | } 123 | 124 | //------------------------------------------------------------------------------ 125 | void CThread::join( 126 | void 127 | ) 128 | { 129 | int ret; 130 | ret = pthread_join(m_thread, NULL); 131 | if (0 != ret) 132 | LOG_E("pthread_join failed with error code %d", ret); 133 | } 134 | 135 | 136 | //------------------------------------------------------------------------------ 137 | void CThread::sleep( 138 | void 139 | ) 140 | { 141 | m_sem->wait(); 142 | } 143 | 144 | 145 | //------------------------------------------------------------------------------ 146 | void CThread::wakeup( 147 | void 148 | ) 149 | { 150 | m_sem->signal(); 151 | } 152 | 153 | 154 | //------------------------------------------------------------------------------ 155 | void *CThreadStartup( 156 | void *_tgtObject 157 | ) 158 | { 159 | CThread *tgtObject = (CThread *) _tgtObject; 160 | tgtObject->run(); 161 | return NULL; 162 | } 163 | 164 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/CThread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Thread implementation (pthread abstraction). 33 | */ 34 | #ifndef CTHREAD_H_ 35 | #define CTHREAD_H_ 36 | 37 | #include 38 | #include "CSemaphore.h" 39 | #include "pthread.h" 40 | 41 | using namespace std; 42 | 43 | 44 | class CThread 45 | { 46 | 47 | public: 48 | 49 | CThread(void); 50 | 51 | virtual ~CThread(void); 52 | 53 | virtual void run(void) = 0; 54 | 55 | void start(void); 56 | 57 | void start(const char* name); 58 | 59 | void join(void); 60 | 61 | void sleep(void); 62 | 63 | void wakeup(void); 64 | 65 | void terminate(void); 66 | 67 | bool isExiting(void); 68 | 69 | void setExiting(void); 70 | 71 | protected: 72 | 73 | bool shouldTerminate(void); 74 | 75 | void exit(void* exitcode); 76 | 77 | private: 78 | 79 | CSemaphore *m_sem; 80 | pthread_t m_thread; 81 | bool m_terminate; 82 | bool m_isExiting; 83 | 84 | }; 85 | 86 | extern "C" void *CThreadStartup(void *); 87 | 88 | #endif /*CTHREAD_H_*/ 89 | 90 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/CWsm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * World shared memory definitions. 33 | */ 34 | #ifndef CWSM_H_ 35 | #define CWSM_H_ 36 | 37 | #include 38 | #include 39 | #include "McTypes.h" 40 | 41 | 42 | class CWsm 43 | { 44 | public: 45 | addr_t virtAddr; 46 | uint32_t len; 47 | uint32_t handle; 48 | uint64_t physAddr; 49 | 50 | CWsm(addr_t virtAddr, 51 | uint32_t len, 52 | uint32_t handle, 53 | // this may be unknown, so is can be omitted. 54 | uint64_t physAddr = 0x0) : 55 | virtAddr(virtAddr), 56 | len(len), 57 | handle(handle), 58 | physAddr(physAddr) 59 | { }; 60 | 61 | }; 62 | 63 | typedef CWsm *CWsm_ptr; 64 | typedef std::list wsmList_t; 65 | typedef wsmList_t::iterator wsmIterator_t; 66 | 67 | #endif /* CWSM_H_ */ 68 | 69 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/Connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Connection data. 33 | */ 34 | #ifndef CONNECTION_H_ 35 | #define CONNECTION_H_ 36 | 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | 47 | class Connection 48 | { 49 | public: 50 | struct sockaddr_un remote; /**< Remote address */ 51 | int32_t socketDescriptor; /**< Local socket descriptor */ 52 | void *connectionData; /**< reference to data related with the connection */ 53 | bool detached; /**< Connection state */ 54 | 55 | Connection(void); 56 | 57 | Connection(int socketDescriptor, sockaddr_un *remote); 58 | 59 | virtual ~Connection(void); 60 | 61 | /** 62 | * Connect to destination. 63 | * 64 | * @param Destination pointer. 65 | * @return true on success. 66 | */ 67 | virtual bool connect(const char *dest); 68 | 69 | /** 70 | * Read bytes from the connection. 71 | * 72 | * @param buffer Pointer to destination buffer. 73 | * @param len Number of bytes to read. 74 | * @param timeout Timeout in milliseconds 75 | * @return Number of bytes read. 76 | * @return -1 if select() failed (returned -1) 77 | * @return -2 if no data available, i.e. timeout 78 | */ 79 | virtual ssize_t readData(void *buffer, uint32_t len, int32_t timeout); 80 | 81 | /** 82 | * Read bytes from the connection. 83 | * 84 | * @param buffer Pointer to destination buffer. 85 | * @param len Number of bytes to read. 86 | * @return Number of bytes read. 87 | */ 88 | virtual ssize_t readData(void *buffer, uint32_t len); 89 | 90 | /** 91 | * Write bytes to the connection. 92 | * 93 | * @param buffer Pointer to source buffer. 94 | * @param len Number of bytes to read. 95 | * @return Number of bytes written. 96 | * @return -1 if written bytes not equal to len. 97 | */ 98 | virtual ssize_t writeData(void *buffer, uint32_t len); 99 | 100 | /** 101 | * Wait for data to be available. 102 | * 103 | * @param timeout Timeout in milliseconds 104 | * @return 0 if data is available 105 | * @return error code if otherwise 106 | */ 107 | virtual int waitData(int32_t timeout); 108 | 109 | /* 110 | * Checks if the socket is still connected to the daemon 111 | * 112 | * @return true if connection is still alive. 113 | */ 114 | virtual bool isConnectionAlive(void); 115 | 116 | /* 117 | * Retrieve the peer's credentials(uid, pid, gid) 118 | * 119 | * @return true if connection peers could be retrieved 120 | */ 121 | virtual bool getPeerCredentials(struct ucred &cr); 122 | 123 | }; 124 | 125 | typedef std::list connectionList_t; 126 | typedef connectionList_t::iterator connectionIterator_t; 127 | 128 | 129 | #endif /* CONNECTION_H_ */ 130 | 131 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/McTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * MobiCore types redefinition. 33 | */ 34 | #ifndef MCTYPES_H_ 35 | #define MCTYPES_H_ 36 | 37 | typedef void *addr_t; 38 | 39 | #endif /* MCTYPES_H_ */ 40 | 41 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/NOTICE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Common/NetlinkConnection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Connection data. 33 | */ 34 | #ifndef NETLINKCONNECTION_H_ 35 | #define NETLINKCONNECTION_H_ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #include "Connection.h" 47 | #include "CMutex.h" 48 | #include "CSemaphore.h" 49 | 50 | /** PID(address) of MC daemon. */ 51 | #define MC_DAEMON_PID 0xFFFFFFFF 52 | /** Maximum Netlink payload size 53 | * TODO: figure out the best value for this */ 54 | #define MAX_PAYLOAD 1024 55 | 56 | #define MC_DAEMON_NETLINK 17 57 | 58 | 59 | class NetlinkConnection; 60 | 61 | /** 62 | * Hash function for unique ID of a connection. 63 | * 64 | * @param pid Connection PID 65 | * @param seq Connection sequenceMagic 66 | * 67 | * @return Unique identifier of the connection 68 | */ 69 | uint64_t hashConnection(pid_t pid, uint32_t seq); 70 | 71 | /** Netlink connection manager interface. 72 | * This inteface has to be implemented by the handling server 73 | * to ensure connection will be removed from accounting when destroied. */ 74 | class NetlinkConnectionManager 75 | { 76 | public: 77 | virtual ~NetlinkConnectionManager() {}; 78 | /** 79 | * Retreive connection based on a unique hash. 80 | * Search the peer connections hashmap for a hash and return 81 | * the associated Connection object 82 | * 83 | * @param hash The hash to search 84 | * @return The NetlinkConnection object if found or NULL if not found 85 | */ 86 | virtual NetlinkConnection *findConnection( 87 | uint64_t hash 88 | ) = 0; 89 | 90 | /** 91 | * Insert a connection in connection lisst 92 | * Insert a new connection in the peer connections list. If there 93 | * is already such a connection 94 | * it will be overriden! 95 | * 96 | * @param hash The hash to use 97 | * @param connection The connection object to insert 98 | */ 99 | virtual void insertConnection( 100 | uint64_t hash, 101 | NetlinkConnection *connection 102 | ) = 0; 103 | 104 | /** 105 | * Remove a connection from the peer connections 106 | * Remove the connection associated with seq from the peer list. 107 | * This doesn't actually free the connection object! 108 | * If the hash is invalid nothing happens. 109 | * 110 | * @param hash The hash hash use 111 | */ 112 | virtual void removeConnection( 113 | uint64_t hash 114 | ) = 0; 115 | }; 116 | 117 | class NetlinkConnection: public Connection 118 | { 119 | public: 120 | pid_t selfPid; /**< Which PID to use to identify when writing data */ 121 | pid_t peerPid; /**< Destination PID for sending data */ 122 | uint32_t sequenceMagic; /**< Random? magic to match requests/answers */ 123 | uint64_t hash; /**< Unique connection ID, see hashConnection */ 124 | 125 | NetlinkConnection( 126 | void 127 | ); 128 | 129 | /** 130 | * Connection main constructor 131 | * 132 | * @param manager Connection manager pointer. 133 | * @param socketDescriptor Socket descriptor to use for writing 134 | * @param pid Connection PID 135 | * @param seq Connection sequence magic number 136 | */ 137 | NetlinkConnection( 138 | NetlinkConnectionManager *manager, 139 | int socketDescriptor, 140 | uint32_t pid, 141 | uint32_t seq 142 | ); 143 | 144 | virtual ~NetlinkConnection( 145 | void 146 | ); 147 | 148 | /** 149 | * Connect to destination. 150 | * 151 | * @param Destination pointer. 152 | * @return true on success. 153 | */ 154 | virtual bool connect( 155 | const char *dest 156 | ); 157 | 158 | /** 159 | * Read bytes from the connection(compatiblity method). 160 | * 161 | * @param buffer Pointer to destination buffer. 162 | * @param len Number of bytes to read. 163 | * @param timeout Timeout in milliseconds(ignored) 164 | * @return Number of bytes read. 165 | * @return -1 if select() failed (returned -1) 166 | * @return -2 if no data available, i.e. timeout 167 | */ 168 | virtual ssize_t readData( 169 | void *buffer, 170 | uint32_t len, 171 | int32_t timeout 172 | ); 173 | 174 | /** 175 | * Read bytes from the connection. 176 | * 177 | * @param buffer Pointer to destination buffer. 178 | * @param len Number of bytes to read. 179 | * @return Number of bytes read. 180 | */ 181 | virtual ssize_t readData( 182 | void *buffer, 183 | uint32_t len 184 | ); 185 | 186 | /** 187 | * Write bytes to the connection. 188 | * 189 | * @param buffer Pointer to source buffer. 190 | * @param len Number of bytes to read. 191 | * @return Number of bytes written. 192 | */ 193 | virtual ssize_t writeData( 194 | void *buffer, 195 | uint32_t len 196 | ); 197 | 198 | /** 199 | * Set the internal data connection. 200 | * This method is called by the 201 | * 202 | * @param nlh Netlink structure pointing to data. 203 | */ 204 | void handleMessage( 205 | struct nlmsghdr *nlh 206 | ); 207 | 208 | private: 209 | CMutex dataMutex; 210 | CSemaphore dataLeft; 211 | struct nlmsghdr *dataMsg; /**< Last message received */ 212 | uint32_t dataLen; /**< How much connection data is left */ 213 | uint8_t *dataStart; /**< Start pointer of remaining data */ 214 | NetlinkConnectionManager *manager; /**< Netlink connection manager(eg. NetlinkServer) */ 215 | }; 216 | 217 | typedef std::map connectionMap_t; 218 | 219 | #endif /* NETLINKCONNECTION_H_ */ 220 | 221 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Module: mcDriverDaemon 4 | # 5 | # ============================================================================= 6 | 7 | # Add new source files here 8 | LOCAL_SRC_FILES += Daemon/MobiCoreDriverDaemon.cpp 9 | 10 | # Includes required for the Daemon 11 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/Daemon/public \ 12 | 13 | # Internal components 14 | include $(LOCAL_PATH)/Daemon/Device/Android.mk 15 | include $(LOCAL_PATH)/Daemon/Server/Android.mk 16 | include $(LOCAL_PATH)/Daemon/FSD/Android.mk 17 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # MC driver device files 4 | # 5 | # ============================================================================= 6 | 7 | # This is not a separate module. 8 | # Only for inclusion by other modules. 9 | # All paths are relative to APP_PROJECT_PATH 10 | 11 | DEVICE_PATH := Daemon/Device 12 | include $(LOCAL_PATH)/$(DEVICE_PATH)/Platforms/Android.mk 13 | 14 | # Add new folders with header files here 15 | # Include paths are absolute paths 16 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(DEVICE_PATH) \ 17 | $(LOCAL_PATH)/$(DEVICE_PATH)/public 18 | 19 | # Add new source files here 20 | LOCAL_SRC_FILES += $(DEVICE_PATH)/DeviceIrqHandler.cpp \ 21 | $(DEVICE_PATH)/DeviceScheduler.cpp \ 22 | $(DEVICE_PATH)/TAExitHandler.cpp \ 23 | $(DEVICE_PATH)/MobiCoreDevice.cpp \ 24 | $(DEVICE_PATH)/NotificationQueue.cpp \ 25 | $(DEVICE_PATH)/TrustletSession.cpp \ 26 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/DeviceIrqHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include "DeviceIrqHandler.h" 32 | #include "log.h" 33 | 34 | //------------------------------------------------------------------------------ 35 | void DeviceIrqHandler::run( 36 | void 37 | ) 38 | { 39 | handleIrq(); 40 | this->exit((void*)-1); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/DeviceIrqHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * IRQ handler thread. 33 | */ 34 | 35 | #ifndef DEVICEIRQHANDLER_H_ 36 | #define DEVICEIRQHANDLER_H_ 37 | 38 | #include "CThread.h" 39 | 40 | 41 | class DeviceIrqHandler: public CThread 42 | { 43 | 44 | public: 45 | 46 | virtual void handleIrq() = 0; 47 | 48 | void run(); 49 | }; 50 | 51 | #endif /* DEVICEIRQHANDLER_H_ */ 52 | 53 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/DeviceScheduler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include "DeviceScheduler.h" 32 | 33 | 34 | //------------------------------------------------------------------------------ 35 | void DeviceScheduler::run( 36 | void 37 | ) 38 | { 39 | schedule(); 40 | exit((void*)-1); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/DeviceScheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Scheduler thread 33 | */ 34 | #ifndef DEVICESCHEDULER_H_ 35 | #define DEVICESCHEDULER_H_ 36 | 37 | #include "CThread.h" 38 | 39 | 40 | class DeviceScheduler: public CThread 41 | { 42 | 43 | public: 44 | 45 | virtual void schedule() = 0; 46 | 47 | void run(); 48 | 49 | }; 50 | 51 | #endif /* DEVICESCHEDULER_H_ */ 52 | 53 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/NotificationQueue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include "NotificationQueue.h" 32 | #include 33 | 34 | #include "log.h" 35 | 36 | //------------------------------------------------------------------------------ 37 | NotificationQueue::NotificationQueue( 38 | notificationQueue_t *i, 39 | notificationQueue_t *o, 40 | uint32_t size 41 | ) : in(i), out(o) 42 | { 43 | in->hdr.queueSize = size; 44 | out->hdr.queueSize = size; 45 | } 46 | 47 | 48 | //------------------------------------------------------------------------------ 49 | void NotificationQueue::putNotification( 50 | notification_t *notification 51 | ) 52 | { 53 | mutex.lock(); 54 | if ((out->hdr.writeCnt - out->hdr.readCnt) < out->hdr.queueSize) { 55 | out->notification[out->hdr.writeCnt & (out->hdr.queueSize - 1)] 56 | = *notification; 57 | out->hdr.writeCnt++; 58 | } 59 | mutex.unlock(); 60 | } 61 | 62 | 63 | //------------------------------------------------------------------------------ 64 | notification_t *NotificationQueue::getNotification( 65 | void 66 | ) 67 | { 68 | notification_t *ret = NULL; 69 | mutex.lock(); 70 | if ((in->hdr.writeCnt - in->hdr.readCnt) > 0) { 71 | ret = &(in->notification[in->hdr.readCnt & (in->hdr.queueSize - 1)]); 72 | in->hdr.readCnt++; 73 | } 74 | mutex.unlock(); 75 | return ret; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/NotificationQueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * MobiCore Notification Queue handling. 33 | */ 34 | #ifndef NOTIFICATIONQUEUE_H_ 35 | #define NOTIFICATIONQUEUE_H_ 36 | 37 | #include //C99 data 38 | #include "Mci/mcinq.h" 39 | #include "CMutex.h" 40 | 41 | 42 | class NotificationQueue 43 | { 44 | 45 | public: 46 | 47 | /** NQ Constructor, initializes the NQ component. 48 | * 49 | * makes the given queue object usable with the queue type of functions 50 | * 51 | * @param in queue to initialize 52 | * @param out beginning of queue header 53 | * @param queueSize Size of the queue 54 | */ 55 | NotificationQueue( 56 | notificationQueue_t *in, 57 | notificationQueue_t *out, 58 | uint32_t size 59 | ); 60 | 61 | /** Places an element to the outgoing queue. 62 | * 63 | * @param notification Data to be placed in queue. 64 | */ 65 | void putNotification( 66 | notification_t *notification 67 | ); 68 | 69 | /** Retrieves the first element from the queue. 70 | * 71 | * @return first notification Queue element. 72 | * @return NULL if the queue is empty. 73 | */ 74 | notification_t *getNotification( 75 | void 76 | ); 77 | 78 | private: 79 | 80 | notificationQueue_t *in; 81 | notificationQueue_t *out; 82 | CMutex mutex; 83 | 84 | }; 85 | 86 | #endif /* NOTIFICATIONQUEUE_H_ */ 87 | 88 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/Platforms/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Makefile pointing to the platform specific makefile. 4 | # 5 | # ============================================================================= 6 | 7 | PLATFORMS_PATH := $(LOCAL_PATH)/Daemon/Device/Platforms 8 | 9 | # Always include the Generic code 10 | include $(PLATFORMS_PATH)/Generic/Android.mk 11 | 12 | ifneq ($(filter-out Generic,$(PLATFORM)),) 13 | $(info PLATFORM: $(PLATFORM)) 14 | include $(PLATFORMS_PATH)/$(PLATFORM)/Android.mk 15 | endif 16 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/Platforms/Generic/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Generic TrustZone device includes 4 | # 5 | # ============================================================================= 6 | 7 | # This is not a separate module. 8 | # Only for inclusion by other modules. 9 | 10 | GENERIC_PATH := Daemon/Device/Platforms/Generic 11 | 12 | # Add new source files here 13 | LOCAL_SRC_FILES += $(GENERIC_PATH)/TrustZoneDevice.cpp 14 | 15 | # Header files for components including this module 16 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(GENERIC_PATH) 17 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/Platforms/Generic/TrustZoneDevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Class for TrustZone Devices. 33 | * TrustZone device implements communication functions needed for 34 | * accessing MobiCore located in an TrustZone environment. 35 | */ 36 | #ifndef TRUSTZONEDEVICE_H_ 37 | #define TRUSTZONEDEVICE_H_ 38 | 39 | 40 | #include 41 | 42 | #include "McTypes.h" 43 | 44 | #include "CSemaphore.h" 45 | #include "CMcKMod.h" 46 | #include "CWsm.h" 47 | 48 | #include "MobiCoreDevice.h" 49 | 50 | 51 | #define SCHEDULING_FREQ 5 /**< N-SIQ every n-th time */ 52 | 53 | #define MS_PER_S 1000 /**< Milliseconds per second */ 54 | #define US_PER_MS 1000 /**< Microseconds per millisecond */ 55 | 56 | class TrustZoneDevice : public MobiCoreDevice 57 | { 58 | 59 | protected: 60 | bool schedulerEnabled; /**< NQ IRQ Scheduler enabling */ 61 | CMcKMod_ptr pMcKMod; /**< kernel module */ 62 | CWsm_ptr pWsmMcp; /**< WSM use for MCP */ 63 | CWsm_ptr mobicoreInDDR; /**< WSM used for Mobicore binary */ 64 | 65 | /** Access functions to the MC Linux kernel module 66 | */ 67 | bool yield(void); 68 | 69 | bool nsiq(void); 70 | 71 | bool waitSsiq(void); 72 | 73 | public: 74 | 75 | TrustZoneDevice(void); 76 | 77 | virtual ~TrustZoneDevice(void); 78 | 79 | // static MobiCoreDevice* getDeviceInstance( 80 | // void 81 | // ); 82 | /** Set up MCI and wait till MC is initialized 83 | * 84 | * @param devFile the device node to speak to. 85 | * @param loadMobiCore 86 | * @param mobicoreImage 87 | * @param enableScheduler 88 | * 89 | * @return true if mobicore is initialized 90 | * @trows ExcDevice 91 | */ 92 | bool initDevice( 93 | const char *devFile, 94 | bool enableScheduler 95 | ); 96 | 97 | void initDeviceStep2(void); 98 | 99 | void notify(uint32_t sessionId); 100 | 101 | void dumpMobicoreStatus(void); 102 | 103 | uint32_t getMobicoreStatus(void); 104 | 105 | bool checkMciVersion(void); 106 | 107 | /** Memory allocation functions */ 108 | bool getMciInstance(uint32_t len, CWsm_ptr *mci, bool *reused); 109 | 110 | //bool freeWsm(CWsm_ptr pWsm); 111 | 112 | CWsm_ptr registerWsmL2(addr_t buffer, uint32_t len, uint32_t pid); 113 | 114 | /* pWsm is freed even in case of error */ 115 | bool unregisterWsmL2(CWsm_ptr pWsm); 116 | 117 | bool lockWsmL2(uint32_t handle); 118 | 119 | bool unlockWsmL2(uint32_t handle); 120 | 121 | uint64_t findWsmL2(uint32_t handle, int fd); 122 | 123 | bool findContiguousWsm(uint32_t handle, int fd, uint64_t *phys, uint32_t *len); 124 | 125 | /** 126 | * Allocates persistent WSM memory for TL (won't be fried when TLC exits). 127 | */ 128 | CWsm_ptr allocateContiguousPersistentWsm(uint32_t len); 129 | 130 | bool setupLog(void); 131 | 132 | bool schedulerAvailable(void); 133 | 134 | void schedule(void); 135 | 136 | void handleIrq(void); 137 | 138 | void handleTaExit(void); 139 | }; 140 | 141 | #endif /* TRUSTZONEDEVICE_H_ */ 142 | 143 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/TAExitHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include "TAExitHandler.h" 32 | #include "log.h" 33 | 34 | //------------------------------------------------------------------------------ 35 | void TAExitHandler::run( 36 | void 37 | ) 38 | { 39 | handleTaExit(); 40 | this->exit((void*)-1); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/TAExitHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef _TAEXITHANDLER_H_ 32 | #define _TAEXITHANDLER_H_ 33 | 34 | #include "CThread.h" 35 | #include "CMutex.h" 36 | #include "TrustletSession.h" 37 | 38 | 39 | class TAExitHandler: public CThread 40 | { 41 | public: 42 | virtual void handleTaExit() = 0; 43 | 44 | void run(); 45 | }; 46 | 47 | #endif /* TAEXITHANDLER_H_ */ 48 | 49 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/TrustletSession.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include "TrustletSession.h" 32 | #include 33 | 34 | #include "log.h" 35 | 36 | using namespace std; 37 | 38 | //------------------------------------------------------------------------------ 39 | TrustletSession::TrustletSession(Connection *deviceConnection, uint32_t sessionId) 40 | { 41 | this->deviceConnection = deviceConnection; 42 | this->notificationConnection = NULL; 43 | this->sessionId = sessionId; 44 | sessionMagic = rand(); 45 | this->gp_level=0; 46 | this->sessionState=TS_TA_RUNNING; 47 | } 48 | 49 | 50 | //------------------------------------------------------------------------------ 51 | TrustletSession::~TrustletSession(void) 52 | { 53 | map::iterator it; 54 | delete notificationConnection; 55 | 56 | if (!buffers.empty()) { 57 | LOG_W("%s: Mapped buffers still available %zu", __func__, buffers.size()); 58 | } 59 | for ( it = buffers.begin() ; it != buffers.end(); it++ ) 60 | delete (*it).second; 61 | 62 | buffers.clear(); 63 | } 64 | 65 | //------------------------------------------------------------------------------ 66 | void TrustletSession::queueNotification(notification_t *notification) 67 | { 68 | if (sessionState == TS_TA_DEAD) { 69 | return; 70 | } 71 | if ((gp_level == 1) && (notification->payload != 0)) { 72 | LOG_I(" Mark session %03x dead", sessionId); 73 | sessionState = TS_TA_DEAD; 74 | } 75 | // Note this is a very subtle synchronization requirement: 76 | // The TrustletSession object is manipulated by several threads 77 | // If the sessionState is set to closed, 78 | // it means another thread could soon delete the object 79 | // Also in this case we don't care about any notifications anymore 80 | if (sessionState == TS_CLOSE_SEND) { 81 | return; 82 | } 83 | 84 | notifications.push(*notification); 85 | } 86 | 87 | //------------------------------------------------------------------------------ 88 | void TrustletSession::processQueuedNotifications(void) 89 | { 90 | LOG_I(" %s:%i", __FILE__, __LINE__ ); 91 | 92 | // Nothing to do here! 93 | if (notificationConnection == NULL) 94 | return; 95 | 96 | while (!notifications.empty()) { 97 | // Forward session ID and additional payload of 98 | // notification to the just established connection 99 | notificationConnection->writeData((void *)¬ifications.front(), 100 | sizeof(notification_t)); 101 | notifications.pop(); 102 | } 103 | } 104 | 105 | //------------------------------------------------------------------------------ 106 | bool TrustletSession::addBulkBuff(CWsm_ptr pWsm) 107 | { 108 | if (!pWsm) 109 | return false; 110 | if (buffers.find(pWsm->handle) != buffers.end()) { 111 | delete pWsm; 112 | return false; 113 | } 114 | buffers[pWsm->handle] = pWsm; 115 | return true; 116 | } 117 | 118 | //------------------------------------------------------------------------------ 119 | bool TrustletSession::removeBulkBuff(uint32_t handle) 120 | { 121 | if (buffers.find(handle) == buffers.end()) { 122 | return false; 123 | } 124 | CWsm_ptr pWsm = buffers[handle]; 125 | delete pWsm; 126 | buffers.erase(handle); 127 | return true; 128 | } 129 | 130 | //------------------------------------------------------------------------------ 131 | bool TrustletSession::findBulkBuff(uint32_t handle, uint32_t lenBulkMem) 132 | { 133 | if (buffers.find(handle) == buffers.end()) { 134 | return false; 135 | } 136 | CWsm_ptr pWsm = buffers[handle]; 137 | if ((uint32_t)pWsm->len != lenBulkMem) { 138 | return false; 139 | } 140 | 141 | return true; 142 | } 143 | 144 | //------------------------------------------------------------------------------ 145 | CWsm_ptr TrustletSession::popBulkBuff() 146 | { 147 | if (buffers.empty()) { 148 | return NULL; 149 | } 150 | 151 | CWsm_ptr pWsm = buffers.begin()->second; 152 | // Remove it from the map 153 | buffers.erase(pWsm->handle); 154 | return pWsm; 155 | } 156 | 157 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Device/TrustletSession.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef TRUSTLETSESSION_H_ 32 | #define TRUSTLETSESSION_H_ 33 | 34 | #include "NotificationQueue.h" 35 | #include "CWsm.h" 36 | #include "Connection.h" 37 | #include 38 | #include 39 | 40 | 41 | class TrustletSession 42 | { 43 | private: 44 | std::queue notifications; 45 | std::map buffers; 46 | 47 | public: 48 | uint32_t sessionId; // Assigned by t-base 49 | uint32_t sessionMagic; // Random data 50 | Connection *deviceConnection; // Command socket for client "device" 51 | Connection *notificationConnection; // Notification socket for client session 52 | uint32_t gp_level; 53 | enum TS_STATE { 54 | TS_TA_RUNNING,//->dead,close_send 55 | TS_TA_DEAD, //->close_send, closed 56 | TS_CLOSE_SEND,//->close_send, dead, closed 57 | TS_CLOSED,//unused 58 | } sessionState; 59 | 60 | TrustletSession(Connection *deviceConnection, uint32_t sessionId); 61 | 62 | ~TrustletSession(void); 63 | 64 | void queueNotification(notification_t *notification); 65 | 66 | void processQueuedNotifications(void); 67 | 68 | bool addBulkBuff(CWsm_ptr pWsm); 69 | 70 | bool removeBulkBuff(uint32_t handle); 71 | 72 | bool findBulkBuff(uint32_t handle, uint32_t lenBulkMem); 73 | 74 | CWsm_ptr popBulkBuff(); 75 | 76 | }; 77 | 78 | typedef std::list trustletSessionList_t; 79 | typedef trustletSessionList_t::iterator trustletSessionIterator_t; 80 | 81 | #endif /* TRUSTLETSESSION_H_ */ 82 | 83 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/FSD/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # MC driver server files 4 | # 5 | # ============================================================================= 6 | 7 | # This is not a separate module. 8 | # Only for inclusion by other modules. 9 | 10 | FSD_PATH := Daemon/FSD 11 | 12 | # Add new folders with header files here 13 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(FSD_PATH)/public \ 14 | $(LOCAL_PATH)/ClientLib/public/GP \ 15 | 16 | # Add new source files here 17 | LOCAL_SRC_FILES += $(FSD_PATH)/FSD.cpp \ -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/FSD/public/FSD.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * FSD server. 33 | * 34 | * Handles incoming storage requests from TA through STH 35 | */ 36 | #ifndef FSD_H_ 37 | #define FSD_H_ 38 | 39 | #include 40 | #include 41 | #include 42 | #include "CThread.h" 43 | #include "MobiCoreDriverApi.h" 44 | #include "drSecureStorage_Api.h" 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | 52 | #define max( a, b ) ( ((a) > (b)) ? (a) : (b) ) 53 | #define DCI_BUFF_SIZE 1000*1024 54 | 55 | #define TEE_UUID_STRING_SIZE 32 56 | #define FILENAMESIZE 20 57 | #define NEW_EXT ".new" 58 | 59 | #define TAG_LOG "FSD" 60 | 61 | class FSD: public CThread 62 | { 63 | 64 | public: 65 | /** 66 | * FSD contructor. 67 | * 68 | * @param tbstoragepath Absolute path to the secure storage 69 | */ 70 | FSD( 71 | void 72 | ); 73 | 74 | /** 75 | * FSD destructor. 76 | * Close the current session and resources will be freed. 77 | */ 78 | virtual ~FSD( 79 | void 80 | ); 81 | 82 | /** 83 | * Start server and listen for incoming request from STH. 84 | */ 85 | virtual void run(void); 86 | 87 | /* 88 | * FSD_Open 89 | * 90 | * Open a session with the STH 91 | * 92 | */ 93 | virtual mcResult_t FSD_Open(void); 94 | 95 | 96 | /* 97 | * FSD_Close 98 | * 99 | * Close a session opened with the STH 100 | * 101 | */ 102 | virtual mcResult_t FSD_Close(void); 103 | 104 | 105 | /* 106 | * FSD_listenDci 107 | * 108 | * DCI listener function 109 | * 110 | */ 111 | virtual void FSD_listenDci(void); 112 | 113 | 114 | 115 | private: 116 | mcSessionHandle_t sessionHandle; /**< current session */ 117 | dciMessage_t* dci; /**< dci buffer */ 118 | 119 | 120 | /** Private methods*/ 121 | 122 | /* 123 | * FSD_ExecuteCommand 124 | * 125 | * Execute command received from the STH 126 | * 127 | */ 128 | mcResult_t FSD_ExecuteCommand(void); 129 | 130 | /**************************** File operations *******************************/ 131 | 132 | /* 133 | * FSD_LookFile 134 | * 135 | * look for a file 136 | */ 137 | mcResult_t FSD_LookFile(void); 138 | 139 | 140 | /* 141 | * FSD_ReadFile 142 | * 143 | * Read a file 144 | */ 145 | mcResult_t FSD_ReadFile(void); 146 | 147 | 148 | /* 149 | * FSD_WriteFile 150 | * 151 | * Write a file 152 | */ 153 | mcResult_t FSD_WriteFile(void); 154 | 155 | 156 | /* 157 | * FSD_DeleteFile 158 | * 159 | * Delete a file 160 | */ 161 | mcResult_t FSD_DeleteFile(void); 162 | 163 | /** 164 | * FSD_DeleteDir() 165 | * 166 | * Deletes a TA directory and all files belonigng to that DIR 167 | * Note, this is a restricted function only available to a TA with the 168 | * required capability 169 | */ 170 | mcResult_t FSD_DeleteDir(void); 171 | 172 | }; 173 | 174 | #endif /* FSD_H_ */ 175 | 176 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/FSD/public/dci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * @file dci.h 34 | * @brief Contains DCI (Driver Control 35 | * Interface) definitions and data structures 36 | * 37 | */ 38 | 39 | #ifndef __DCI_H__ 40 | #define __DCI_H__ 41 | 42 | 43 | typedef uint32_t dciCommandId_t; 44 | typedef uint32_t dciResponseId_t; 45 | typedef uint32_t dciReturnCode_t; 46 | 47 | /**< Responses have bit 31 set */ 48 | #define RSP_ID_MASK (1U << 31) 49 | #define RSP_ID(cmdId) (((uint32_t)(cmdId)) | RSP_ID_MASK) 50 | #define IS_CMD(cmdId) ((((uint32_t)(cmdId)) & RSP_ID_MASK) == 0) 51 | #define IS_RSP(cmdId) ((((uint32_t)(cmdId)) & RSP_ID_MASK) == RSP_ID_MASK) 52 | 53 | /** 54 | * Return codes of driver commands. 55 | */ 56 | #define RET_OK 0 57 | #define RET_ERR_UNKNOWN_CMD 1 58 | #define RET_ERR_NOT_SUPPORTED 2 59 | #define RET_ERR_INTERNAL_ERROR 3 60 | /* ... add more error codes when needed */ 61 | 62 | /** 63 | * DCI command header. 64 | */ 65 | typedef struct{ 66 | dciCommandId_t commandId; /**< Command ID */ 67 | } dciCommandHeader_t; 68 | 69 | /** 70 | * DCI response header. 71 | */ 72 | typedef struct{ 73 | dciResponseId_t responseId; /**< Response ID (must be command ID | RSP_ID_MASK )*/ 74 | dciReturnCode_t returnCode; /**< Return code of command */ 75 | } dciResponseHeader_t; 76 | 77 | #endif // __DCI_H__ 78 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/FSD/public/drSecureStorage_Api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * @file drSecureStorage_Api.h 34 | * @brief Contains DCI command definitions and data structures 35 | * 36 | */ 37 | 38 | #ifndef __DRTEMPLATEAPI_H__ 39 | #define __DRTEMPLATEAPI_H__ 40 | 41 | #include "dci.h" 42 | #include "tee_type.h" 43 | #include "tee_error.h" 44 | 45 | #define RW_DATA_SIZE 4096 46 | 47 | /** 48 | * Command ID's for communication 49 | * FSD <--> STH 50 | */ 51 | 52 | #define STH_MESSAGE_TYPE_LOOK 0 53 | #define STH_MESSAGE_TYPE_READ 1 54 | #define STH_MESSAGE_TYPE_WRITE 2 55 | #define STH_MESSAGE_TYPE_DELETE 3 56 | #define STH_MESSAGE_TYPE_DELETE_ALL 4 57 | 58 | #define CMD_ST_SYNC 5 59 | #define NOTIFY_DCIH 6 60 | #define NOTIFY_IPCH 7 61 | /*... add more command ids when needed */ 62 | 63 | #define STH_PUBLIC_FILE_NAME_SIZE 20 64 | 65 | typedef struct { 66 | uint32_t status; 67 | uint8_t type; 68 | uint8_t reserved0; 69 | uint16_t flags; 70 | uint32_t payloadLen; 71 | TEE_UUID uuid; 72 | unsigned char filename[STH_PUBLIC_FILE_NAME_SIZE]; 73 | unsigned char payload[]; 74 | } STH_FSD_message_t; 75 | 76 | typedef struct 77 | { 78 | char header[5]; 79 | unsigned char version; 80 | uint16_t cryptoLen; 81 | uint32_t dataLen; 82 | }FSD_plaintext; 83 | 84 | /** 85 | * command message. 86 | * 87 | * @param len Lenght of the data to process. 88 | * @param data Data to be processed 89 | */ 90 | typedef struct { 91 | dciCommandHeader_t header; /**< Command header */ 92 | uint32_t len; /**< Length of data to process */ 93 | } cmd_t; 94 | 95 | 96 | /** 97 | * Response structure 98 | */ 99 | typedef struct { 100 | dciResponseHeader_t header; /**< Response header */ 101 | uint32_t len; 102 | } rsp_t; 103 | 104 | /** 105 | * DCI message data. 106 | */ 107 | typedef struct { 108 | union { 109 | cmd_t command; 110 | rsp_t response; 111 | }; 112 | 113 | STH_FSD_message_t sth_request; 114 | } dciMessage_t; 115 | 116 | /** 117 | * Driver UUID. Update accordingly after reserving UUID 118 | */ 119 | #define DRV_STH_UUID { { 0x07, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } 120 | 121 | 122 | #endif // __DRTEMPLATEAPI_H__ 123 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Server/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # MC driver server files 4 | # 5 | # ============================================================================= 6 | 7 | # This is not a separate module. 8 | # Only for inclusion by other modules. 9 | 10 | SERVER_PATH := Daemon/Server 11 | 12 | # Add new folders with header files here 13 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SERVER_PATH)/public 14 | 15 | # Add new source files here 16 | LOCAL_SRC_FILES += $(SERVER_PATH)/Server.cpp \ 17 | $(SERVER_PATH)/NetlinkServer.cpp 18 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Server/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef CLIENT_H_ 33 | #define CLIENT_H_ 34 | 35 | #include "pthread.h" 36 | 37 | #include "Queue.h" 38 | #include "Connection.h" 39 | #include "MobiCoreDriverCmd.h" 40 | 41 | class Client: public CThread { 42 | Queue& queue_; 43 | ConnectionHandler* handler_; 44 | Connection* connection_; 45 | pthread_mutex_t mutex_; 46 | pthread_cond_t condition_; 47 | uint32_t command_id_; 48 | bool locked_; 49 | bool dead_; 50 | public: 51 | Client(ConnectionHandler* handler, int sock, struct sockaddr_un* sockaddr, Queue& queue): 52 | queue_(queue), handler_(handler), command_id_(0), locked_(false), dead_(false) { 53 | connection_ = new Connection(sock, sockaddr); 54 | pthread_mutex_init(&mutex_, NULL); 55 | pthread_cond_init(&condition_, NULL); 56 | } 57 | ~Client() { 58 | delete connection_; 59 | pthread_mutex_destroy(&mutex_); 60 | pthread_cond_destroy(&condition_); 61 | } 62 | Connection* connection() { 63 | return connection_; 64 | } 65 | uint32_t commandId() const { 66 | return command_id_; 67 | } 68 | bool isDead() const { 69 | return dead_; 70 | } 71 | // Safe because called on command MC_DRV_CMD_NQ_CONNECT so thread is locked waiting for command to be treated 72 | void detachConnection() { 73 | connection_ = NULL; 74 | } 75 | bool isDetached() const { 76 | return connection_ == NULL; 77 | } 78 | void dropConnection() { 79 | LOG_I("Client: %p shutting down due to error", this); 80 | handler_->dropConnection(connection_); 81 | } 82 | void unlock() { 83 | pthread_mutex_lock(&mutex_); 84 | locked_ = false; 85 | pthread_cond_signal(&condition_); 86 | pthread_mutex_unlock(&mutex_); 87 | } 88 | void run() { 89 | while (!dead_) { 90 | if (!connection_ || !handler_->readCommand(connection_, &command_id_)) { 91 | dead_ = true; 92 | } else if (command_id_ == MC_DRV_CMD_NOTIFY) { 93 | // Notification: send immediately 94 | handler_->handleCommand(connection_, command_id_); 95 | continue; 96 | } 97 | // Standard command or needs dropping: queue 98 | pthread_mutex_lock(&mutex_); 99 | queue_.push(this); 100 | locked_ = true; 101 | while (locked_) { 102 | pthread_cond_wait(&condition_, &mutex_); 103 | } 104 | pthread_mutex_unlock(&mutex_); 105 | } 106 | } 107 | }; 108 | 109 | #endif /* CLIENT_H_ */ 110 | 111 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Server/Queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef QUEUE_H_ 33 | #define QUEUE_H_ 34 | 35 | #include "pthread.h" 36 | 37 | template 38 | class Queue { 39 | std::list queue_; 40 | pthread_mutex_t mutex_; 41 | pthread_cond_t condition_; 42 | public: 43 | Queue() { 44 | pthread_mutex_init(&mutex_, NULL); 45 | pthread_cond_init(&condition_, NULL); 46 | } 47 | ~Queue() { 48 | pthread_mutex_destroy(&mutex_); 49 | pthread_cond_destroy(&condition_); 50 | } 51 | void push(T data) { 52 | pthread_mutex_lock(&mutex_); 53 | queue_.push_back(data); 54 | pthread_cond_signal(&condition_); 55 | pthread_mutex_unlock(&mutex_); 56 | } 57 | T pop() { 58 | pthread_mutex_lock(&mutex_); 59 | while (queue_.empty()) { 60 | pthread_cond_wait(&condition_, &mutex_); 61 | } 62 | T data = queue_.front(); 63 | queue_.pop_front(); 64 | pthread_mutex_unlock(&mutex_); 65 | return data; 66 | } 67 | }; 68 | 69 | #endif /* QUEUE_H_ */ 70 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Server/public/ConnectionHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Interface for connection handlers used by Server. 33 | */ 34 | #ifndef CONNECTIONHANDLER_H_ 35 | #define CONNECTIONHANDLER_H_ 36 | 37 | #include "Connection.h" 38 | 39 | 40 | class ConnectionHandler 41 | { 42 | 43 | public: 44 | virtual ~ConnectionHandler() {}; 45 | virtual bool readCommand(Connection *connection, uint32_t *command_id) = 0; 46 | virtual void handleCommand(Connection *connection, uint32_t command_id) = 0; 47 | 48 | /** 49 | * Handle connection activities. 50 | * The connection handler shall process pending connection activities. 51 | * 52 | * @param [in] connection Reference to the connection which has data to process. 53 | */ 54 | bool handleConnection(Connection *connection) { 55 | uint32_t command_id; 56 | if (!readCommand(connection, &command_id)) { 57 | return false; 58 | } 59 | handleCommand(connection, command_id); 60 | return true; 61 | } 62 | 63 | /** 64 | * Connection has been closed. 65 | * The connection handler shall clean up all resources associated with the given connection. 66 | * After the method has been executed the connection object will be deleted. 67 | * 68 | * @param [in] connection Reference to the connection which will be deleted. 69 | */ 70 | virtual void dropConnection(Connection *connection) = 0; 71 | }; 72 | 73 | #endif /* CONNECTIONHANDLER_H_ */ 74 | 75 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Server/public/NetlinkServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Connection server. 33 | * 34 | * Handles incoming socket connections from clients using the MobiCore driver. 35 | * 36 | * Iterative socket server using Netlink dgram protocol. 37 | */ 38 | #ifndef NETLINKSERVER_H_ 39 | #define NETLINKSERVER_H_ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "NetlinkConnection.h" 49 | #include "ConnectionHandler.h" 50 | #include "Server.h" 51 | 52 | class NetlinkServer: public Server, public NetlinkConnectionManager 53 | { 54 | public: 55 | /** 56 | * Server contructor. 57 | * 58 | * @param connectionHanler Connection handler to pass incoming connections to. 59 | */ 60 | NetlinkServer( 61 | ConnectionHandler *connectionHandler 62 | ); 63 | 64 | /** 65 | * Server destructor. 66 | * All available connections will be terminated. Resources will be freed. 67 | */ 68 | virtual ~NetlinkServer( 69 | void 70 | ); 71 | 72 | /** 73 | * Start server and listen for incoming connections. 74 | * Implements the central socket server loop. Incoming connections will be stored. 75 | */ 76 | virtual void run( 77 | void 78 | ); 79 | 80 | /** 81 | * Remove a connection object from the list of available connections. 82 | * Detaching is required for notification connections wich are never used to transfer command 83 | * data from TLCs to the driver. If the function succeeds, freeing the connection will no longer 84 | * be the server's responsability. 85 | * 86 | * @param connection The connection object to remove. 87 | */ 88 | virtual void detachConnection( 89 | Connection *connection 90 | ); 91 | 92 | private: 93 | /** 94 | * Handle incomming Netlink message. 95 | * It routes the incomming packet to the apropriate connection based on the packet's 96 | * session magic. 97 | * 98 | * @param nlh The netlink message's header + payload 99 | */ 100 | void handleMessage( 101 | struct nlmsghdr *nlh 102 | ); 103 | 104 | /** 105 | * Retreive connection based on hash. 106 | * Search the peer connections hashmap for a hash and return 107 | * the associated Connection object 108 | * 109 | * @param seq The seq to search 110 | * @return The NetlinkConnection object if found or NULL if not found 111 | */ 112 | NetlinkConnection *findConnection( 113 | uint64_t hash 114 | ); 115 | 116 | /** 117 | * Insert a connection in the peer connection hashmap 118 | * Insert a new connection in the peer connections hashmap. If there is 119 | * already such a connection it will be overriden! 120 | * 121 | * @param seq The seq to use 122 | * @param connection The connection object to insert 123 | */ 124 | void insertConnection( 125 | uint64_t hash, 126 | NetlinkConnection *connection 127 | ); 128 | 129 | /** 130 | * Remove a connection from the peer connections 131 | * Remove the connection associated with seq from the peer list. 132 | * This doesn't actually free the connection object! 133 | * If the seq is invalid nothing happens. 134 | * 135 | * @param seq The seq to use 136 | */ 137 | void removeConnection( 138 | uint64_t hash 139 | ); 140 | 141 | 142 | /** 143 | * Check for sessions started by applications that died(exited) 144 | * Remove the connections to applications that are not active anymore 145 | * If the application has died then all the sessions associated with it 146 | * should be closed! 147 | * 148 | */ 149 | void cleanupConnections( 150 | void 151 | ); 152 | 153 | connectionMap_t peerConnections; /**< Hashmap with connections to clients */ 154 | }; 155 | 156 | #endif /* SERVER_H_ */ 157 | 158 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/Server/public/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Connection server. 33 | * 34 | * Handles incoming socket connections from clients using the MobiCore driver. 35 | * 36 | * Iterative socket server using UNIX domain stream protocol. 37 | */ 38 | #ifndef SERVER_H_ 39 | #define SERVER_H_ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include "CThread.h" 48 | #include "ConnectionHandler.h" 49 | 50 | /** Number of incoming connections that can be queued. 51 | * Additional clients will generate the error ECONNREFUSED. */ 52 | #define LISTEN_QUEUE_LEN (16) 53 | 54 | 55 | class Server: public CThread 56 | { 57 | 58 | public: 59 | /** 60 | * Server contructor. 61 | * 62 | * @param connectionHanler Connection handler to pass incoming connections to. 63 | * @param localAdrerss Pointer to a zero terminated string containing the file to listen to. 64 | */ 65 | Server( 66 | ConnectionHandler *connectionHandler, 67 | const char *localAddr 68 | ); 69 | 70 | /** 71 | * Server destructor. 72 | * All available connections will be terminated. Resources will be freed. 73 | */ 74 | virtual ~Server( 75 | void 76 | ); 77 | 78 | /** 79 | * Start server and listen for incoming connections. 80 | * Implements the central socket server loop. Incoming connections will be stored. 81 | */ 82 | virtual void run( 83 | ); 84 | 85 | /** 86 | * Remove a connection object from the list of available connections. 87 | * Detaching is required for notification connections wich are never used to transfer command 88 | * data from TLCs to the driver. If the function succeeds, the connection object will no longer 89 | * be handled by the server. 90 | * 91 | * @param connection The connection object to remove. 92 | */ 93 | virtual void detachConnection( 94 | Connection *connection 95 | ); 96 | 97 | protected: 98 | int serverSock; 99 | string socketAddr; 100 | ConnectionHandler *connectionHandler; /**< Connection handler registered to the server */ 101 | 102 | private: 103 | struct Private; 104 | Private *priv_; 105 | 106 | }; 107 | 108 | #endif /* SERVER_H_ */ 109 | 110 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Daemon/public/mcVersion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef DAEMON_VERSION_H_ 32 | #define DAEMON_VERSION_H_ 33 | 34 | #define DAEMON_VERSION_MAJOR 0 35 | #define DAEMON_VERSION_MINOR 2 36 | 37 | #endif /** DAEMON_VERSION_H_ */ 38 | 39 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Kernel/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Module: Kernel Module access 4 | # All paths are relative to application root! 5 | # 6 | # ============================================================================= 7 | 8 | 9 | include $(LOCAL_PATH)/Kernel/Platforms/Generic/Android.mk 10 | 11 | # Include platform specific sub-makefiles 12 | ifdef $(PLATFORM) 13 | include $(LOCAL_PATH)/Kernel/Platforms/$(PLATFORM)/Android.mk 14 | endif 15 | 16 | # Add new source files here 17 | LOCAL_SRC_FILES += Kernel/CKMod.cpp 18 | 19 | # Header files for components including this module 20 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/Kernel 21 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Kernel/CKMod.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Kernel Module Interface. 33 | */ 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "CKMod.h" 41 | 42 | #include "log.h" 43 | 44 | #define INVALID_FILE_DESCRIPTOR ((int)(-1)) 45 | 46 | //------------------------------------------------------------------------------ 47 | CKMod::CKMod(void) 48 | { 49 | fdKMod = INVALID_FILE_DESCRIPTOR; 50 | } 51 | 52 | 53 | //------------------------------------------------------------------------------ 54 | CKMod::~CKMod(void) 55 | { 56 | close(); 57 | } 58 | 59 | 60 | //------------------------------------------------------------------------------ 61 | bool CKMod::isOpen(void) 62 | { 63 | return (INVALID_FILE_DESCRIPTOR == fdKMod) ? false : true; 64 | } 65 | 66 | 67 | //------------------------------------------------------------------------------ 68 | mcResult_t CKMod::open(const char *deviceName) 69 | { 70 | if (isOpen()) { 71 | LOG_W("already open"); 72 | return MC_DRV_ERR_DEVICE_ALREADY_OPEN; 73 | } 74 | 75 | LOG_I(" Opening kernel module at %s.", deviceName); 76 | 77 | // open return -1 on error, "errno" is set with details 78 | int openRet = ::open(deviceName, O_RDWR); 79 | if (openRet == -1) { 80 | LOG_ERRNO("open"); 81 | return MAKE_MC_DRV_KMOD_WITH_ERRNO(errno); 82 | } 83 | 84 | fdKMod = openRet; 85 | return MC_DRV_OK; 86 | } 87 | 88 | 89 | //------------------------------------------------------------------------------ 90 | void CKMod::close( 91 | void 92 | ) 93 | { 94 | if (isOpen()) { 95 | if (::close(fdKMod) != 0) { 96 | LOG_ERRNO("close"); 97 | } else { 98 | fdKMod = INVALID_FILE_DESCRIPTOR; 99 | } 100 | } else { 101 | LOG_W(" Kernel module device not open"); 102 | } 103 | } 104 | 105 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Kernel/CKMod.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Kernel Module Interface. 33 | */ 34 | #ifndef CKMOD_H_ 35 | #define CKMOD_H_ 36 | 37 | #include 38 | #include "ClientLib/public/MobiCoreDriverApi.h" 39 | 40 | 41 | /** 42 | * Base class for accessing a kernel module. 43 | */ 44 | class CKMod 45 | { 46 | 47 | protected: 48 | 49 | int fdKMod; 50 | 51 | /** 52 | * Helper function to check if connected to kernel module. 53 | */ 54 | bool isOpen( 55 | void 56 | ); 57 | 58 | public: 59 | 60 | CKMod( 61 | void 62 | ); 63 | 64 | virtual ~CKMod( 65 | void 66 | ); 67 | 68 | mcResult_t open( 69 | const char *deviceName 70 | ); 71 | 72 | void close( 73 | void 74 | ); 75 | 76 | }; 77 | 78 | #endif // CKMOD_H_ 79 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Kernel/Platforms/Generic/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Generic TrustZone device includes 4 | # 5 | # ============================================================================= 6 | 7 | # This is not a separate module. 8 | # All paths are relative to APP_PROJECT_PATH! 9 | KERNEL_PATH := Kernel/Platforms/Generic 10 | 11 | # Add new source files here 12 | LOCAL_SRC_FILES += $(KERNEL_PATH)/CMcKMod.cpp 13 | 14 | # Header files for components including this module 15 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(KERNEL_PATH) 16 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Kernel/Platforms/Generic/CMcKMod.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * 38 | 39 | #include "McTypes.h" 40 | #include "CKMod.h" 41 | 42 | 43 | /** 44 | * As this is also used by the ClientLib, we do not use exceptions. 45 | */ 46 | class CMcKMod : public CKMod 47 | { 48 | public: 49 | /** 50 | * Map data. 51 | * 52 | * @param len 53 | * @param pHandle 54 | * @param pVirtAddr 55 | * 56 | * @return 0 if all went fine 57 | * @return MC_DRV_ERR_KMOD_NOT_OPEN 58 | * @return MC_DRV_ERR_KERNEL_MODULE or'ed with errno<<16 59 | */ 60 | mcResult_t mapWsm(uint32_t len, 61 | uint32_t *pHandle, 62 | addr_t *pVirtAddr); 63 | /** 64 | * Map data. 65 | * 66 | * @param len 67 | * @param pVirtAddr 68 | * @param pMciReuse [in|out] set to true [in] for reusing MCI buffer 69 | * is set to true [out] if MCI buffer has been reused 70 | * @return 0 if all went fine 71 | * @return MC_DRV_ERR_KMOD_NOT_OPEN 72 | * @return MC_DRV_ERR_KERNEL_MODULE or'ed with errno<<16 73 | */ 74 | mcResult_t mapMCI( 75 | uint32_t len, 76 | addr_t *pVirtAddr, 77 | bool *pReuse); 78 | 79 | int read(addr_t buffer, uint32_t len); 80 | 81 | bool waitSSIQ(uint32_t *pCnt); 82 | 83 | int fcInit(uint32_t nqLength, 84 | uint32_t mcpOffset, 85 | uint32_t mcpLength); 86 | 87 | int fcInfo( 88 | uint32_t extInfoId, 89 | uint32_t *pState, 90 | uint32_t *pExtInfo); 91 | 92 | int fcYield(void); 93 | 94 | int fcNSIQ(void); 95 | 96 | mcResult_t free(uint32_t handle, addr_t buffer, uint32_t len); 97 | 98 | mcResult_t registerWsmL2( 99 | addr_t buffer, 100 | uint32_t len, 101 | uint32_t pid, 102 | uint32_t *pHandle, 103 | uint64_t *pPhysWsmL2); 104 | 105 | mcResult_t unregisterWsmL2(uint32_t handle); 106 | 107 | mcResult_t lockWsmL2(uint32_t handle); 108 | 109 | mcResult_t unlockWsmL2(uint32_t handle); 110 | 111 | uint64_t findWsmL2(uint32_t handle, int fd); 112 | 113 | mcResult_t findContiguousWsm(uint32_t handle, int fd, uint64_t *phys, uint32_t *len); 114 | 115 | mcResult_t setupLog(void); 116 | 117 | bool checkVersion(void); 118 | }; 119 | 120 | typedef CMcKMod *CMcKMod_ptr; 121 | 122 | #endif // CMCKMOD_H_ 123 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/MODULE_LICENSE_BSD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trustonic/trustonic-tee-user-space/e3b0b06025605b06fc1e19588098e5011f6afc83/MobiCoreDriverLib/MODULE_LICENSE_BSD -------------------------------------------------------------------------------- /MobiCoreDriverLib/NOTICE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Registry/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # Module: MobiCore driver registry 4 | # 5 | # ============================================================================= 6 | 7 | # Add new folders with header files here 8 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/Registry/Public 9 | 10 | # Add new source files here 11 | LOCAL_SRC_FILES += Registry/Registry.cpp 12 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/Registry/Public/MobiCoreRegistry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef MOBICORE_REGISTRY_H_ 32 | #define MOBICORE_REGISTRY_H_ 33 | 34 | #include "MobiCoreDriverApi.h" 35 | #include "mcContainer.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** Stores an authentication token in registry. 42 | * @param so Authentication token secure object. 43 | * @param size Authentication token object size 44 | * @return MC_DRV_OK if successful, otherwise error code. 45 | */ 46 | mcResult_t mcRegistryStoreAuthToken(void *so, uint32_t size); 47 | 48 | /** Reads an authentication token from registry. 49 | * @param[out] so Authentication token secure object. 50 | * @param[out] size Authentication token secure object size 51 | * @return MC_DRV_OK if successful, otherwise error code. 52 | */ 53 | mcResult_t mcRegistryReadAuthToken(void *so, uint32_t *size); 54 | 55 | /** Deletes the authentication token secure object from the registry. 56 | * @return MC_DRV_OK if successful, otherwise error code. 57 | */ 58 | mcResult_t mcRegistryDeleteAuthToken(void); 59 | 60 | /** Stores a root container secure object in the registry. 61 | * @param so Root container secure object. 62 | * @param size Root container secure object size 63 | * @return MC_DRV_OK if successful, otherwise error code. 64 | */ 65 | mcResult_t mcRegistryStoreRoot(void *so, uint32_t size); 66 | 67 | /** Reads a root container secure object from the registry. 68 | * @param[out] so Root container secure object. 69 | * @param[out] size Root container secure object size 70 | * @return MC_DRV_OK if successful, otherwise error code. 71 | */ 72 | mcResult_t mcRegistryReadRoot(void *so, uint32_t *size); 73 | 74 | /** Stores a service provider container secure object in the registry. 75 | * @param spid Service provider ID. 76 | * @param so Service provider container secure object. 77 | * @return MC_DRV_OK if successful, otherwise error code. 78 | */ 79 | mcResult_t mcRegistryStoreSp(mcSpid_t spid, void *so, uint32_t size); 80 | 81 | /** Reads a service provider container secure object from the registry. 82 | * @param spid Service provider ID. 83 | * @param[out] so Service provider container secure object. 84 | * @param[out] size Service provider container secure object size 85 | * @return MC_DRV_OK if successful, otherwise error code. 86 | */ 87 | mcResult_t mcRegistryReadSp(mcSpid_t spid, void *so, uint32_t *size); 88 | 89 | /** Deletes a service provider recursively, including all trustlets and 90 | * data. 91 | * @param spid Service provider ID. 92 | * @return MC_DRV_OK if successful, otherwise error code. 93 | */ 94 | mcResult_t mcRegistryCleanupSp(mcSpid_t spid); 95 | 96 | /** Stores a trustlet container secure object in the registry. 97 | * @param uuid Trustlet UUID. 98 | * @param spid SPID of the trustlet container. 99 | * @param so Trustlet container secure object. 100 | * @param size Trustlet container secure object size. 101 | * @return MC_DRV_OK if successful, otherwise error code. 102 | */ 103 | mcResult_t mcRegistryStoreTrustletCon(const mcUuid_t *uuid, const mcSpid_t spid, void *so, uint32_t size); 104 | 105 | /** Reads a trustlet container secure object from the registry. 106 | * @param uuid Trustlet UUID. 107 | * @param spid SPID of the trustlet container 108 | * @param[out] so Trustlet container secure object. 109 | * @param[out] size Trustlet container secure object size 110 | * @return MC_DRV_OK if successful, otherwise error code. 111 | */ 112 | mcResult_t mcRegistryReadTrustletCon(const mcUuid_t *uuid, const mcSpid_t spid, void *so, uint32_t *size); 113 | 114 | /** Deletes a trustlet container secure object and all of its associated data. 115 | * @param uuid Trustlet UUID. 116 | * @param spid Service provider ID 117 | * @return MC_DRV_OK if successful, otherwise error code. 118 | */ 119 | mcResult_t mcRegistryCleanupTrustlet(const mcUuid_t *uuid, const mcSpid_t spid); 120 | 121 | /** 122 | * mcRegistryCleanupTA() 123 | * 124 | * Removes all associated data of a TA (when uninstalled) 125 | * 126 | * @param [in] uuid the UUID to clean up all files belonging too 127 | * @retrurn MC_DRV_OK is successful, othwise an error code from mcResult_t 128 | */ 129 | mcResult_t mcRegistryCleanupTA(const mcUuid_t *uuid); 130 | 131 | /** Deletes the root container and all of its associated service provider 132 | * containers. 133 | * @return MC_DRV_OK if successful, otherwise error code. 134 | */ 135 | mcResult_t mcRegistryCleanupRoot(void); 136 | 137 | /** Stores a Trustlet Application blob in the registry. 138 | * @param spid SPID of the trustlet container. 139 | * @param blob Trustlet Application blob. 140 | * @param size Trustlet Application blob size. 141 | * @return MC_DRV_OK if successful, otherwise error code. 142 | */ 143 | mcResult_t mcRegistryStoreTABlob(mcSpid_t spid, void *blob, uint32_t size); 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif // MOBICORE_REGISTRY_H_ 150 | 151 | -------------------------------------------------------------------------------- /MobiCoreDriverLib/buildTag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #define MOBICORE_COMPONENT_BUILD_TAG \ 32 | "t-base-ARNDALE-Android-302A-2003_2003" 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # trustonic-tee-user-space 2 | 3 | Android user space components for the Trustonic Trusted Execution Environment 4 | 5 | Version for the QEmu/Goldfish emulator 6 | -------------------------------------------------------------------------------- /common/LogWrapper/Android.mk: -------------------------------------------------------------------------------- 1 | # ============================================================================= 2 | # 3 | # MobiCore log wrapper to be included by Android components / products 4 | # 5 | # ============================================================================= 6 | 7 | # This is not a separate module. 8 | # Only for inclusion by other modules. 9 | 10 | LOCAL_SHARED_LIBRARIES += liblog 11 | 12 | # Enable logging to logcat per default 13 | LOCAL_CFLAGS += -DLOG_ANDROID 14 | 15 | LOCAL_C_INCLUDES += $(call my-dir) -------------------------------------------------------------------------------- /common/MobiCore/inc/McLib/GpTci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef _GP_TCI_H_ 32 | #define _GP_TCI_H_ 33 | 34 | typedef struct { 35 | uint32_t a; 36 | uint32_t b; 37 | } TEE_Value; 38 | 39 | #if defined (TRUSTEDAPP) 40 | typedef struct { 41 | void *sVirtualAddr; /**< The virtual address of the Bulk buffer regarding the address space of the Trustlet, already includes a possible offset! */ 42 | uint32_t sVirtualLen; /**< Length of the mapped Bulk buffer */ 43 | } mcBulkMap_t; 44 | #endif 45 | 46 | typedef struct { 47 | mcBulkMap_t mapInfo; 48 | uint32_t outputSize; 49 | } _TEEC_MemoryReferenceInternal; 50 | 51 | typedef union { 52 | TEE_Value value; 53 | _TEEC_MemoryReferenceInternal memref; 54 | } _TEEC_ParameterInternal; 55 | 56 | typedef enum { 57 | _TA_OPERATION_OPEN_SESSION = 1, 58 | _TA_OPERATION_INVOKE_COMMAND = 2, 59 | _TA_OPERATION_CLOSE_SESSION = 3, 60 | } _TEEC_TCI_type; 61 | 62 | typedef struct { 63 | _TEEC_TCI_type type; 64 | uint32_t commandId; 65 | uint32_t paramTypes; 66 | _TEEC_ParameterInternal params[4]; 67 | bool isCancelled; 68 | } _TEEC_OperationInternal; 69 | 70 | typedef struct { 71 | char header[8];// = "TCIGP000"`: version indicator (to support future format changes) 72 | TEEC_UUID destination; 73 | _TEEC_OperationInternal operation; //the data of the ongoing operation (if any) 74 | uint32_t ready; 75 | // The following fields are set by the secure world (in a future version, they may also be set by the normal world communication layer): 76 | uint32_t returnOrigin; 77 | uint32_t returnStatus; 78 | } _TEEC_TCI; 79 | 80 | /** 81 | * Termination codes 82 | */ 83 | #define TA_EXIT_CODE_PANIC (300) 84 | #define TA_EXIT_CODE_TCI (301) 85 | #define TA_EXIT_CODE_PARAMS (302) 86 | #define TA_EXIT_CODE_FINISHED (303) 87 | #define TA_EXIT_CODE_SESSIONSTATE (304) 88 | #define TA_EXIT_CODE_CREATEFAILED (305) 89 | 90 | #endif // _GP_TCI_H_ 91 | -------------------------------------------------------------------------------- /common/MobiCore/inc/Mci/mci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | *

Introduction

33 | * The MobiCore Control Interface (MCI) is the interface for integrating G&D MobiCore technology into the 34 | * rich operating system running in the non-secure part of an ARM TrustZone enabled platform. 35 | * 36 | *

Interface overview

37 | * The Structure of the MobiCore control interface is depicted in the figure below: 38 | * @image html DoxyOverviewMci500x.png "MobiCore control interface" 39 | * @image latex DoxyOverviewMci500x.png "MobiCore control interface" width=12cm 40 | * 41 | * The MCI is composed of the following interfaces: 42 | *
    43 | * 44 | *
  • MobiCore control protocol (MCP) interface.

  • 45 | * The MCP interface is responsible for the main communicating with the MobiCore. This involves sending commands for starting 46 | * and stopping of Trustlets as well as checking their corresponding answers. MCP information is exchanged in a 47 | * world shared memory buffer which needs to be initially established between NWd and SWd using the FastCall interface.
    48 | * 49 | *
  • Notification queue interface.

  • 50 | * Notifications inform the MobiCore runtime environment that information is pending in a WSM buffer. 51 | * The Trustlet Connector (TLC) and the corresponding Trustlet also utilize this buffer to 52 | * notify each other about new data within the Trustlet Connector Interface (TCI). Therefore the TLC writes 53 | * a notification including the session ID to the buffer. The driver informs the MobiCore 54 | * about the availability of a notification with the use of a SIQ. On the secure side the Runtime Management 55 | * notifies the Trustlet, according to the given session ID, about the availability of new data. 56 | * The same mechanism is used vice versa for writing data back to the None-secure world. 57 | * 58 | *
  • FastCall interface.

  • 59 | * The FastCall interface of the MobiCore system is used to transfer control from the Non-secure World (NWd) to the 60 | * Secure World (SWd) and back. There are three mechanisms the NWd shall use to interact with the MobiCore Monitor: 61 | * FastCall, N-SIQ and NQ-IRQ (Notification IRQ). FastCall and N-SIQ operations are used to hand over control 62 | * to the MobiCore. Both functions make use of the SMC [ARM11] operation. 63 | * 64 | *
65 | * 66 | * You can find more information about the interfaces in the respective modules description. 67 | * 68 | *

Version history

69 | * 70 | * 71 | * 72 | * 73 | * 74 | * 75 | * 76 | * 77 | * 78 | *
DateVersionChanges
2009-06-250.1Initial Release
2009-07-010.2Major rewrite
2009-08-060.3Added documentation for FastCall helper functions
2009-09-100.4Update of constant naming. Modification of doxygen config.
2010-03-090.5Added fastCallPower() helper function for MC_FC_POWER.
2010-05-100.6Restructuring of load format header.
2011-07-190.7update to reflect current code changes.
79 | * 80 | * 81 | * @file 82 | * @defgroup FCI FastCall Interface 83 | * 84 | * @defgroup NQ Notification Queue 85 | * 86 | * @defgroup MCP MobiCore Control Protocol 87 | * 88 | */ 89 | #ifndef MCI_H_ 90 | #define MCI_H_ 91 | 92 | #include "version.h" 93 | #include "mcifc.h" 94 | #include "mcinq.h" 95 | #include "mcimcp.h" 96 | 97 | #endif /** MCI_H_ */ 98 | 99 | /** @} */ 100 | -------------------------------------------------------------------------------- /common/MobiCore/inc/Mci/mcinq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * @addtogroup NQ 33 | * @{ 34 | * Notifications inform the MobiCore runtime environment that information is pending in a WSM buffer. 35 | * The Trustlet Connector (TLC) and the corresponding trustlet also utilize this buffer to notify 36 | * each other about new data within the Trustlet Connector Interface (TCI). 37 | * 38 | * The buffer is set up as a queue, which means that more than one notification can be written to the buffer 39 | * before the switch to the other world is performed. Each side therefore facilitates an incoming and an 40 | * outgoing queue for communication with the other side. 41 | * 42 | * Notifications hold the session ID, which is used to reference the communication partner in the other world. 43 | * So if, e.g., the TLC in the normal world wants to notify his trustlet about new data in the TLC buffer 44 | * 45 | * @file 46 | * Notification queue declarations. 47 | * 48 | */ 49 | 50 | #ifndef NQ_H_ 51 | #define NQ_H_ 52 | 53 | /** \name NQ Size Defines 54 | * Minimum and maximum count of elements in the notification queue. 55 | * @{ */ 56 | #define MIN_NQ_ELEM 1 /**< Minimum notification queue elements. */ 57 | #define MAX_NQ_ELEM 64 /**< Maximum notification queue elements. */ 58 | /** @} */ 59 | 60 | /** \name NQ Length Defines 61 | * Minimum and maximum notification queue length. 62 | * @{ */ 63 | #define MIN_NQ_LEN (MIN_NQ_ELEM * sizeof(notification_t)) /**< Minimum notification length (in bytes). */ 64 | #define MAX_NQ_LEN (MAX_NQ_ELEM * sizeof(notification_t)) /**< Maximum notification length (in bytes). */ 65 | /** @} */ 66 | 67 | /** \name Session ID Defines 68 | * Standard Session IDs. 69 | * @{ */ 70 | #define SID_MCP 0 /**< MCP session ID is used when directly communicating with the MobiCore (e.g. for starting and stopping of trustlets). */ 71 | #define SID_INVALID 0xffffffff /**< Invalid session id is returned in case of an error. */ 72 | /** @} */ 73 | 74 | /** Notification data structure. */ 75 | typedef struct{ 76 | uint32_t sessionId; /**< Session ID. */ 77 | int32_t payload; /**< Additional notification information. */ 78 | } notification_t; 79 | 80 | /** Notification payload codes. 81 | * 0 indicated a plain simple notification, 82 | * a positive value is a termination reason from the task, 83 | * a negative value is a termination reason from MobiCore. 84 | * Possible negative values are given below. 85 | */ 86 | typedef enum { 87 | ERR_INVALID_EXIT_CODE = -1, /**< task terminated, but exit code is invalid */ 88 | ERR_SESSION_CLOSE = -2, /**< task terminated due to session end, no exit code available */ 89 | ERR_INVALID_OPERATION = -3, /**< task terminated due to invalid operation */ 90 | ERR_INVALID_SID = -4, /**< session ID is unknown */ 91 | ERR_SID_NOT_ACTIVE = -5, /**< session is not active */ 92 | ERR_SESSION_KILLED = -6, /**< session was force-killed (due to an administrative command). */ 93 | } notificationPayload_t; 94 | 95 | /** Declaration of the notification queue header. 96 | * layout as specified in the data structure specification. 97 | */ 98 | typedef struct { 99 | uint32_t writeCnt; /**< Write counter. */ 100 | uint32_t readCnt; /**< Read counter. */ 101 | uint32_t queueSize; /**< Queue size. */ 102 | } notificationQueueHeader_t; 103 | 104 | /** Queue struct which defines a queue object. 105 | * The queue struct is accessed by the queue type of 106 | * function. elementCnt must be a power of two and the power needs 107 | * to be smaller than power of uint32_t (obviously 32). 108 | */ 109 | typedef struct { 110 | notificationQueueHeader_t hdr; /**< Queue header. */ 111 | notification_t notification[MIN_NQ_ELEM]; /**< Notification elements. */ 112 | } notificationQueue_t; 113 | 114 | #endif /** NQ_H_ */ 115 | 116 | /** @} */ 117 | -------------------------------------------------------------------------------- /common/MobiCore/inc/Mci/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2014 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef MCI_VERSION_H_ 32 | #define MCI_VERSION_H_ 33 | 34 | #define MCI_VERSION_MAJOR 1 35 | #define MCI_VERSION_MINOR 0 36 | 37 | #endif /** MCI_VERSION_H_ */ 38 | -------------------------------------------------------------------------------- /common/MobiCore/inc/TlCm/tlCmApiCommon.h: -------------------------------------------------------------------------------- 1 | /** @addtogroup CMP_COMMON 2 | * @{ 3 | * @file 4 | * Common interface definitions to content management trustlet (TlCm). 5 | * 6 | * The TlCm is responsible for implementing content management protocol (CMP) 7 | * commands and generating approriate CMP responses. 8 | * 9 | * Copyright © Trustonic Limited 2013. 10 | * 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of the Trustonic Limited nor the names of its 21 | * contributors may be used to endorse or promote products derived from this 22 | * software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef TL_CM_API_COMMON_H_ 38 | #define TL_CM_API_COMMON_H_ 39 | 40 | #include "tlCmError.h" 41 | 42 | /** TlCm command ids supported. 43 | * @note All command ids must be in range 0 to 0x1D. 44 | */ 45 | //lint -esym(756, cmpCommands_t) cmpCommands_t type by itself not used. 46 | typedef enum cmpCommands_t { 47 | MC_CMP_CMD_AUTHENTICATE = 0, 48 | MC_CMP_CMD_BEGIN_ROOT_AUTHENTICATION = 1, 49 | MC_CMP_CMD_BEGIN_SOC_AUTHENTICATION = 2, 50 | MC_CMP_CMD_BEGIN_SP_AUTHENTICATION = 3, 51 | MC_CMP_CMD_GENERATE_AUTH_TOKEN = 4, 52 | MC_CMP_CMD_GET_VERSION = 5, 53 | //MC_CMP_CMD_ROOT_CONT_ACTIVATE = 6, 54 | MC_CMP_CMD_ROOT_CONT_LOCK_BY_ROOT = 7, 55 | //MC_CMP_CMD_ROOT_CONT_REGISTER = 8, 56 | MC_CMP_CMD_ROOT_CONT_REGISTER_ACTIVATE = 9, 57 | MC_CMP_CMD_ROOT_CONT_UNLOCK_BY_ROOT = 10, 58 | MC_CMP_CMD_ROOT_CONT_UNREGISTER = 11, 59 | MC_CMP_CMD_SP_CONT_ACTIVATE = 12, 60 | MC_CMP_CMD_SP_CONT_LOCK_BY_ROOT = 13, 61 | MC_CMP_CMD_SP_CONT_LOCK_BY_SP = 14, 62 | MC_CMP_CMD_SP_CONT_REGISTER = 15, 63 | MC_CMP_CMD_SP_CONT_REGISTER_ACTIVATE = 16, 64 | MC_CMP_CMD_SP_CONT_UNLOCK_BY_ROOT = 17, 65 | MC_CMP_CMD_SP_CONT_UNLOCK_BY_SP = 18, 66 | MC_CMP_CMD_SP_CONT_UNREGISTER = 19, 67 | MC_CMP_CMD_TLT_CONT_ACTIVATE = 20, 68 | MC_CMP_CMD_TLT_CONT_LOCK_BY_SP = 21, 69 | MC_CMP_CMD_TLT_CONT_PERSONALIZE = 22, 70 | MC_CMP_CMD_TLT_CONT_REGISTER = 23, 71 | MC_CMP_CMD_TLT_CONT_REGISTER_ACTIVATE = 24, 72 | MC_CMP_CMD_TLT_CONT_UNLOCK_BY_SP = 25, 73 | MC_CMP_CMD_TLT_CONT_UNREGISTER = 26, 74 | MC_CMP_CMD_GET_SUID = 27, 75 | MC_CMP_CMD_AUTHENTICATE_TERMINATE = 28, 76 | MC_CMP_CMD_LAST_ = MC_CMP_CMD_AUTHENTICATE_TERMINATE, 77 | } cmpCommands_t; 78 | 79 | /** TlCm exit code: TlCm exited with error. */ 80 | #define EXIT_ERROR ((uint32_t)(-1)) 81 | 82 | #endif // TL_CM_API_COMMON_H_ 83 | 84 | /** @} */ 85 | -------------------------------------------------------------------------------- /common/MobiCore/inc/TlCm/tlCmError.h: -------------------------------------------------------------------------------- 1 | /** @addtogroup CMP_COMMON 2 | * @{ 3 | * 4 | * @file 5 | * Content management trustlet (TlCm) error return code definitions. 6 | * Definition of all possible TlCm error return codes. 7 | * 8 | * Copyright © Trustonic Limited 2013. 9 | * 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. Neither the name of the Trustonic Limited nor the names of its 20 | * contributors may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef TL_CM_ERROR_H_ 37 | #define TL_CM_ERROR_H_ 38 | 39 | /** No error. */ 40 | #define SUCCESSFUL 0x00000000 41 | 42 | /** Error unknown command. */ 43 | #define RET_ERR_EXT_UNKNOWN_COMMAND 0xE0000000 44 | /** Error security status not satified. */ 45 | #define RET_ERR_EXT_SECURITY_STATUS_NOT_SATISFIED 0xE0000010 46 | /** Error secure messaging failed. */ 47 | #define RET_ERR_EXT_SECURE_MESSAGING_FAILED 0xE0000020 48 | /** Error incorrect parameters. */ 49 | #define RET_ERR_EXT_INCORRECT_PARAMETERS 0xE0000030 50 | /** Error referenced data invalid. */ 51 | #define RET_ERR_EXT_REFERENCED_DATA_INVALID 0xE0000040 52 | /** Error referenced data not found. */ 53 | #define RET_ERR_EXT_REFERENCED_DATA_NOT_FOUND 0xE0000050 54 | /** Error method blocked. */ 55 | #define RET_ERR_EXT_METHOD_BLOCKED 0xE0000060 56 | /** Error conditions of use not satified. */ 57 | #define RET_ERR_EXT_CONDITIONS_OF_USE_NOT_SATISFIED 0xE0000070 58 | /** Error container already registred error. */ 59 | #define RET_ERR_EXT_ALREADY_REGISTERED 0xE0000090 60 | /** Error container already activated. */ 61 | #define RET_ERR_EXT_ALREADY_ACTIVATED 0xE00000A0 62 | /** Error container not registred. */ 63 | #define RET_ERR_EXT_NOT_REGISTERED 0xE00000B0 64 | /** Error container not activated. */ 65 | #define RET_ERR_EXT_NOT_ACTIVATED 0xE00000C0 66 | /** Error container full. */ 67 | #define RET_ERR_EXT_CONTAINER_FULL 0xE00000D0 68 | /** Error container not locked. */ 69 | #define RET_ERR_EXT_NOT_LOCKED 0xE00000E0 70 | /** Error container locked. */ 71 | #define RET_ERR_EXT_LOCKED 0xE00000F0 72 | /** Error container already locked. */ 73 | #define RET_ERR_EXT_ALREADY_LOCKED 0xE0000100 74 | 75 | /** Internal error. */ 76 | #define RET_ERR_EXT_INTERNAL_ERROR 0xE0001000 77 | /** Mapped allocation size error. */ 78 | #define RET_ERR_EXT_SIZE 0xE0002000 79 | 80 | /** Unspecified error. */ 81 | #define RET_ERR_EXT_UNSPECIFIED 0xEEEEEEEE 82 | 83 | #endif // TL_CM_ERROR_H_ 84 | 85 | /** @} */ 86 | -------------------------------------------------------------------------------- /common/MobiCore/inc/TlCm/tlCmUuid.h: -------------------------------------------------------------------------------- 1 | /** @addtogroup CMP_COMMON 2 | * @{ 3 | * @file 4 | * Content management trustlet (TlCm) Uuid definition. 5 | * 6 | * Copyright © Trustonic Limited 2013. 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of the Trustonic Limited nor the names of its 18 | * contributors may be used to endorse or promote products derived from this 19 | * software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef TL_CM_UUID_H 35 | #define TL_CM_UUID_H 36 | 37 | /** Uuid of TlCm. */ 38 | #define TL_CM_UUID { { 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } 39 | 40 | #endif // TL_CM_UUID_H 41 | 42 | /** @} */ 43 | -------------------------------------------------------------------------------- /common/MobiCore/inc/TlCm/version.h: -------------------------------------------------------------------------------- 1 | /** @addtogroup CMP_COMMON 2 | * @{ 3 | * @file 4 | * Content management trustlet (TlCm) version definition. 5 | * 6 | * Copyright © Trustonic Limited 2013. 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of the Trustonic Limited nor the names of its 18 | * contributors may be used to endorse or promote products derived from this 19 | * software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef CMP_VERSION_H_ 35 | #define CMP_VERSION_H_ 36 | 37 | /** Latest supported CMP major version number. */ 38 | #define CMP_VERSION_MAJOR 3 39 | /** Latest supported CMP minor version number. */ 40 | #define CMP_VERSION_MINOR 0 41 | 42 | #endif // CMP_VERSION_H_ 43 | 44 | /** @} */ 45 | -------------------------------------------------------------------------------- /common/MobiCore/inc/mcDriverId.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2015 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef RTMDRVID_H_ 33 | #define RTMDRVID_H_ 34 | 35 | #define MC_DRV_VENDOR_ID_SHIFT (16) 36 | #define MC_DRV_VENDOR_ID_MASK (0xFFFF << MC_DRV_VENDOR_ID_SHIFT) 37 | #define MC_DRV_NUMBER_MASK (0x0000FFFF) 38 | 39 | /** MobiCore vendor IDs. */ 40 | typedef enum { 41 | MC_DRV_VENDOR_ID_GD = 0 << MC_DRV_VENDOR_ID_SHIFT, 42 | } mcDrvVendorId_t; 43 | 44 | /** MobiCore GD driver numbers. */ 45 | typedef enum { 46 | MC_DRV_NUMBER_INVALID = 0, 47 | MC_DRV_NUMBER_CRYPTO = 1, 48 | /** Last GD driver number reserved for pre-installed drivers. 49 | * GD driver numbers up to this constant may not be used for loadable drivers. */ 50 | MC_DRV_NUMBER_LAST_PRE_INSTALLED = 100, 51 | TB_DRV_NUMBER_TUI = 0x101, 52 | TB_DRV_NUMBER_TPLAY = 0x600, 53 | } mcDrvNumber_t; 54 | 55 | /** MobiCore driver IDs for Trustlets. */ 56 | typedef enum { 57 | MC_DRV_ID_INVALID = MC_DRV_VENDOR_ID_GD | MC_DRV_NUMBER_INVALID, 58 | MC_DRV_ID_CRYPTO = MC_DRV_VENDOR_ID_GD | MC_DRV_NUMBER_CRYPTO, 59 | /** Last GD driver ID reserved for pre-installed drivers. 60 | * GD driver IDs up to this constant may not be used for loadable drivers. */ 61 | MC_DRV_ID_LAST_PRE_INSTALLED = MC_DRV_VENDOR_ID_GD | MC_DRV_NUMBER_LAST_PRE_INSTALLED, 62 | TB_DRV_ID_TUI = MC_DRV_VENDOR_ID_GD | TB_DRV_NUMBER_TUI, 63 | TB_DRV_ID_TPLAY = MC_DRV_VENDOR_ID_GD | TB_DRV_NUMBER_TPLAY, 64 | } mcDriverId_t; 65 | 66 | #endif /* RTMDRVID_H_ */ 67 | -------------------------------------------------------------------------------- /common/MobiCore/inc/mcRootid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2015 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef MC_ROOTID_H_ 33 | #define MC_ROOTID_H_ 34 | 35 | #ifdef WIN32 36 | #define _UNUSED 37 | #else 38 | #define _UNUSED __attribute__((unused)) 39 | #endif 40 | 41 | /** Root Identifier type. */ 42 | typedef uint32_t mcRootid_t; 43 | 44 | /** Reserved root id value 1. */ 45 | static _UNUSED const mcRootid_t MC_ROOTID_RESERVED1 = 0; 46 | 47 | /** Reserved root id value 2. */ 48 | static _UNUSED const mcRootid_t MC_ROOTID_RESERVED2 = 0xFFFFFFFF; 49 | 50 | /** Root id for system applications. */ 51 | static _UNUSED const mcRootid_t MC_ROOTID_SYSTEM = 0xFFFFFFFE; 52 | 53 | /** Yet another test ROOT ID */ 54 | static _UNUSED const mcRootid_t MC_ROOTID_RESERVED3 = 0xFFFFFFFD; 55 | 56 | /** GP TAs - used in the Trusted storage */ 57 | static _UNUSED const mcRootid_t MC_ROOTID_GP = 0xFFFFFFFC; 58 | 59 | /** RTM's Root ID */ 60 | static _UNUSED const mcRootid_t MC_ROOTID_RTM = 0xFFFFFFFB; 61 | 62 | #endif // MC_ROOTID_H_ 63 | 64 | -------------------------------------------------------------------------------- /common/MobiCore/inc/mcSpid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2015 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef MC_SPID_H_ 33 | #define MC_SPID_H_ 34 | 35 | #ifdef WIN32 36 | #define _UNUSED 37 | #else 38 | #define _UNUSED __attribute__((unused)) 39 | #endif 40 | 41 | /** Service provider Identifier type. */ 42 | typedef uint32_t mcSpid_t; 43 | 44 | /** SPID value used as free marker in root containers. */ 45 | static _UNUSED const mcSpid_t MC_SPID_FREE = 0xFFFFFFFF; 46 | 47 | /** Reserved SPID value. */ 48 | static _UNUSED const mcSpid_t MC_SPID_RESERVED = 0; 49 | 50 | /** SPID for system applications. */ 51 | static _UNUSED const mcSpid_t MC_SPID_SYSTEM = 0xFFFFFFFE; 52 | 53 | /** SPID reserved for tests only */ 54 | static _UNUSED const mcSpid_t MC_SPID_RESERVED_TEST = 0xFFFFFFFD; 55 | static _UNUSED const mcSpid_t MC_SPID_TRUSTONIC_TEST = 0x4; 56 | 57 | /** SPID reserved for OTA development */ 58 | static _UNUSED const mcSpid_t MC_SPID_TRUSTONIC_OTA = 0x2A; 59 | 60 | /** GP TAs - stored in the trusted storage. They all share the same */ 61 | static _UNUSED const mcSpid_t MC_SPID_GP = 0xFFFFFFFC; 62 | 63 | /** RTM's SPID */ 64 | static _UNUSED const mcSpid_t MC_SPID_RTM = 0xFFFFFFFB; 65 | 66 | #endif // MC_SPID_H_ 67 | 68 | -------------------------------------------------------------------------------- /common/MobiCore/inc/mcSuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2015 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef MC_SUID_H_ 33 | #define MC_SUID_H_ 34 | 35 | /** Length of SUID. */ 36 | #define MC_SUID_LEN 16 37 | 38 | /** Platform specific device identifier (serial number of the chip). */ 39 | typedef struct { 40 | uint8_t data[MC_SUID_LEN - sizeof(uint32_t)]; 41 | } suidData_t; 42 | 43 | /** Soc unique identifier type. */ 44 | typedef struct { 45 | uint32_t sipId; /**< Silicon Provider ID to be set during build. */ 46 | suidData_t suidData; 47 | } mcSuid_t; 48 | 49 | #endif // MC_SUID_H_ 50 | 51 | -------------------------------------------------------------------------------- /common/MobiCore/inc/mcUuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2015 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef MC_UUID_H_ 33 | #define MC_UUID_H_ 34 | 35 | #ifdef WIN32 36 | #define _UNUSED 37 | #else 38 | #define _UNUSED __attribute__((unused)) 39 | #endif 40 | 41 | #define UUID_TYPE 42 | 43 | #define UUID_LENGTH 16 44 | /** Universally Unique Identifier (UUID) according to ISO/IEC 11578. */ 45 | typedef struct { 46 | uint8_t value[UUID_LENGTH]; /**< Value of the UUID. */ 47 | } mcUuid_t, *mcUuid_ptr; 48 | 49 | /** UUID value used as free marker in service provider containers. */ 50 | #define MC_UUID_FREE_DEFINE \ 51 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ 52 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } 53 | 54 | static _UNUSED const mcUuid_t MC_UUID_FREE = { 55 | MC_UUID_FREE_DEFINE 56 | }; 57 | 58 | /** Reserved UUID. */ 59 | #define MC_UUID_RESERVED_DEFINE \ 60 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } 62 | 63 | static _UNUSED const mcUuid_t MC_UUID_RESERVED = { 64 | MC_UUID_RESERVED_DEFINE 65 | }; 66 | 67 | /** UUID for system applications. */ 68 | #define MC_UUID_SYSTEM_DEFINE \ 69 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ 70 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE } 71 | 72 | static _UNUSED const mcUuid_t MC_UUID_SYSTEM = { 73 | MC_UUID_SYSTEM_DEFINE 74 | }; 75 | 76 | #define MC_UUID_RTM_DEFINE \ 77 | { 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, \ 78 | 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34 } 79 | 80 | static _UNUSED const mcUuid_t MC_UUID_RTM = { 81 | MC_UUID_RTM_DEFINE 82 | }; 83 | 84 | /** 85 | * TODO: Replace with v5 UUID (milestone #3) 86 | */ 87 | #define LTA_UUID_DEFINE \ 88 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 89 | 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11} 90 | 91 | #endif // MC_UUID_H_ 92 | 93 | -------------------------------------------------------------------------------- /common/MobiCore/inc/mcVersionInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2015 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef MCVERSIONINFO_H_ 32 | #define MCVERSIONINFO_H_ 33 | 34 | /** Length of MobiCore product ID string. */ 35 | #define MC_PRODUCT_ID_LEN 64 36 | 37 | /** Global MobiCore Version Information. 38 | */ 39 | typedef struct { 40 | char productId[MC_PRODUCT_ID_LEN]; /** < Product ID of Mobicore; zero-terminated */ 41 | uint32_t versionMci; /** < Version of Mobicore Control Interface */ 42 | uint32_t versionSo; /** < Version of Secure Objects */ 43 | uint32_t versionMclf; /** < Version of MobiCore Load Format */ 44 | uint32_t versionContainer; /** < Version of MobiCore Container Format */ 45 | uint32_t versionMcConfig; /** < Version of MobiCore Configuration Block Format */ 46 | uint32_t versionTlApi; /** < Version of MobiCore Trustlet API Implementation */ 47 | uint32_t versionDrApi; /** < Version of MobiCore Driver API Implementation */ 48 | uint32_t versionCmp; /** < Version of Content Management Protocol */ 49 | } mcVersionInfo_t; 50 | 51 | #endif /** MCVERSIONINFO_H_ */ 52 | -------------------------------------------------------------------------------- /common/MobiCore/inc/version.md5: -------------------------------------------------------------------------------- 1 | a548519579b1a7cddb06c56989fd01f8 *- 2 | -------------------------------------------------------------------------------- /include/Public/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2015 TRUSTONIC LIMITED 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef _MC_DRV_VERSION_H_ 32 | #define _MC_DRV_VERSION_H_ 33 | 34 | #define MCDRVMODULEAPI_VERSION_MAJOR 1 35 | #define MCDRVMODULEAPI_VERSION_MINOR 1 36 | 37 | #endif /* _MC_DRV_VERSION_H_ */ 38 | --------------------------------------------------------------------------------