cap20wxx.c 8.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * cap20wxx.c
 *
 * Copyright 2002-2003 AVM Computersysteme Vertriebs GmbH
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#define __NO_CAPIUTILS__

#include "config.h"
25
#include "wine/port.h"
26 27 28

#include <stdio.h>
#include <sys/types.h>
29 30 31
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
32

33
#define __user
34 35 36 37 38 39
#ifdef HAVE_LINUX_CAPI_H
# include <linux/capi.h>
#endif
#ifdef HAVE_CAPI20_H
# include <capi20.h>
#endif
40
#include "wine/library.h"
41 42 43 44 45
#include "wine/debug.h"
#include "cap20wxx.h"

WINE_DEFAULT_DEBUG_CHANNEL(capi);

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#ifdef HAVE_CAPI4LINUX

#ifndef SONAME_LIBCAPI20
#define SONAME_LIBCAPI20 "libcapi20.so"
#endif

static unsigned (*pcapi20_register)(unsigned, unsigned, unsigned, unsigned *) = NULL;
static unsigned (*pcapi20_release)(unsigned) = NULL;
static unsigned (*pcapi20_put_message)(unsigned, unsigned char *) = NULL;
static unsigned (*pcapi20_get_message)(unsigned, unsigned char **) = NULL;
static unsigned (*pcapi20_waitformessage)(unsigned, struct timeval *) = NULL;
static unsigned (*pcapi20_isinstalled)() = NULL;
static unsigned (*pcapi20_get_profile)(unsigned, unsigned char *) = NULL;
static unsigned char *(*pcapi20_get_manufacturer)(unsigned, unsigned char *) = NULL;
static unsigned char *(*pcapi20_get_serial_number)(unsigned, unsigned char *) = NULL;
static unsigned char *(*pcapi20_get_version)(unsigned, unsigned char *) = NULL;

static void load_functions() {
    void *capi_handle = NULL;

    if (pcapi20_register) /* loaded already */
	return;
    capi_handle = wine_dlopen(SONAME_LIBCAPI20, RTLD_NOW, NULL, 0);
    if(!capi_handle) {
        FIXME("Wine cannot find the library %s, capi2032.dll not working.\n", SONAME_LIBCAPI20);
        return;
    }
#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(capi_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f); return;}
LOAD_FUNCPTR(capi20_register);
LOAD_FUNCPTR(capi20_release);
LOAD_FUNCPTR(capi20_put_message);
LOAD_FUNCPTR(capi20_get_message);
LOAD_FUNCPTR(capi20_waitformessage);
LOAD_FUNCPTR(capi20_isinstalled);
LOAD_FUNCPTR(capi20_get_profile);
LOAD_FUNCPTR(capi20_get_manufacturer);
LOAD_FUNCPTR(capi20_get_serial_number);
LOAD_FUNCPTR(capi20_get_version);
#undef LOAD_FUNCPTR
}

#endif

89 90 91
/*===========================================================================*\
\*===========================================================================*/

