From cb96784ed889be9a17e1d938efc63630280015c5 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Thu, 24 Jul 2014 23:06:13 +0200 Subject: [PATCH] include non exported OpenSC functions --- npa/src/boxing.c | 8 +------- npa/src/card-npa.c | 4 ---- npa/src/npa/scutil.h | 31 +++++++++++++++++++++++++++++++ npa/src/scutil.c | 15 +++++++++++++++ 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/npa/src/boxing.c b/npa/src/boxing.c index 4dca68e..c38e658 100644 --- a/npa/src/boxing.c +++ b/npa/src/boxing.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -39,13 +40,6 @@ #include #endif -#if HAVE_SC_APDU_GET_OCTETS -#include "libopensc/internal.h" -#else -/* Pull request for exporting sc_apdu_get_octets is pending. */ -#include "libopensc/apdu.c" -#endif - static const u8 boxing_cla = 0xff; static const u8 boxing_ins = 0x9a; static const u8 boxing_p1 = 0x04; diff --git a/npa/src/card-npa.c b/npa/src/card-npa.c index ccc0449..d78abf5 100644 --- a/npa/src/card-npa.c +++ b/npa/src/card-npa.c @@ -26,10 +26,6 @@ #include #include -#ifndef HAVE_SC_APDU_GET_OCTETS -#include "libopensc/card.c" -#endif - struct npa_drv_data { unsigned char *can; size_t can_length; diff --git a/npa/src/npa/scutil.h b/npa/src/npa/scutil.h index 79131a7..31e0098 100644 --- a/npa/src/npa/scutil.h +++ b/npa/src/npa/scutil.h @@ -116,5 +116,36 @@ int read_binary_rec(sc_card_t *card, unsigned char sfid, int write_binary_rec(sc_card_t *card, unsigned char sfid, u8 *ef, size_t ef_len); +/* + * OPENSC functions that do not get exported (sometimes) + */ + +/** + * Returns the encoded APDU in newly created buffer. + * @param ctx sc_context_t object + * @param apdu sc_apdu_t object with the APDU to encode + * @param buf pointer to the newly allocated buffer + * @param len length of the encoded APDU + * @param proto protocol to be used + * @return SC_SUCCESS on success and an error code otherwise + */ +int sc_apdu_get_octets(sc_context_t *ctx, const sc_apdu_t *apdu, u8 **buf, + size_t *len, unsigned int proto); + +/** + * Sets the status bytes and return data in the APDU + * @param ctx sc_context_t object + * @param apdu the apdu to which the data should be written + * @param buf returned data + * @param len length of the returned data + * @return SC_SUCCESS on success and an error code otherwise + */ +int sc_apdu_set_resp(sc_context_t *ctx, sc_apdu_t *apdu, const u8 *buf, + size_t len); + +/* Returns an index number if a match was found, -1 otherwise. table has to + * be null terminated. */ +int _sc_match_atr(struct sc_card *card, struct sc_atr_table *table, int *type_out); + #endif /* @} */ diff --git a/npa/src/scutil.c b/npa/src/scutil.c index 403c79f..e48368e 100644 --- a/npa/src/scutil.c +++ b/npa/src/scutil.c @@ -20,6 +20,21 @@ #include "config.h" #endif +#include "libopensc/internal.h" + +#if !defined(HAVE_SC_APDU_GET_OCTETS) || !defined(HAVE_SC_APDU_SET_RESP) +/* Pull request for exporting sc_apdu_get_octets is pending. */ +#include "libopensc/apdu.c" +#endif + +#ifndef HAVE__SC_MATCH_ATR +/* I hate to do this, but to include _sc_match_atr we need to satisfy all + * dependencies of card.c */ +#include "common/libscdl.c" +#include "libopensc/sc.c" +#include "libopensc/card.c" +#endif + #include #include #include