pcsc-lite 2.3.0
winscard_svc.c File Reference

This demarshalls functions over the message queue and keeps track of clients and their handles. More...

#include "config.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdbool.h>
#include "pcscd.h"
#include "winscard.h"
#include "debuglog.h"
#include "winscard_msg.h"
#include "winscard_svc.h"
#include "sys_generic.h"
#include "utils.h"
#include "readerfactory.h"
#include "eventhandler.h"
#include "simclist.h"
#include "auth.h"

Go to the source code of this file.

Data Structures

struct  _psContext
 

Macros

#define READ_BODY(v)
 
#define WRITE_BODY(v)    WRITE_BODY_WITH_COMMAND(CommandsText[header.command], v)
 
#define WRITE_BODY_WITH_COMMAND(command, v)
 

Typedefs

typedef struct _psContext SCONTEXT
 

Functions

static LONG MSGCheckHandleAssociation (SCARDHANDLE, SCONTEXT *)
 
static LONG MSGAddContext (SCARDCONTEXT, SCONTEXT *)
 
static LONG MSGRemoveContext (SCARDCONTEXT, SCONTEXT *)
 
static LONG MSGAddHandle (SCARDCONTEXT, SCARDHANDLE, SCONTEXT *)
 
static LONG MSGRemoveHandle (SCARDHANDLE, SCONTEXT *)
 
static void MSGCleanupClient (SCONTEXT *)
 
static void * ContextThread (LPVOID pdwIndex)
 
static int contextsListhContext_seeker (const void *el, const void *key)
 
LONG ContextsInitialize (int customMaxThreadCounter, int customMaxThreadCardHandles)
 
void ContextsDeinitialize (void)
 
LONG CreateContextThread (uint32_t *pdwClientID)
 Creates threads to handle messages received from Clients.
 
LONG MSGSignalClient (uint32_t filedes, LONG rv)
 
LONG MSGSendReaderStates (uint32_t filedes)
 

Variables

bool AutoExit
 Represents an Application Context on the Server side.
 
static int contextMaxThreadCounter = PCSC_MAX_CONTEXT_THREADS
 
static int contextMaxCardHandles = PCSC_MAX_CONTEXT_CARD_HANDLES
 
static list_t contextsList
 Context tracking list.
 
pthread_mutex_t contextsList_lock
 lock for the above list
 
READER_STATE readerStates [PCSCLITE_MAX_READERS_CONTEXTS]
 
int16_t ReaderEvents
 
static const char * CommandsText []
 Handles messages received from Clients.
 

Detailed Description

This demarshalls functions over the message queue and keeps track of clients and their handles.

Each Client message is deald by creating a thread (CreateContextThread). The thread establishes reands and demarshalls the message and calls the appropriate function to threat it.

Definition in file winscard_svc.c.

Macro Definition Documentation

◆ READ_BODY

#define READ_BODY ( v)
Value:
do { \
if (header.size != sizeof(v)) \
goto wrong_length; \
ret = MessageReceive(&v, sizeof(v), filedes); \
if (ret != SCARD_S_SUCCESS) { \
Log2(PCSC_LOG_DEBUG, "Client die: %d", filedes); \
goto exit; \
} \
} while (0)
#define SCARD_S_SUCCESS
No error was encountered.
Definition pcsclite.h:107
INTERNAL LONG MessageReceive(void *buffer_void, uint64_t buffer_size, int32_t filedes)
Called by the Client to get the response from the server or vice-versa.

Definition at line 331 of file winscard_svc.c.

◆ WRITE_BODY

#define WRITE_BODY ( v)     WRITE_BODY_WITH_COMMAND(CommandsText[header.command], v)

Definition at line 342 of file winscard_svc.c.

◆ WRITE_BODY_WITH_COMMAND

#define WRITE_BODY_WITH_COMMAND ( command,
v )
Value:
do { \
LogRv4(PCSC_LOG_DEBUG, v.rv, "%s for client %d", command, filedes); \
ret = MessageSend(&v, sizeof(v), filedes); \
} while (0)
INTERNAL LONG MessageSend(void *buffer_void, uint64_t buffer_size, int32_t filedes)
Sends a menssage from client to server or vice-versa.

Definition at line 344 of file winscard_svc.c.

Typedef Documentation

◆ SCONTEXT

typedef struct _psContext SCONTEXT

Definition at line 90 of file winscard_svc.c.

Function Documentation

◆ ContextsDeinitialize()

void ContextsDeinitialize ( void )

Definition at line 150 of file winscard_svc.c.

