您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 最新PCSC CCID 测试源码
  所属分类: 系统安全
  开发工具:
  文件大小: 1mb
  下载次数: 0
  上传时间: 2011-06-23
  提 供 者: yzx19******
 详细说明: 最新的PCSC、CCID以及测试源码。 贴一段源码: LONG SCardEstablishContext(DWORD dwScope, /*@unused@*/ LPCVOID pvReserved1, /*@unused@*/ LPCVOID pvReserved2, LPSCARDCONTEXT phContext) { (void)pvReserved1; (void)pvReserved2; if (dwScope != SCARD_SCOPE_USER && dwScope != SCARD_SCOPE_TERMINAL && dwScope != SCARD_SCOPE_SYSTEM && dwScope != SCARD_SCOPE_GLOBAL) { *phContext = 0; return SCARD_E_INVALID_VALUE; } /* * Unique identifier for this server so that it can uniquely be * identified by clients and distinguis hed from others */ *phContext = (PCSCLITE_SVC_IDENTITY + SYS_RandomInt(1, 65535)); Log2(PCSC_LOG_DEBUG, "Establishing Context: 0x%X", *phContext); return SCARD_S_SUCCESS; } LONG SCardReleaseContext(SCARDCONTEXT hContext) { /* * Nothing to do here RPC layer will handle this */ Log2(PCSC_LOG_DEBUG, "Releasing Context: 0x%X", hContext); return SCARD_S_SUCCESS; } LONG SCardConnect(/*@unused@*/ SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) { LONG rv; READER_CONTEXT * rContext = NULL; uint32_t readerState; (void)hContext; PROFILE_START *phCard = 0; if ((dwShareMode != SCARD_SHARE_DIRECT) && !(dwPreferredProtocols & SCARD_PROTOCOL_T0) && !(dwPreferredProtocols & SCARD_PROTOCOL_T1) && !(dwPreferredProtocols & SCARD_PROTOCOL_RAW) && !(dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD)) return SCARD_E_PROTO_MISMATCH; if (dwShareMode != SCARD_SHARE_EXCLUSIVE && dwShareMode != SCARD_SHARE_SHARED && dwShareMode != SCARD_SHARE_DIRECT) return SCARD_E_INVALID_VALUE; Log3(PCSC_LOG_DEBUG, "Attempting Connect to %s using protocol: %d", szReader, dwPreferredProtocols); rv = RFReaderInfo((LPSTR) szReader, &rContext); if (rv != SCARD_S_SUCCESS) { Log2(PCSC_LOG_ERROR, "Reader %s Not Found", szReader); return rv; } /* * Make sure the reader is working properly */ rv = RFCheckReaderStatus(rContext); if (rv != SCARD_S_SUCCESS) return rv; /******************************************* * * This section checks for simple errors * *******************************************/ /* * Connect if not exclusive mode */ if (rContext->contexts == PCSCLITE_SHARING_EXCLUSIVE_CONTEXT) { Log1(PCSC_LOG_ERROR, "Error Reader Exclusive"); return SCARD_E_SHARING_VIOLATION; } /* * wait until a possible transaction is finished */ if (rContext->hLockId != 0) { Log1(PCSC_LOG_INFO, "Waiting for release of lock"); while (rContext->hLockId != 0) (void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE); Log1(PCSC_LOG_INFO, "Lock released"); } /******************************************* * * This section tries to determine the * presence of a card or not * *******************************************/ readerState = rContext->readerState->readerState; if (dwShareMode != SCARD_SHARE_DIRECT) { if (!(readerState & SCARD_PRESENT)) { Log1(PCSC_LOG_ERROR, "Card Not Inserted"); return SCARD_E_NO_SMARTCARD; } /* Power on (again) the card if needed */ (void)pthread_mutex_lock(&rContext->powerState_lock); if (POWER_STATE_UNPOWERED == rContext->powerState) { DWORD dwAtrLen; dwAtrLen = sizeof(rContext->readerState->cardAtr); rv = IFDPowerICC(rContext, IFD_POWER_UP, rContext->readerState->cardAtr, &dwAtrLen); rContext->readerState->cardAtrLength = dwAtrLen; if (rv == IFD_SUCCESS) { readerState = SCARD_PRESENT | SCARD_POWERED | SCARD_NEGOTIABLE; Log1(PCSC_LOG_DEBUG, "power up complete."); LogXxd(PCSC_LOG_DEBUG, "Card ATR: ", rContext->readerState->cardAtr, rContext->readerState->cardAtrLength); } else Log3(PCSC_LOG_ERROR, "Error powering up card: %d 0x%04X", rv, rv); } if (! (readerState & SCARD_POWERED)) { Log1(PCSC_LOG_ERROR, "Card Not Powered"); (void)pthread_mutex_unlock(&rContext->powerState_lock); return SCARD_W_UNPOWERED_CARD; } /* the card is now in use */ rContext->powerState = POWER_STATE_INUSE; Log1(PCSC_LOG_DEBUG, "powerState: POWER_STATE_INUSE"); (void)pthread_mutex_unlock(&rContext->powerState_lock); } /******************************************* * * This section tries to decode the ATR * and set up which protocol to use * *******************************************/ if (dwPreferredProtocols & SCARD_PROTOCOL_RAW) rContext->readerState->cardProtocol = SCARD_PROTOCOL_RAW; else { if (dwShareMode != SCARD_SHARE_DIRECT) { /* lock here instead in IFDSetPTS() to lock up to * setting rContext->readerState->cardProtocol */ (void)pthread_mutex_lock(rContext->mMutex); /* the protocol is not yet set (no PPS yet) */ if (SCARD_PROTOCOL_UNDEFINED == rContext->readerState->cardProtocol) { UCHAR ucAvailable, ucDefault; int ret; ucDefault = PHGetDefaultProtocol(rContext->readerState->cardAtr, rContext->readerState->cardAtrLength); ucAvailable = PHGetAvailableProtocols(rContext->readerState->cardAtr, rContext->readerState->cardAtrLength); /* * If it is set to ANY let it do any of the protocols */ if (dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD) dwPreferredProtocols = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1; ret = PHSetProtocol(rContext, dwPreferredProtocols, ucAvailable, ucDefault); /* keep cardProtocol = SCARD_PROTOCOL_UNDEFINED in case of error */ if (SET_PROTOCOL_PPS_FAILED == ret) { (void)pthread_mutex_unlock(rContext->mMutex); return SCARD_W_UNRESPONSIVE_CARD; } if (SET_PROTOCOL_WRONG_ARGUMENT == ret) { (void)pthread_mutex_unlock(rContext->mMutex); return SCARD_E_PROTO_MISMATCH; } /* use negotiated protocol */ rContext->readerState->cardProtocol = ret; (void)pthread_mutex_unlock(rContext->mMutex); } else { (void)pthread_mutex_unlock(rContext->mMutex); if (! (dwPreferredProtocols & rContext->readerState->cardProtocol)) return SCARD_E_PROTO_MISMATCH; } } } *pdwActiveProtocol = rContext->readerState->cardProtocol; if (dwShareMode != SCARD_SHARE_DIRECT) { switch (*pdwActiveProtocol) { case SCARD_PROTOCOL_T0: case SCARD_PROTOCOL_T1: Log2(PCSC_LOG_DEBUG, "Active Protocol: T=%d", (*pdwActiveProtocol == SCARD_PROTOCOL_T0) ? 0 : 1); break; case SCARD_PROTOCOL_RAW: Log1(PCSC_LOG_DEBUG, "Active Protocol: RAW"); break; default: Log2(PCSC_LOG_ERROR, "Active Protocol: unknown %d", *pdwActiveProtocol); } } else Log1(PCSC_LOG_DEBUG, "Direct access: no protocol selected"); /* * Prepare the SCARDHANDLE identity */ *phCard = RFCreateReaderHandle(rContext); Log2(PCSC_LOG_DEBUG, "hCard Identity: %x", *phCard); /******************************************* * * This section tries to set up the * exclusivity modes. -1 is exclusive * *******************************************/ if (dwShareMode == SCARD_SHARE_EXCLUSIVE) { if (rContext->contexts == PCSCLITE_SHARING_NO_CONTEXT) { rContext->contexts = PCSCLITE_SHARING_EXCLUSIVE_CONTEXT; (void)RFLockSharing(*phCard, rContext); } else { (void)RFDestroyReaderHandle(*phCard); *phCard = 0; return SCARD_E_SHARING_VIOLATION; } } else { /* * Add a connection to the context stack */ rContext->contexts += 1; } /* * Add this handle to the handle list */ rv = RFAddReaderHandle(rContext, *phCard); if (rv != SCARD_S_SUCCESS) { /* * Clean up - there is no more room */ (void)RFDestroyReaderHandle(*phCard); if (rContext->contexts == PCSCLITE_SHARING_EXCLUSIVE_CONTEXT) rContext->contexts = PCSCLITE_SHARING_NO_CONTEXT; else if (rContext->contexts > PCSCLITE_SHARING_NO_CONTEXT) rContext->contexts -= 1; *phCard = 0; PROFILE_END return SCARD_F_INTERNAL_ERROR; } /* * Propagate new state to reader state */ rContext->readerState->readerSharing = rContext->contexts; PROFILE_END return SCARD_S_SUCCESS; } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: PCSC 读卡器 智能卡 CCID USB
 输入关键字,在本站1000多万海量源码库中尽情搜索: