/** * Close the interface and free all allocated resources * * @param ctn Card terminal number * @return Status code \ref OK, \ref ERR_INVALID, \ref ERR_CT, \ref ERR_TRANS, \ref ERR_MEMORY, \ref ERR_HOST, \ref ERR_HTSI */ signed char CT_close(unsigned short ctn) { int rc; scr_t *ctx; if (mutex_lock(&globalmutex) != 0) { return ERR_CT; } rc = LookupReader(ctn); if (rc < 0) { mutex_unlock(&globalmutex); return ERR_CT; } ctx = readerTable[rc]; if (!ctx) { mutex_unlock(&globalmutex); return ERR_CT; } if (ctx->t1) { ccidT1Term(ctx); } USB_Close(&ctx->device); mutex_destroy(&ctx->mutex); free(ctx); readerTable[rc] = NULL; if (mutex_unlock(&globalmutex) != 0) { return ERR_CT; } mutexInitialized--; if (!mutexInitialized) { mutex_destroy(&globalmutex); } return OK; }
/** * Close the interface and free all allocated resources * * @param ctn Card terminal number * @return Status code \ref OK, \ref ERR_INVALID, \ref ERR_CT, \ref ERR_TRANS, \ref ERR_MEMORY, \ref ERR_HOST, \ref ERR_HTSI */ signed char CT_close(unsigned short ctn) { int rc; scr_t *ctx; if (mutex_lock(&mutex) != 0) { return ERR_MUTEX; } rc = LookupReader(ctn); if (rc < 0) { mutex_unlock(&mutex); return ERR_CT; } ctx = readerTable[rc]; if (!ctx) { mutex_unlock(&mutex); return ERR_CT; } if (ctx->t1) { ccidT1Term(ctx); } USB_Close(&ctx->device); mutex_destroy(&ctx->mutex); free(ctx); readerTable[rc] = NULL; if (mutex_unlock(&mutex) != 0) { return ERR_MUTEX; } if (InterlockedDecrement(&mutex_refcnt) == 0) { safe_mutex_destroy(); } return OK; }