92
DWORD WINAPI wrapCAPI_REGISTER (DWORD MessageBufferSize, DWORD maxLogicalConnection, DWORD maxBDataBlocks, DWORD maxBDataLen, DWORD *pApplID) {
93 94
#ifdef HAVE_CAPI4LINUX
    unsigned aid = 0;
95 96 97 98 99 100
    DWORD fret;

    load_functions();
    if (!pcapi20_register)
        return 0x1009;
    fret = pcapi20_register (maxLogicalConnection, maxBDataBlocks, maxBDataLen, &aid);
101 102 103 104
    *pApplID   = aid;
    TRACE ( "(%lx) -> %lx\n", *pApplID, fret);
    return fret;
#else
105
    FIXME ( "(), no CAPI4LINUX support compiled into WINE.\n" );
106 107 108 109 110 111
    return 0x1009;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
112
DWORD WINAPI wrapCAPI_RELEASE (DWORD ApplID) {
113
#ifdef HAVE_CAPI4LINUX
114 115 116 117 118 119
    DWORD fret;

    load_functions();
    if (!pcapi20_release)
        return 0x1109;
    fret = pcapi20_release (ApplID);
120 121 122 123 124 125 126 127 128
    TRACE ("(%lx) -> %lx\n", ApplID, fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
129
DWORD WINAPI wrapCAPI_PUT_MESSAGE (DWORD ApplID, PVOID pCAPIMessage) {
130
#ifdef HAVE_CAPI4LINUX
131 132 133 134 135 136
    DWORD fret;

    load_functions();
    if (!pcapi20_put_message)
        return 0x1109;
    fret = pcapi20_put_message (ApplID, pCAPIMessage);
137 138 139 140 141 142 143 144 145
    TRACE ("(%lx) -> %lx\n", ApplID, fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
146
DWORD WINAPI wrapCAPI_GET_MESSAGE (DWORD ApplID, PVOID *ppCAPIMessage) {
147
#ifdef HAVE_CAPI4LINUX
148 149 150 151 152 153
    DWORD fret;

    load_functions();
    if (!pcapi20_get_message)
        return 0x1109;
    fret = pcapi20_get_message (ApplID, (unsigned char **)ppCAPIMessage);
154 155 156 157 158 159 160 161 162
    TRACE ("(%lx) -> %lx\n", ApplID, fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
163
DWORD WINAPI wrapCAPI_WAIT_FOR_SIGNAL (DWORD ApplID) {
164 165
#ifdef HAVE_CAPI4LINUX
    TRACE ("(%lx)\n", ApplID);
166 167 168 169 170 171

    load_functions();
    if (!pcapi20_waitformessage)
        return 0x1109;

    return pcapi20_waitformessage (ApplID, NULL);
172 173 174 175 176 177 178
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
179
DWORD WINAPI wrapCAPI_GET_MANUFACTURER (char *SzBuffer) {
180
#ifdef HAVE_CAPI4LINUX
181 182 183 184 185 186 187
    DWORD fret;

    load_functions();
    if (!pcapi20_get_manufacturer)
        return 0x1109;

    fret = (pcapi20_get_manufacturer (0, SzBuffer) != 0) ? 0 : 0x1108;
188 189 190 191 192 193 194 195 196 197 198 199
    if (!strncmp (SzBuffer, "AVM", 3)) {
        strcpy (SzBuffer, "AVM-GmbH");
    }
    TRACE ("(%s) -> %lx\n", SzBuffer, fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
200
DWORD WINAPI wrapCAPI_GET_VERSION (DWORD *pCAPIMajor, DWORD *pCAPIMinor, DWORD *pManufacturerMajor, DWORD *pManufacturerMinor) {
201 202
#ifdef HAVE_CAPI4LINUX
    unsigned char version[4 * sizeof (unsigned)];
203 204 205 206 207 208
    DWORD fret;

    load_functions();
    if (!pcapi20_get_version)
        return 0x1109;
    fret = (pcapi20_get_version (0, version) != 0) ? 0 : 0x1108;
209 210 211 212 213 214 215 216 217 218 219 220 221 222
    *pCAPIMajor         = *(unsigned *)(version + 0 * sizeof (unsigned));
    *pCAPIMinor         = *(unsigned *)(version + 1 * sizeof (unsigned));
    *pManufacturerMajor = *(unsigned *)(version + 2 * sizeof (unsigned));
    *pManufacturerMinor = *(unsigned *)(version + 3 * sizeof (unsigned));
    TRACE ("(%lx.%lx,%lx.%lx) -> %lx\n", *pCAPIMajor, *pCAPIMinor, *pManufacturerMajor,
             *pManufacturerMinor, fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
223
DWORD WINAPI wrapCAPI_GET_SERIAL_NUMBER (char *SzBuffer) {
224
#ifdef HAVE_CAPI4LINUX
225 226 227 228 229 230
    DWORD fret;

    load_functions();
    if (!pcapi20_get_serial_number)
        return 0x1109;
    fret = (pcapi20_get_serial_number (0, SzBuffer) != 0) ? 0 : 0x1108;
231 232 233 234 235 236 237 238 239
    TRACE ("(%s) -> %lx\n", SzBuffer, fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
240
DWORD WINAPI wrapCAPI_GET_PROFILE (PVOID SzBuffer, DWORD CtlrNr) {
241
#ifdef HAVE_CAPI4LINUX
242 243 244 245 246 247 248
    DWORD fret;

    load_functions();
    if (!pcapi20_get_profile)
        return 0x1109;

    fret = pcapi20_get_profile (CtlrNr, SzBuffer);
249 250 251 252 253 254 255 256 257
    TRACE ("(%lx,%x) -> %lx\n", CtlrNr, *(unsigned short *)SzBuffer, fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
258
DWORD WINAPI wrapCAPI_INSTALLED (void) {
259
#ifdef HAVE_CAPI4LINUX
260 261 262 263 264 265
    DWORD fret;

    load_functions();
    if (!pcapi20_isinstalled)
        return 0x1109;
    fret = pcapi20_isinstalled();
266 267 268 269 270 271 272 273 274
    TRACE ("() -> %lx\n", fret);
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
275
DWORD WINAPI wrapCAPI_MANUFACTURER (DWORD Class, DWORD Function, DWORD Ctlr, PVOID pParams, DWORD ParamsLen) {
276 277 278 279 280 281
    FIXME ("(), not supported!\n");
    return 0x1109;
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/