Commit 6677ba78 authored by Alexandre Julliard's avatar Alexandre Julliard

ctapi32: Move libctapi.so interface to a separate Unix library.

parent 85b063af
MODULE = ctapi32.dll
IMPORTS = advapi32
EXTRADLLFLAGS = -mcygwin
C_SRCS = ctapi32.c
C_SRCS = \
ctapi32.c \
unixlib.c
/*
* CT-API library for the REINER SCT cyberJack pinpad/e-com USB.
* Copyright (C) 2001 REINER SCT
* Author: Matthias Bruestle
* Support: support@reiner-sct.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef H_CTAPI
#define H_CTAPI
/* More unique defines */
#define CT_API_AD_HOST 2
#define CT_API_AD_REMOTE 5
#define CT_API_AD_CT 1
#define CT_API_AD_ICC1 0
#define CT_API_AD_ICC2 2
#define CT_API_AD_ICC3 3
#define CT_API_AD_ICC4 4
#define CT_API_AD_ICC5 5
#define CT_API_AD_ICC6 6
#define CT_API_AD_ICC7 7
#define CT_API_AD_ICC8 8
#define CT_API_AD_ICC9 9
#define CT_API_AD_ICC10 10
#define CT_API_AD_ICC11 11
#define CT_API_AD_ICC12 12
#define CT_API_AD_ICC13 13
#define CT_API_AD_ICC14 14
#define CT_API_RV_OK 0
#define CT_API_RV_ERR_INVALID -1
#define CT_API_RV_ERR_CT -8
#define CT_API_RV_ERR_TRANS -10
#define CT_API_RV_ERR_MEMORY -11
#define CT_API_RV_ERR_HOST -127
#define CT_API_RV_ERR_HTSI -128
/* MUSCLE style defines */
#define OK 0 /* Success */
#define ERR_INVALID -1 /* Invalid Data */
#define ERR_CT -8 /* CT Error */
#define ERR_TRANS -10 /* Transmission Error */
#define ERR_MEMORY -11 /* Memory Allocate Error */
#define ERR_HOST -127 /* Host Error */
#define ERR_HTSI -128 /* HTSI Error */
#define PORT_COM1 0 /* COM 1 */
#define PORT_COM2 1 /* COM 2 */
#define PORT_COM3 2 /* COM 3 */
#define PORT_COM4 3 /* COM 4 */
#define PORT_Printer 4 /* Printer Port (MAC) */
#define PORT_Modem 5 /* Modem Port (MAC) */
#define PORT_LPT1 6 /* LPT 1 */
#define PORT_LPT2 7 /* LPT 2 */
#define CT 1
#define HOST 2
/* Short */
#define CJ_CTAPI_MAX_LENC 4+1+255+1
#define CJ_CTAPI_MAX_LENR 256+2
/* Extended */
/* #define CJ_CTAPI_MAX_LENC 5+2+65535+2 */
/* #define CJ_CTAPI_MAX_LENR 65536+2 */
/* Maximum for CTAPI */
/* #define CJ_CTAPI_MAX_LENC 65535 */
/* #define CJ_CTAPI_MAX_LENR 65535 */
typedef unsigned char IU8;
typedef unsigned short IU16;
typedef signed char IS8;
typedef signed short IS16;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
IS8 CT_init( IU16 ctn, IU16 pn );
IS8 CT_data( IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr,
IU8 *response );
IS8 CT_close( IU16 ctn );
/* Proprietary extension */
IS8 CT_keycb( IU16 ctn, void (* cb)(IU16 ctn, IU8 status) );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* H_CTAPI */
......@@ -18,102 +18,81 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <string.h>
#include "wine/debug.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "winnls.h"
#include "ctapi.h"
#include "unixlib.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ctapi32);
#define FALLBACK_LIBCTAPI "libctapi.so"
static const WCHAR value_name[] = {'l','i','b','r','a','r','y',0};
static IS8 (*pCT_init)(IU16 ctn, IU16 pn) = NULL;
static IS8 (*pCT_data)(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command,
IU16 *lenr, IU8 *response) = NULL;
static IS8 (*pCT_close)(IU16 ctn) = NULL;
static unixlib_handle_t ctapi_handle;
static void *ctapi_handle = NULL;
#define CTAPI_CALL( func, params ) __wine_unix_call( ctapi_handle, unix_ ## func, params )
static BOOL load_functions(void) {
char soname[MAX_PATH] = FALLBACK_LIBCTAPI, buffer[MAX_PATH];
struct attach_params params;
char soname[MAX_PATH] = FALLBACK_LIBCTAPI;
LONG result;
HKEY key_handle;
if (pCT_init) /* loaded already */
return TRUE;
/* Try to get name of low level library from registry */
/* @@ Wine registry key: HKCU\Software\Wine\ctapi32 */
result = RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Wine\\ctapi32", 0, KEY_READ, &key_handle);
result = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Wine\\ctapi32", 0, KEY_READ, &key_handle);
if (result == ERROR_SUCCESS) {
DWORD type, size;
WCHAR buffer_w[MAX_PATH];
size = sizeof(buffer_w) - sizeof(WCHAR); /* Leave space for null termination */
result = RegQueryValueExW(key_handle, value_name, NULL, &type, (LPBYTE)buffer_w, &size);
result = RegQueryValueExW(key_handle, L"library", NULL, &type, (LPBYTE)buffer_w, &size);
if ((result == ERROR_SUCCESS) && (type == REG_SZ)) {
int len;
/* Null termination */
buffer_w[size / sizeof(WCHAR)] = '\0';
len = WideCharToMultiByte(CP_UNIXCP, 0, buffer_w, -1, buffer, sizeof(buffer), NULL, NULL);
if (len)
memcpy(soname, buffer, len);
WideCharToMultiByte(CP_UNIXCP, 0, buffer_w, -1, soname, sizeof(soname), NULL, NULL);
}
RegCloseKey(key_handle);
}
TRACE("Loading library '%s'\n", soname);
ctapi_handle = dlopen(soname, RTLD_NOW);
if (ctapi_handle) {
TRACE("Successfully loaded '%s'\n", soname);
}
else {
MESSAGE("Wine cannot find any usable hardware library, ctapi32.dll not working.\n");
MESSAGE("Please create the key \"HKEY_CURRENT_USER\\Software\\Wine\\ctapi32\" in your registry\n");
MESSAGE("and set the value \"library\" to your library name (e.g. \"libctapi-cyberjack.so.1\" or \"/usr/lib/readers/libctapi.so\").\n");
return FALSE;
}
params.libname = soname;
if (!CTAPI_CALL( attach, &params )) return TRUE;
#define LOAD_FUNCPTR(f) if((p##f = dlsym(ctapi_handle, #f)) == NULL){WARN("Can't find symbol %s\n", #f); return FALSE;}
LOAD_FUNCPTR(CT_init);
LOAD_FUNCPTR(CT_data);
LOAD_FUNCPTR(CT_close);
#undef LOAD_FUNCPTR
return TRUE;
MESSAGE("Wine cannot find any usable hardware library, ctapi32.dll not working.\n");
MESSAGE("Please create the key \"HKEY_CURRENT_USER\\Software\\Wine\\ctapi32\" in your registry\n");
MESSAGE("and set the value \"library\" to your library name (e.g. \"libctapi-cyberjack.so.1\" or \"/usr/lib/readers/libctapi.so\").\n");
return FALSE;
}
/*
* ct-API specific functions
*/
IS8 WINAPI WIN_CT_init(IU16 ctn, IU16 pn)
IS8 WINAPI CT_init(IU16 ctn, IU16 pn)
{
if (!pCT_init)
return ERR_HOST;
return pCT_init(ctn, pn);
struct ct_init_params params = { ctn, pn };
return CTAPI_CALL( ct_init, &params );
}
IS8 WINAPI WIN_CT_data(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr, IU8 *response)
IS8 WINAPI CT_data(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr, IU8 *response)
{
if (!pCT_data)
return ERR_HOST;
return pCT_data(ctn, dad, sad, lenc, command, lenr, response);
struct ct_data_params params = { ctn, dad, sad, lenc, command, lenr, response };
return CTAPI_CALL( ct_data, &params );
}
IS8 WINAPI WIN_CT_close(IU16 ctn)
IS8 WINAPI CT_close(IU16 ctn)
{
if (!pCT_close)
return ERR_HOST;
return pCT_close(ctn);
struct ct_close_params params = { ctn };
return CTAPI_CALL( ct_close, &params );
}
/*
......@@ -127,13 +106,15 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hinstDLL);
/* Try to load low-level library */
if (NtQueryVirtualMemory( GetCurrentProcess(), hinstDLL, MemoryWineUnixFuncs,
&ctapi_handle, sizeof(ctapi_handle), NULL ))
return FALSE;
if (!load_functions())
return FALSE; /* error */
return FALSE;
break;
case DLL_PROCESS_DETACH:
if (lpvReserved) break;
if (ctapi_handle) dlclose(ctapi_handle);
CTAPI_CALL( detach, NULL );
break;
}
......
@ stdcall CT_close (long) WIN_CT_close
@ stdcall CT_data (long ptr ptr long ptr ptr ptr) WIN_CT_data
@ stdcall CT_init (long long) WIN_CT_init
@ stdcall CT_close(long)
@ stdcall CT_data(long ptr ptr long ptr ptr ptr)
@ stdcall CT_init(long long)
/*
* WINE ct-api wrapper
*
* Copyright 2007 Christian Eggers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#if 0
#pragma makedep unix
#endif
#include "config.h"
#include <stdarg.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "unixlib.h"
static IS8 (*pCT_init)(IU16 ctn, IU16 pn);
static IS8 (*pCT_data)(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr, IU8 *response);
static IS8 (*pCT_close)(IU16 ctn);
static void *ctapi_handle;
static NTSTATUS attach( void *args )
{
struct attach_params *params = args;
if (!(ctapi_handle = dlopen( params->libname, RTLD_NOW ))) return STATUS_DLL_NOT_FOUND;
#define LOAD_FUNCPTR(f) if((p##f = dlsym(ctapi_handle, #f)) == NULL) return STATUS_ENTRYPOINT_NOT_FOUND
LOAD_FUNCPTR(CT_init);
LOAD_FUNCPTR(CT_data);
LOAD_FUNCPTR(CT_close);
#undef LOAD_FUNCPTR
return STATUS_SUCCESS;
}
static NTSTATUS detach( void *args )
{
dlclose( ctapi_handle );
return STATUS_SUCCESS;
}
static NTSTATUS ct_init( void *args )
{
struct ct_init_params *params = args;
return pCT_init(params->ctn, params->pn);
}
static NTSTATUS ct_data( void *args )
{
struct ct_data_params *params = args;
return pCT_data(params->ctn, params->dad, params->sad, params->lenc,
params->command, params->lenr, params->response);
}
static NTSTATUS ct_close( void *args )
{
struct ct_close_params *params = args;
return pCT_close(params->ctn);
}
unixlib_entry_t __wine_unix_call_funcs[] =
{
attach,
detach,
ct_init,
ct_data,
ct_close,
};
/*
* WINE ct-api wrapper
*
* Copyright 2021 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "wine/unixlib.h"
typedef unsigned char IU8;
typedef unsigned short IU16;
typedef signed char IS8;
typedef signed short IS16;
struct attach_params
{
const char *libname;
};
struct ct_init_params
{
IU16 ctn;
IU16 pn;
};
struct ct_data_params
{
IU16 ctn;
IU8 *dad;
IU8 *sad;
IU16 lenc;
IU8 *command;
IU16 *lenr;
IU8 *response;
};
struct ct_close_params
{
IU16 ctn;
};
enum ctapi_funcs
{
unix_attach,
unix_detach,
unix_ct_init,
unix_ct_data,
unix_ct_close,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment