OLD | NEW |
(Empty) | |
| 1 /* Software-based Trusted Platform Module (TPM) Emulator |
| 2 * Copyright (C) 2004-2010 Mario Strasser <mast@gmx.net> |
| 3 * |
| 4 * This module is free software; you can redistribute it and/or modify |
| 5 * it under the terms of the GNU General Public License as published |
| 6 * by the Free Software Foundation; either version 2 of the License, |
| 7 * or (at your option) any later version. |
| 8 * |
| 9 * This module is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * $Id: tddl.c 364 2010-02-11 10:24:45Z mast $ |
| 15 */ |
| 16 |
| 17 #include <fcntl.h> |
| 18 #include <unistd.h> |
| 19 #include <errno.h> |
| 20 #include <windows.h> |
| 21 #include <config.h> |
| 22 #include "tddl.h" |
| 23 |
| 24 /* library lock */ |
| 25 static CRITICAL_SECTION tddli_lock; |
| 26 |
| 27 #define tddli_mutex_lock(a) EnterCriticalSection(a) |
| 28 #define tddli_mutex_unlock(a) LeaveCriticalSection(a) |
| 29 |
| 30 BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID lpReserved) |
| 31 { |
| 32 switch(reason) { |
| 33 case DLL_PROCESS_ATTACH: |
| 34 InitializeCriticalSection(&tddli_lock); |
| 35 break; |
| 36 case DLL_PROCESS_DETACH: |
| 37 DeleteCriticalSection(&tddli_lock); |
| 38 break; |
| 39 default: |
| 40 break; |
| 41 } |
| 42 return TRUE; |
| 43 } |
| 44 |
| 45 static TSS_RESULT open_device(const char *device_name) |
| 46 { |
| 47 /* open the named pipe and generate a posix file handle */ |
| 48 DWORD mode = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE; |
| 49 HANDLE ph = CreateFile(device_name, GENERIC_READ | GENERIC_WRITE, |
| 50 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 51 SetNamedPipeHandleState(ph, &mode, NULL, NULL); |
| 52 tddli_dh = _open_osfhandle((DWORD)ph, O_RDWR | O_BINARY); |
| 53 if (tddli_dh < 0) { |
| 54 if (errno == ENOENT || errno == ENXIO) { |
| 55 tddli_driver_status = TDDL_DRIVER_FAILED; |
| 56 tddli_device_status = TDDL_DEVICE_NOT_FOUND; |
| 57 } else { |
| 58 tddli_driver_status = TDDL_DRIVER_NOT_OPENED; |
| 59 tddli_device_status = TDDL_DEVICE_RECOVERABLE; |
| 60 } |
| 61 return TDDL_E_FAIL; |
| 62 } else { |
| 63 tddli_driver_status = TDDL_DRIVER_OK; |
| 64 tddli_device_status = TDDL_DEVICE_OK; |
| 65 |
| 66 return TDDL_SUCCESS; |
| 67 } |
| 68 } |
| 69 |
| 70 static TSS_RESULT open_socket(const char *socket_name) |
| 71 { |
| 72 return TDDL_E_FAIL; |
| 73 } |
| 74 |
OLD | NEW |