"Fossies" - the Fresh Open Source Software Archive

Member "gnupg-2.2.17/scd/apdu.h" (9 Jul 2019, 5954 Bytes) of package /linux/misc/gnupg-2.2.17.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "apdu.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.2.13_vs_2.2.14.

    1 /* apdu.h - ISO 7816 APDU functions and low level I/O
    2  * Copyright (C) 2003, 2008 Free Software Foundation, Inc.
    3  *
    4  * This file is part of GnuPG.
    5  *
    6  * GnuPG is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 3 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * GnuPG is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, see <https://www.gnu.org/licenses/>.
   18  *
   19  * $Id$
   20  */
   21 
   22 #ifndef APDU_H
   23 #define APDU_H
   24 
   25 /* ISO 7816 values for the statusword are defined here because they
   26    should not be visible to the users of the actual ISO command
   27    API. */
   28 enum {
   29   SW_MORE_DATA      = 0x6100, /* Note: that the low byte must be
   30                                  masked of.*/
   31   SW_EOF_REACHED    = 0x6282,
   32   SW_TERM_STATE     = 0x6285, /* Selected file is in termination state.  */
   33   SW_EEPROM_FAILURE = 0x6581,
   34   SW_WRONG_LENGTH   = 0x6700,
   35   SW_SM_NOT_SUP     = 0x6882, /* Secure Messaging is not supported.  */
   36   SW_CC_NOT_SUP     = 0x6884, /* Command Chaining is not supported.  */
   37   SW_CHV_WRONG      = 0x6982,
   38   SW_CHV_BLOCKED    = 0x6983,
   39   SW_REF_DATA_INV   = 0x6984, /* Referenced data invalidated. */
   40   SW_USE_CONDITIONS = 0x6985,
   41   SW_BAD_PARAMETER  = 0x6a80, /* (in the data field) */
   42   SW_NOT_SUPPORTED  = 0x6a81,
   43   SW_FILE_NOT_FOUND = 0x6a82,
   44   SW_RECORD_NOT_FOUND = 0x6a83,
   45   SW_NOT_ENOUGH_MEMORY= 0x6a84, /* Not enough memory space in the file.  */
   46   SW_INCONSISTENT_LC  = 0x6a85, /* Lc inconsistent with TLV structure.  */
   47   SW_INCORRECT_P0_P1  = 0x6a86,
   48   SW_BAD_LC         = 0x6a87, /* Lc does not match command or p1/p2.  */
   49   SW_REF_NOT_FOUND  = 0x6a88,
   50   SW_BAD_P0_P1      = 0x6b00,
   51   SW_EXACT_LENGTH   = 0x6c00,
   52   SW_INS_NOT_SUP    = 0x6d00,
   53   SW_CLA_NOT_SUP    = 0x6e00,
   54   SW_SUCCESS        = 0x9000,
   55 
   56   /* The following statuswords are no real ones but used to map host
   57      OS errors into status words.  A status word is 16 bit so that
   58      those values can't be issued by a card. */
   59   SW_HOST_OUT_OF_CORE = 0x10001,  /* No way yet to differentiate
   60                                      between errnos on a failed malloc. */
   61   SW_HOST_INV_VALUE     = 0x10002,
   62   SW_HOST_INCOMPLETE_CARD_RESPONSE = 0x10003,
   63   SW_HOST_NO_DRIVER     = 0x10004,
   64   SW_HOST_NOT_SUPPORTED = 0x10005,
   65   SW_HOST_LOCKING_FAILED= 0x10006,
   66   SW_HOST_BUSY          = 0x10007,
   67   SW_HOST_NO_CARD       = 0x10008,
   68   SW_HOST_CARD_INACTIVE = 0x10009,
   69   SW_HOST_CARD_IO_ERROR = 0x1000a,
   70   SW_HOST_GENERAL_ERROR = 0x1000b,
   71   SW_HOST_NO_READER     = 0x1000c,
   72   SW_HOST_ABORTED       = 0x1000d,
   73   SW_HOST_NO_PINPAD     = 0x1000e,
   74   SW_HOST_ALREADY_CONNECTED = 0x1000f,
   75   SW_HOST_CANCELLED     = 0x10010
   76 };
   77 
   78 struct dev_list;
   79 
   80 #define SW_EXACT_LENGTH_P(a) (((a)&~0xff) == SW_EXACT_LENGTH)
   81 
   82 
   83 /* Bit flags for the card status.  */
   84 #define APDU_CARD_USABLE   (1)    /* Card is present and ready for use.  */
   85 #define APDU_CARD_PRESENT  (2)    /* Card is just present.  */
   86 #define APDU_CARD_ACTIVE   (4)    /* Card is active.  */
   87 
   88 
   89 gpg_error_t apdu_init (void);
   90 
   91 gpg_error_t apdu_dev_list_start (const char *portstr, struct dev_list **l_p);
   92 void apdu_dev_list_finish (struct dev_list *l);
   93 
   94 /* Note, that apdu_open_reader returns no status word but -1 on error. */
   95 int apdu_open_reader (struct dev_list *l, int app_empty);
   96 int apdu_open_remote_reader (const char *portstr,
   97                              const unsigned char *cookie, size_t length,
   98                              int (*readfnc) (void *opaque,
   99                                              void *buffer, size_t size),
  100                              void *readfnc_value,
  101                              int (*writefnc) (void *opaque,
  102                                               const void *buffer, size_t size),
  103                              void *writefnc_value,
  104                              void (*closefnc) (void *opaque),
  105                              void *closefnc_value);
  106 int apdu_close_reader (int slot);
  107 void apdu_prepare_exit (void);
  108 int apdu_enum_reader (int slot, int *used);
  109 unsigned char *apdu_get_atr (int slot, size_t *atrlen);
  110 
  111 const char *apdu_strerror (int rc);
  112 
  113 
  114 /* These APDU functions return status words. */
  115 
  116 int apdu_connect (int slot);
  117 int apdu_disconnect (int slot);
  118 
  119 int apdu_set_progress_cb (int slot, gcry_handler_progress_t cb, void *cb_arg);
  120 int apdu_set_prompt_cb (int slot, void (*cb) (void *, int), void *cb_arg);
  121 
  122 int apdu_reset (int slot);
  123 int apdu_get_status (int slot, int hang, unsigned int *status);
  124 int apdu_check_pinpad (int slot, int command, pininfo_t *pininfo);
  125 int apdu_pinpad_verify (int slot, int class, int ins, int p0, int p1,
  126                         pininfo_t *pininfo);
  127 int apdu_pinpad_modify (int slot, int class, int ins, int p0, int p1,
  128                         pininfo_t *pininfo);
  129 int apdu_send_simple (int slot, int extended_mode,
  130                       int class, int ins, int p0, int p1,
  131                       int lc, const char *data);
  132 int apdu_send (int slot, int extended_mode,
  133                int class, int ins, int p0, int p1, int lc, const char *data,
  134                unsigned char **retbuf, size_t *retbuflen);
  135 int apdu_send_le (int slot, int extended_mode,
  136                   int class, int ins, int p0, int p1,
  137                   int lc, const char *data, int le,
  138                   unsigned char **retbuf, size_t *retbuflen);
  139 int apdu_send_direct (int slot, size_t extended_length,
  140                       const unsigned char *apdudata, size_t apdudatalen,
  141                       int handle_more, unsigned int *r_sw,
  142                       unsigned char **retbuf, size_t *retbuflen);
  143 const char *apdu_get_reader_name (int slot);
  144 
  145 #endif /*APDU_H*/