◆ ContextsInitialize()

LONG ContextsInitialize ( int customMaxThreadCounter,
int customMaxThreadCardHandles )

Definition at line 120 of file winscard_svc.c.

◆ contextsListhContext_seeker()

static int contextsListhContext_seeker ( const void * el,
const void * key )
static

Definition at line 104 of file winscard_svc.c.

◆ ContextThread()

static void * ContextThread ( LPVOID pdwIndex)
static

Definition at line 350 of file winscard_svc.c.

◆ CreateContextThread()

LONG CreateContextThread ( uint32_t * pdwClientID)

Creates threads to handle messages received from Clients.

Parameters
[in]pdwClientIDConnection ID used to reference the Client.
Returns
Error code.
Return values
SCARD_S_SUCCESSSuccess.
SCARD_F_INTERNAL_ERRORExceeded the maximum number of simultaneous Application Contexts.
SCARD_E_NO_MEMORYError creating the Context Thread.

Definition at line 192 of file winscard_svc.c.

◆ MSGAddContext()

static LONG MSGAddContext ( SCARDCONTEXT hContext,
SCONTEXT * threadContext )
static

Definition at line 891 of file winscard_svc.c.

◆ MSGAddHandle()

static LONG MSGAddHandle ( SCARDCONTEXT hContext,
SCARDHANDLE hCard,
SCONTEXT * threadContext )
static

Definition at line 999 of file winscard_svc.c.

◆ MSGCheckHandleAssociation()

static LONG MSGCheckHandleAssociation ( SCARDHANDLE hCard,
SCONTEXT * threadContext )
static

Definition at line 1067 of file winscard_svc.c.

◆ MSGCleanupClient()

static void MSGCleanupClient ( SCONTEXT * threadContext)
static

Definition at line 1097 of file winscard_svc.c.

◆ MSGRemoveContext()

static LONG MSGRemoveContext ( SCARDCONTEXT hContext,
SCONTEXT * threadContext )
static

Definition at line 897 of file winscard_svc.c.

◆ MSGRemoveHandle()

static LONG MSGRemoveHandle ( SCARDHANDLE hCard,
SCONTEXT * threadContext )
static

Definition at line 1050 of file winscard_svc.c.

◆ MSGSendReaderStates()

LONG MSGSendReaderStates ( uint32_t filedes)

Definition at line 879 of file winscard_svc.c.

◆ MSGSignalClient()

LONG MSGSignalClient ( uint32_t filedes,
LONG rv )

Definition at line 862 of file winscard_svc.c.

Variable Documentation

◆ AutoExit

bool AutoExit
extern

Represents an Application Context on the Server side.

An Application Context contains Channels (hCard).

Definition at line 74 of file pcscdaemon.c.

◆ CommandsText

const char* CommandsText[]
static
Initial value:
= {
"NULL",
"ESTABLISH_CONTEXT",
"RELEASE_CONTEXT",
"LIST_READERS",
"CONNECT",
"RECONNECT",
"DISCONNECT",
"BEGIN_TRANSACTION",
"END_TRANSACTION",
"TRANSMIT",
"CONTROL",
"STATUS",
"GET_STATUS_CHANGE",
"CANCEL",
"CANCEL_TRANSACTION",
"GET_ATTRIB",
"SET_ATTRIB",
"CMD_VERSION",
"CMD_GET_READERS_STATE",
"CMD_WAIT_READER_STATE_CHANGE",
"CMD_STOP_WAITING_READER_STATE_CHANGE",
"CMD_GET_READER_EVENTS",
"NULL"
}

Handles messages received from Clients.

For each Client message a new instance of this thread is created.

Parameters
[in]dwIndexIndex of an available Application Context slot in SCONTEXT *.

Definition at line 304 of file winscard_svc.c.

◆ contextMaxCardHandles

int contextMaxCardHandles = PCSC_MAX_CONTEXT_CARD_HANDLES
static

Definition at line 77 of file winscard_svc.c.

◆ contextMaxThreadCounter

int contextMaxThreadCounter = PCSC_MAX_CONTEXT_THREADS
static

Definition at line 76 of file winscard_svc.c.

◆ contextsList

list_t contextsList
static

Context tracking list.

Definition at line 79 of file winscard_svc.c.

◆ contextsList_lock

pthread_mutex_t contextsList_lock

lock for the above list

Definition at line 80 of file winscard_svc.c.

◆ ReaderEvents

int16_t ReaderEvents
extern

Definition at line 76 of file readerfactory.c.

◆ readerStates

Definition at line 68 of file readerfactory.c.