cap20wxx.c 8.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24
 *
 */

#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
#ifdef SONAME_LIBCAPI20
47 48 49 50 51 52

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;
53
static unsigned (*pcapi20_isinstalled)(void) = NULL;
54 55 56 57 58
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;

59
static void load_functions(void) {
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
    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

85 86 87
/*===========================================================================*\
\*===========================================================================*/

88
DWORD WINAPI wrapCAPI_REGISTER (DWORD MessageBufferSize, DWORD maxLogicalConnection, DWORD maxBDataBlocks, DWORD maxBDataLen, DWORD *pApplID) {
89
#ifdef SONAME_LIBCAPI20
90
    unsigned aid = 0;
91 92 93 94 95 96
    DWORD fret;

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

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
108
DWORD WINAPI wrapCAPI_RELEASE (DWORD ApplID) {
109
#ifdef SONAME_LIBCAPI20
110 111 112 113 114 115
    DWORD fret;

    load_functions();
    if (!pcapi20_release)
        return 0x1109;
    fret = pcapi20_release (ApplID);
116
    TRACE ("(%x) -> %x\n", ApplID, fret);
117 118 119 120 121 122 123 124
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
125
DWORD WINAPI wrapCAPI_PUT_MESSAGE (DWORD ApplID, PVOID pCAPIMessage) {
126
#ifdef SONAME_LIBCAPI20
127 128 129 130 131 132
    DWORD fret;

    load_functions();
    if (!pcapi20_put_message)
        return 0x1109;
    fret = pcapi20_put_message (ApplID, pCAPIMessage);
133
    TRACE ("(%x) -> %x\n", ApplID, fret);
134 135 136 137 138 139 140 141
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
142
DWORD WINAPI wrapCAPI_GET_MESSAGE (DWORD ApplID, PVOID *ppCAPIMessage) {
143
#ifdef SONAME_LIBCAPI20
144 145 146 147 148 149
    DWORD fret;

    load_functions();
    if (!pcapi20_get_message)
        return 0x1109;
    fret = pcapi20_get_message (ApplID, (unsigned char **)ppCAPIMessage);
150
    TRACE ("(%x) -> %x\n", ApplID, fret);
151 152 153 154 155 156 157 158
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
159
DWORD WINAPI wrapCAPI_WAIT_FOR_SIGNAL (DWORD ApplID) {
160
#ifdef SONAME_LIBCAPI20
161
    TRACE ("(%x)\n", ApplID);
162 163 164 165 166 167

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

    return pcapi20_waitformessage (ApplID, NULL);
168 169 170 171 172 173 174
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
175
DWORD WINAPI wrapCAPI_GET_MANUFACTURER (char *SzBuffer) {
176
#ifdef SONAME_LIBCAPI20
177 178 179 180 181 182
    DWORD fret;

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

Uwe Bonnes's avatar
Uwe Bonnes committed
183
    fret = (pcapi20_get_manufacturer (0, (unsigned char *) SzBuffer) != 0) ? 0 : 0x1108;
184 185 186
    if (!strncmp (SzBuffer, "AVM", 3)) {
        strcpy (SzBuffer, "AVM-GmbH");
    }
187
    TRACE ("(%s) -> %x\n", SzBuffer, fret);
188 189 190 191 192 193 194 195
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
196
DWORD WINAPI wrapCAPI_GET_VERSION (DWORD *pCAPIMajor, DWORD *pCAPIMinor, DWORD *pManufacturerMajor, DWORD *pManufacturerMinor) {
197
#ifdef SONAME_LIBCAPI20
198
    unsigned char version[4 * sizeof (unsigned)];
199 200 201 202 203 204
    DWORD fret;

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

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
219
DWORD WINAPI wrapCAPI_GET_SERIAL_NUMBER (char *SzBuffer) {
220
#ifdef SONAME_LIBCAPI20
221 222 223 224 225
    DWORD fret;

    load_functions();
    if (!pcapi20_get_serial_number)
        return 0x1109;
Uwe Bonnes's avatar
Uwe Bonnes committed
226
    fret = (pcapi20_get_serial_number (0, (unsigned char*) SzBuffer) != 0) ? 0 : 0x1108;
227
    TRACE ("(%s) -> %x\n", SzBuffer, fret);
228 229 230 231 232 233 234 235
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
236
DWORD WINAPI wrapCAPI_GET_PROFILE (PVOID SzBuffer, DWORD CtlrNr) {
237
#ifdef SONAME_LIBCAPI20
238 239 240 241 242 243 244
    DWORD fret;

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

    fret = pcapi20_get_profile (CtlrNr, SzBuffer);
245
    TRACE ("(%x,%x) -> %x\n", CtlrNr, *(unsigned short *)SzBuffer, fret);
246 247 248 249 250 251 252 253
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
254
DWORD WINAPI wrapCAPI_INSTALLED (void) {
255
#ifdef SONAME_LIBCAPI20
256 257 258 259 260 261
    DWORD fret;

    load_functions();
    if (!pcapi20_isinstalled)
        return 0x1109;
    fret = pcapi20_isinstalled();
262
    TRACE ("() -> %x\n", fret);
263 264 265 266 267 268 269 270
    return fret;
#else
    return 0x1109;
#endif
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
271
DWORD WINAPI wrapCAPI_MANUFACTURER (DWORD Class, DWORD Function, DWORD Ctlr, PVOID pParams, DWORD ParamsLen) {
272 273 274 275 276 277
    FIXME ("(), not supported!\n");
    return 0x1109;
}

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