libchipcard 5.0.0

chipcard.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     begin       : Tue Dec 23 2003
00003     copyright   : (C) 2003 by Martin Preuss
00004     email       : martin@libchipcard.de
00005 
00006  ***************************************************************************
00007  *          Please see toplevel file COPYING for license details           *
00008  ***************************************************************************/
00009 
00010 
00011 #ifndef CHIPCARD_CHIPCARD_H
00012 #define CHIPCARD_CHIPCARD_H
00013 
00014 #define CHIPCARD_SYS_IS_WINDOWS 0
00015 
00016 
00017 #ifdef LCC_IS_SUBPROJECT
00018 # define CHIPCARD_API
00019 # define CHIPCARD_EXPORT
00020 # define CHIPCARD_NOEXPORT
00021 #else
00022 # ifdef BUILDING_CHIPCARD
00023    /* building Gwenhywfar */
00024 #  if CHIPCARD_SYS_IS_WINDOWS
00025      /* for windows */
00026 #    ifdef __declspec
00027 #      define CHIPCARD_API __declspec (dllexport)
00028 #    else /* if __declspec */
00029 #      define CHIPCARD_API
00030 #    endif /* if NOT __declspec */
00031 #  else
00032      /* for non-win32 */
00033 #    ifdef GCC_WITH_VISIBILITY_ATTRIBUTE
00034 #      define CHIPCARD_API __attribute__((visibility("default")))
00035 #    else
00036 #      define CHIPCARD_API
00037 #    endif
00038 #  endif
00039 # else
00040    /* not building Gwenhywfar */
00041 #  if CHIPCARD_SYS_IS_WINDOWS
00042      /* for windows */
00043 #    ifdef __declspec
00044 #      define CHIPCARD_API __declspec (dllimport)
00045 #    else /* if __declspec */
00046 #      define CHIPCARD_API
00047 #    endif /* if NOT __declspec */
00048 #  else
00049      /* for non-win32 */
00050 #    define CHIPCARD_API
00051 #  endif
00052 # endif
00053 
00054 # ifdef GCC_WITH_VISIBILITY_ATTRIBUTE
00055 #  define CHIPCARD_EXPORT __attribute__((visibility("default")))
00056 #  define CHIPCARD_NOEXPORT __attribute__((visibility("hidden")))
00057 # else
00058 #  define CHIPCARD_EXPORT
00059 #  define CHIPCARD_NOEXPORT
00060 # endif
00061 #endif
00062 
00063 
00064 #if CHIPCARD_SYS_IS_WINDOWS
00065 # define CHIPCARD_CB __stdcall
00066 #else
00067 # define CHIPCARD_CB
00068 #endif
00069 
00070 
00071 #ifndef CHIPCARD_NOWARN_DEPRECATED
00072 # ifdef __GNUC__
00073 #  define CHIPCARD_DEPRECATED __attribute((__deprecated__))
00074 # else
00075 #  define CHIPCARD_DEPRECATED
00076 # endif
00077 # else
00078 #  define CHIPCARD_DEPRECATED
00079 #endif
00080 
00081 #include <gwenhywfar/db.h>
00082 #include <gwenhywfar/xml.h>
00083 
00084 #include <inttypes.h>
00085 
00086 
00087 #define LC_DEFAULT_PORT 7392 /* FIXME: make this adjustable by configure */
00088 #define LC_DEFAULT_UDS_SOCK "/var/run/chipcard.comm"
00089 
00092 #define LC_ERROR_NONE                  0x00000000
00093 #define LC_ERROR_GENERIC               0x00000001
00094 #define LC_ERROR_INVALID               0x00000002
00095 #define LC_ERROR_CARD_REMOVED          0x00000003
00096 #define LC_ERROR_CARD_NOT_OWNED        0x00000004
00097 #define LC_ERROR_NOT_SUPPORTED         0x00000005
00098 #define LC_ERROR_SETUP                 0x00000006
00099 #define LC_ERROR_NO_DATA               0x00000007
00100 #define LC_ERROR_LOCKED_BY_OTHER       0x00000008
00101 #define LC_ERROR_NOT_LOCKED            0x00000009
00102 
00103 #define LC_ERROR_BAD_RESPONSE          0x0000000a
00104 #define LC_ERROR_NO_SLOTS_CONNECTED    0x0000000b
00105 #define LC_ERROR_NO_SLOTS_DISCONNECTED 0x0000000c
00106 #define LC_ERROR_NO_SLOTS_AVAILABLE    0x0000000d
00107 #define LC_ERROR_BAD_PIN               0x0000000e
00108 #define LC_ERROR_USER_ABORTED          0x0000000f
00109 #define LC_ERROR_CARD_DESTROYED        0x00000010
00110 #define LC_ERROR_READER_REMOVED        0x00000011
00111 #define LC_ERROR_TIMEOUT               0x00000012
00112 #define LC_ERROR_IPC                   0x00000013
00113 #define LC_ERROR_BUFFER_OVERFLOW       0x00000014
00114 
00115 const char *LC_Error_toString(uint32_t err);
00116 
00117 
00118 #define LC_LOGDOMAIN "ccclient"
00119 
00122 #define LC_READER_FLAGS_KEYPAD             0x00010000
00123 #define LC_READER_FLAGS_DISPLAY            0x00020000
00124 #define LC_READER_FLAGS_NOINFO             0x00040000
00125 #define LC_READER_FLAGS_REMOTE             0x00080000
00126 #define LC_READER_FLAGS_AUTO               0x00100000
00127 #define LC_READER_FLAGS_SUSPENDED_CHECKS   0x00200000
00128 #define LC_READER_FLAGS_DRIVER_HAS_VERIFY  0x00400000
00129 #define LC_READER_FLAGS_KEEP_RUNNING       0x00800000
00130 #define LC_READER_FLAGS_LOW_WRITE_BOUNDARY 0x01000000
00131 #define LC_READER_FLAGS_NO_MEMORY_SW       0x02000000
00132 
00134 CHIPCARD_API
00135 uint32_t LC_ReaderFlags_fromXml(GWEN_XMLNODE *node, const char *name);
00136 CHIPCARD_API
00137 uint32_t LC_ReaderFlags_fromDb(GWEN_DB_NODE *db, const char *name);
00138 CHIPCARD_API void LC_ReaderFlags_toDb(GWEN_DB_NODE *db,
00139                                       const char *name,
00140                                       uint32_t fl);
00141 
00143 #define LC_DRIVER_FLAGS_RUNTIME_MASK  0xffff0000
00144 #define LC_DRIVER_FLAGS_AUTO          0x00010000
00145 #define LC_DRIVER_FLAGS_REMOTE        0x00020000
00146 #define LC_DRIVER_FLAGS_CONFIG        0x00040000
00147 
00148 #define LC_DRIVER_FLAGS_HAS_VERIFY_FN 0x00000001
00149 #define LC_DRIVER_FLAGS_HAS_MODIFY_FN 0x00000002
00150 
00151 CHIPCARD_API
00152 uint32_t LC_DriverFlags_fromDb(GWEN_DB_NODE *db, const char *name);
00153 
00154 CHIPCARD_API
00155 int LC_DriverFlags_toDb(GWEN_DB_NODE *db,
00156                         const char *name,
00157                         uint32_t flags);
00158 
00159 
00161 #define LC_SERVICE_FLAGS_RUNTIME_MASK (\
00162     LC_SERVICE_FLAGS_CLIENT \
00163     )
00164 #define LC_SERVICE_FLAGS_CLIENT   0x00000001
00165 #define LC_SERVICE_FLAGS_AUTOLOAD 0x00000002
00166 #define LC_SERVICE_FLAGS_SILENT   0x00000004
00167 
00168 CHIPCARD_API
00169 uint32_t LC_ServiceFlags_fromDb(GWEN_DB_NODE *db, const char *name);
00170 CHIPCARD_API void LC_ServiceFlags_toDb(GWEN_DB_NODE *db,
00171                                        const char *name,
00172                                        uint32_t fl);
00173 
00174 
00177 #define LC_NOTIFY_FLAGS_DRIVER_MASK      0x0000003f
00178 #define LC_NOTIFY_FLAGS_DRIVER_START     0x00000001
00179 #define LC_NOTIFY_FLAGS_DRIVER_UP        0x00000002
00180 #define LC_NOTIFY_FLAGS_DRIVER_DOWN      0x00000004
00181 #define LC_NOTIFY_FLAGS_DRIVER_ERROR     0x00000008
00182 #define LC_NOTIFY_FLAGS_DRIVER_ADD       0x00000010
00183 #define LC_NOTIFY_FLAGS_DRIVER_DEL       0x00000020
00184 
00185 #define LC_NOTIFY_FLAGS_READER_MASK      0x00000fc0
00186 #define LC_NOTIFY_FLAGS_READER_START     0x00000040
00187 #define LC_NOTIFY_FLAGS_READER_UP        0x00000080
00188 #define LC_NOTIFY_FLAGS_READER_DOWN      0x00000100
00189 #define LC_NOTIFY_FLAGS_READER_ERROR     0x00000200
00190 #define LC_NOTIFY_FLAGS_READER_ADD       0x00000400
00191 #define LC_NOTIFY_FLAGS_READER_DEL       0x00000800
00192 
00193 #define LC_NOTIFY_FLAGS_SERVICE_MASK     0x0000f000
00194 #define LC_NOTIFY_FLAGS_SERVICE_START    0x00001000
00195 #define LC_NOTIFY_FLAGS_SERVICE_UP       0x00002000
00196 #define LC_NOTIFY_FLAGS_SERVICE_DOWN     0x00004000
00197 #define LC_NOTIFY_FLAGS_SERVICE_ERROR    0x00008000
00198 
00199 #define LC_NOTIFY_FLAGS_CARD_MASK        0x000f0000
00200 #define LC_NOTIFY_FLAGS_CARD_INSERTED    0x00010000
00201 #define LC_NOTIFY_FLAGS_CARD_REMOVED     0x00020000
00202 #define LC_NOTIFY_FLAGS_CARD_RFU1        0x00040000
00203 #define LC_NOTIFY_FLAGS_CARD_RFU2        0x00080000
00204 
00205 #define LC_NOTIFY_FLAGS_CLIENT_MASK      0xfff00000
00206 #define LC_NOTIFY_FLAGS_CLIENT_UP        0x00100000
00207 #define LC_NOTIFY_FLAGS_CLIENT_DOWN      0x00200000
00208 #define LC_NOTIFY_FLAGS_CLIENT_STARTWAIT 0x00400000
00209 #define LC_NOTIFY_FLAGS_CLIENT_STOPWAIT  0x00800000
00210 #define LC_NOTIFY_FLAGS_CLIENT_TAKECARD  0x01000000
00211 #define LC_NOTIFY_FLAGS_CLIENT_GOTCARD   0x02000000
00212 
00213 #define LC_NOTIFY_FLAGS_CLIENT_CMDSEND   0x04000000
00214 #define LC_NOTIFY_FLAGS_CLIENT_CMDRECV   0x08000000
00215 
00216 #define LC_NOTIFY_FLAGS_SINGLESHOT       0x80000000
00217 
00218 #define LC_NOTIFY_FLAGS_PRIVILEGED (\
00219   LC_NOTIFY_FLAGS_CLIENT_CMDSEND |\
00220   LC_NOTIFY_FLAGS_CLIENT_CMDRECV)
00221 
00222 CHIPCARD_API
00223 uint32_t LC_NotifyFlags_fromDb(GWEN_DB_NODE *db, const char *name);
00224 CHIPCARD_API void LC_NotifyFlags_toDb(GWEN_DB_NODE *db,
00225                                       const char *name,
00226                                       uint32_t fl);
00227 
00228 
00237 #define LC_NOTIFY_TYPE_DRIVER           "driver"
00238 #define LC_NOTIFY_CODE_DRIVER_START     "start"
00239 #define LC_NOTIFY_CODE_DRIVER_UP        "up"
00240 #define LC_NOTIFY_CODE_DRIVER_DOWN      "down"
00241 #define LC_NOTIFY_CODE_DRIVER_ERROR     "error"
00242 #define LC_NOTIFY_CODE_DRIVER_ADD       "add"
00243 #define LC_NOTIFY_CODE_DRIVER_DEL       "del"
00244 
00245 #define LC_NOTIFY_TYPE_READER           "reader"
00246 #define LC_NOTIFY_CODE_READER_START     "start"
00247 #define LC_NOTIFY_CODE_READER_UP        "up"
00248 #define LC_NOTIFY_CODE_READER_DOWN      "down"
00249 #define LC_NOTIFY_CODE_READER_ERROR     "error"
00250 #define LC_NOTIFY_CODE_READER_ADD       "add"
00251 #define LC_NOTIFY_CODE_READER_DEL       "del"
00252 
00253 #define LC_NOTIFY_TYPE_SERVICE          "service"
00254 #define LC_NOTIFY_CODE_SERVICE_START    "start"
00255 #define LC_NOTIFY_CODE_SERVICE_UP       "up"
00256 #define LC_NOTIFY_CODE_SERVICE_DOWN     "down"
00257 #define LC_NOTIFY_CODE_SERVICE_ERROR    "error"
00258 
00259 #define LC_NOTIFY_TYPE_CARD             "card"
00260 #define LC_NOTIFY_CODE_CARD_INSERTED    "inserted"
00261 #define LC_NOTIFY_CODE_CARD_REMOVED     "removed"
00262 #define LC_NOTIFY_CODE_CARD_RFU1        "rfu1"
00263 #define LC_NOTIFY_CODE_CARD_RFU2        "rfu2"
00264 
00265 #define LC_NOTIFY_TYPE_CLIENT           "client"
00266 #define LC_NOTIFY_CODE_CLIENT_UP        "up"
00267 #define LC_NOTIFY_CODE_CLIENT_DOWN      "down"
00268 #define LC_NOTIFY_CODE_CLIENT_STARTWAIT "startwait"
00269 #define LC_NOTIFY_CODE_CLIENT_STOPWAIT  "stopwait"
00270 #define LC_NOTIFY_CODE_CLIENT_TAKECARD  "takecard"
00271 #define LC_NOTIFY_CODE_CLIENT_GOTCARD   "gotcard"
00272 
00273 #define LC_NOTIFY_CODE_CLIENT_CMDSEND   "cmdsend"
00274 #define LC_NOTIFY_CODE_CLIENT_CMDRECV   "cmdrecv"
00275 
00280 typedef enum {
00281   LC_DriverStatusDown=0,
00282   LC_DriverStatusWaitForStart,
00283   LC_DriverStatusStarted,
00284   LC_DriverStatusUp,
00285   LC_DriverStatusStopping,
00286   LC_DriverStatusAborted,
00287   LC_DriverStatusDisabled,
00288   LC_DriverStatusUnknown=999
00289 } LC_DRIVER_STATUS;
00290 
00291 CHIPCARD_API LC_DRIVER_STATUS LC_DriverStatus_fromString(const char *s);
00292 CHIPCARD_API const char *LC_DriverStatus_toString(LC_DRIVER_STATUS dst);
00293 
00294 
00295 typedef enum {
00296   LC_ReaderStatusDown=0,
00297   LC_ReaderStatusWaitForStart,
00298   LC_ReaderStatusWaitForDriver,
00299   LC_ReaderStatusWaitForReaderUp,
00300   LC_ReaderStatusWaitForReaderDown,
00301   LC_ReaderStatusUp,
00302   LC_ReaderStatusAborted,
00303   LC_ReaderStatusDisabled,
00304   LC_ReaderStatusHwAdd=900,  /* internal status code */
00305   LC_ReaderStatusHwDel=901,  /* internal status code */
00306   LC_ReaderStatusUnknown=999
00307 } LC_READER_STATUS;
00308 
00309 CHIPCARD_API LC_READER_STATUS LC_ReaderStatus_fromString(const char *s);
00310 CHIPCARD_API const char *LC_ReaderStatus_toString(LC_READER_STATUS rst);
00311 
00312 
00313 typedef enum {
00314   LC_ServiceStatusDown=0,
00315   LC_ServiceStatusWaitForStart,
00316   LC_ServiceStatusStarted,
00317   LC_ServiceStatusUp,
00318   LC_ServiceStatusSilentRunning,
00319   LC_ServiceStatusStopping,
00320   LC_ServiceStatusAborted,
00321   LC_ServiceStatusDisabled,
00322   LC_ServiceStatusUnknown=999
00323 } LC_SERVICE_STATUS;
00324 
00325 CHIPCARD_API LC_SERVICE_STATUS LC_ServiceStatus_fromString(const char *s);
00326 CHIPCARD_API const char *LC_ServiceStatus_toString(LC_SERVICE_STATUS st);
00327 
00328 
00329 typedef enum {
00330   LC_CardStatusInserted=0,
00331   LC_CardStatusRemoved,
00332   LC_CardStatusOrphaned,
00333 
00334   LC_CardStatusUnknown=999
00335 } LC_CARD_STATUS;
00336 
00337 
00338 typedef enum {
00339   LC_CardTypeUnknown=0,
00340   LC_CardTypeProcessor,
00341   LC_CardTypeMemory
00342 } LC_CARD_TYPE;
00343 
00344 
00345 #endif /* CHIPCARD_CHIPCARD_H */