VPCD: partial rewrite of socket communication

- memory for buffer of received data is now reused with realloc
- internal functions now use a similar interface like recv/send/...
- added documentation about memory handling of vicc_getatr/vicc_transmit
- fixed transmit when using send in multiple passes
This commit is contained in:
Frank Morgner
2012-08-13 00:19:58 +02:00
parent 3adf5b1e60
commit 01c9f00a33
4 changed files with 178 additions and 130 deletions

View File

@@ -19,25 +19,51 @@
#ifndef _VPCD_H_
#define _VPCD_H_
#include <stdint.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Standard port of the virtual smart card reader */
#define VPCDPORT 35963
int vicc_eject(void);
int vicc_init(unsigned short port);
int vicc_exit(void);
int vicc_transmit(int apdu_len, const char *apdu, char **rapdu);
int vicc_getatr(char** atr);
int vicc_eject(void);
int vicc_present(void);
int vicc_poweron(void);
int vicc_poweroff(void);
int vicc_reset(void);
/**
* @brief Receive ATR from the virtual smart card.
*
* @param[in,out] atr ATR received. Memory will be reused (via \a realloc) and
* should be freed by the caller if no longer needed.
*
* @return On success, the call returns the number of bytes received.
* On error, -1 is returned, and errno is set appropriately.
*/
ssize_t vicc_getatr(unsigned char** atr);
/**
* @brief Send an APDU to the virtual smart card.
*
* @param[in] apdu_len Number of bytes to send
* @param[in] apdu Data to be sent
* @param[in,out] rapdu Data received. Memory will be reused (via \a
* realloc) and should be freed by the caller if no
* longer needed.
*
* @return On success, the call returns the number of bytes received.
* On error, -1 is returned, and errno is set appropriately.
*/
ssize_t vicc_transmit(size_t apdu_len, const unsigned char *apdu,
unsigned char **rapdu);
#ifdef __cplusplus
}
#endif