⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scardtpl.cpp

📁 wince5.0 pb中pccard源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}

STATUS HCard::CardGetParsedTuple (CARD_SOCKET_HANDLE hSocket,
                                  UINT8 uDesiredTuple,
                                  PVOID pBuf,
                                  PUINT pnItems)
{
    	STATUS status = ::CardGetParsedTuple(hSocket, uDesiredTuple, pBuf, pnItems);
    	return status ;
}

//------------------------------ MatchedCard --------------------------------

MatchedCard::MatchedCard (UINT8 cSlot, UINT8 cFunc){
    	pHCard = new HCard ;
   	pSCard = new SCard (pHCard, cSlot, cFunc) ;

    	sStatus      = hStatus     = 0 ;
    	usTupleCode  = uhTupleCode = 0 ;
   	usTupleLink  = uhTupleLink = 0 ;
    	usDataLen    = uhDataLen   = 0 ;
    	fDataMatches = 1 ;
    	unExtraData = 0 ;
}

MatchedCard::~MatchedCard () {delete pSCard ; delete pHCard ;}

VOID MatchedCard::getMismatchedParams (UINT32 *which, UINT32 *softValue, UINT32 *hardValue){

	if (sStatus != hStatus)   {
		if ((sStatus == CERR_NO_MORE_ITEMS)&&(hStatus == CERR_SUCCESS)){
			*which = 0xFFFFFFFF ; 
			*softValue = 0 ; 
			*hardValue = 0 ; 
			return ;
		}
	     	else{
	     		*which = 0 ; 
	     		*softValue = sStatus ;     
	     		*hardValue = hStatus ;     
	     		return ;
	     	}
	}

    	if (usTupleCode != uhTupleCode) {
    		*which = 1 ; 
    		*softValue = usTupleCode ; 
    		*hardValue = uhTupleCode ; 
    		return ;
    	}
    	if (usTupleLink != uhTupleLink) {
    		*which = 2 ; 
    		*softValue = usTupleLink ; 
    		*hardValue = uhTupleLink ; 
    		return ;
    	}
    	if (usDataLen != uhDataLen) {
    		*which = 3 ; 
    		*softValue = usDataLen ;   
    		*hardValue = uhDataLen ;  
    		return ;
    	}
    	if (!fDataMatches) {
    		*which = 4 ; 
    		*softValue = usDataLen ;   
    		*hardValue = uhDataLen ;   
    		return ;
    	}
    	if (unExtraData){
    		*which = 5 ; 
    		*softValue = 0 ;           
    		*hardValue = unExtraData ; 
    		return ;
    	}

    	// The values to return if all matches.
    	*which = 0xFFFFFFFF ; 
    	*softValue = 0 ; 
    	*hardValue = 0 ; 
    	return ;
}

STATUS MatchedCard::CardGetFirstTuple (PCARD_TUPLE_PARMS p){
    	// Get ready to write on p by keeping a copy.
    	PCARD_TUPLE_PARMS s = newCopy (p) ;
    	if (!s) 
    		return CERR_OUT_OF_RESOURCE ;

    	// Get HardCard result.
    	hStatus = pHCard->CardGetFirstTuple (p) ;
    	uhTupleCode = p->uTupleCode ;
    	uhTupleLink = p->uTupleLink ;

    	if (hStatus == CERR_SUCCESS){
        	// CISTPL_END has a second meaning: any tuple
        	if (p->uDesiredTuple == CISTPL_END){
	            sStatus      = hStatus ;
	            usTupleCode  = uhTupleCode ;
	            usTupleLink  = uhTupleLink ;
	            usDataLen    = uhDataLen ;
	            fDataMatches = 1 ;
	            unExtraData  = 0 ;
	            delete s ;
	            return hStatus ;
          	}

        	// Cover the possibility that SCard is not completely initialized.
        	// If hStatus != CERR_SUCCESS then guaranteePresence makes no sense.
        	guaranteePresence (p) ;
      }

    	// Get SCard result
    	sStatus = pSCard->CardGetFirstTuple (s) ;
    	usTupleCode = s->uTupleCode ;
    	usTupleLink = s->uTupleLink ;
    	delete s ;

    	if ((hStatus == CERR_NO_MORE_ITEMS) && (sStatus == CERR_NO_MORE_ITEMS)){
        	sStatus      = hStatus ;
        	usTupleCode  = uhTupleCode ;
        	usTupleLink  = uhTupleLink ;
        	usDataLen    = uhDataLen ;
        	fDataMatches = 1 ;
        	unExtraData  = 0 ;
        	return hStatus ;
      }

    	// CISTPL_NULL anomaly
    	if ((usTupleCode == CISTPL_END) && (uhTupleCode == CISTPL_NULL))
        	usTupleCode = CISTPL_NULL ;

    	// What we didn't try to get must be OK.
    	usDataLen = uhDataLen = 0 ;
    	fDataMatches = 1 ;
    	unExtraData = 0 ;

    	return hStatus ;
}

STATUS MatchedCard::CardGetNextTuple (PCARD_TUPLE_PARMS p){
    	hStatus = pHCard->CardGetNextTuple (p) ;
    	uhTupleCode = p->uTupleCode ;
    	uhTupleLink = p->uTupleLink ;

    	if (hStatus == CERR_SUCCESS){
        	// Cover the possibility that SCard is not completely initialized.
        	guaranteePresence (p) ;

        	// Maybe we were not supposed to find links.
        	if (!(p->fAttributes & 1) && isLink(p->uTupleCode)) 
        		sStatus = CERR_NO_MORE_ITEMS ;
        	else 
        		sStatus = isPresent(p) ? hStatus : CERR_READ_FAILURE ;

        	if (sStatus == hStatus){
            		PCARD_TUPLE_PARMS s = newCopy (p) ;

            		if (pSCard) 
            			pSCard->CardGetThisTuple (s) ;
            		usTupleCode = s->uTupleCode ;
            		usTupleLink = s->uTupleLink ;
            		delete s ;
            		// Possible pass
          	}
        	else{ // The error is a status error.
            		usTupleCode  = uhTupleCode ;
            		usTupleLink  = uhTupleLink ;
            		// Certain failure
          	}
      	}
    	else{
        	// It was not found by HCard.
        	// Assume the tuple walking algorithm is correct.
        	// This algorithm is really arcane, given the
        	// contradictions in the PCMCIA books, and the
        	// inconsistencies in the real code.
       	sStatus      = hStatus ;
        	usTupleCode  = uhTupleCode ;
        	usTupleLink  = uhTupleLink ;
        	// Possible pass
      	}

    	// This stuff does not exist.
    	usDataLen    = uhDataLen = 0 ;
    	fDataMatches = 1 ;
    	unExtraData  = 0 ;

    	return hStatus ;
}

STATUS MatchedCard::CardGetTupleData (PCARD_DATA_PARMS p, UINT32 size){
    	// Get ready to detect overwrites.
   	memset ((PUCHAR)p + sizeof(CARD_DATA_PARMS), 0, size - sizeof(CARD_DATA_PARMS)) ;
    	PCARD_DATA_PARMS s = newCopy (p, size) ;

    	// This succeeds because guaranteePresence () was cleverly called using a CARD_TUPLE_PARMS version of p.
    	syncronizeSoftCard (p) ;

    	// Get SCard result: assume p->uBufLen and p->uTupleOffset are correctly set.
    	sStatus = pSCard->CardGetTupleData(s) ;

    	// Get HardCard result.
    	hStatus = pHCard->CardGetTupleData (p) ;
	NKDbgPrintfW(_T("sStatus = %d; hStatus=%d"), sStatus, hStatus);

    	// In case of CERR_BAD_ARG_LENGTH in both cases, we pass
    	if ((sStatus == CERR_BAD_ARG_LENGTH) && (hStatus == CERR_BAD_ARG_LENGTH)){
        	usTupleCode = uhTupleCode = 0 ;
        	usTupleLink = uhTupleLink = 0 ;
        	usDataLen   = uhDataLen   = 0 ;
        	fDataMatches = 1 ; unExtraData = 0 ;
        	delete s ;
        	return hStatus ;
      }

    	usDataLen = s->uDataLen ;
    	uhDataLen = p->uDataLen ;

	NKDbgPrintfW(_T("sDatalen=%d, hDataLen=%d"), usDataLen, uhDataLen);
    	// See if data matches.
    	if (uhDataLen == usDataLen){
        	UINT start = sizeof (CARD_DATA_PARMS) ;
        	PUCHAR x = (PUCHAR)s + start, y = (PUCHAR)p + start ;
        	fDataMatches = !memcmp (x, y, uhDataLen) ;
      }
    	else 
    		fDataMatches = 0 ; // Not used if the data lengths are different,

    	// s is longer needed.
    	delete s ;

    	// Look for extra data.
    	if (fDataMatches){
        	unExtraData = 0 ;
        	UINT16 uStartFrom = sizeof(CARD_DATA_PARMS) + p->uDataLen ;
        	PUCHAR pBuf = (PUCHAR) p ;
        	for (UINT16 i = uStartFrom ; i < size ; i++) 
        		if (pBuf[i]) 
        			unExtraData++ ;
      }
    	else 
    		unExtraData = 0 ; // A useless but assigned value.

    	// These are not available.
    	usTupleCode = uhTupleCode = 0 ;
    	usTupleLink = uhTupleLink = 0 ;

    	return hStatus ;
}

STATUS MatchedCard::CardGetParsedTuple (CARD_SOCKET_HANDLE hSocket,
                                        UINT8 uDesiredTuple,
                                        PVOID pBuf,
                                        PUINT pnItems,
                                        UINT32 actualBufSize)
{
   	// Get ready to detect overwrites - pBuf != 0 of course.
    	memset (pBuf, 0, actualBufSize) ;

    	// Set a soft card buffer.
    	PVOID s = new UCHAR [actualBufSize] ;
    	if (!s) return CERR_OUT_OF_RESOURCE ;
    	memset (s, 0, actualBufSize) ;

     	// Get SoftCard result.
    	UINT nsCount = *pnItems ;
    	sStatus = pSCard->CardGetParsedTuple (hSocket, uDesiredTuple, s, &nsCount) ;
    	usDataLen = (sStatus == CERR_SUCCESS) ? (UINT16)nsCount : 0 ;

    	// Get HardCard result.
    	UINT nhCount = *pnItems ;
    	hStatus = pHCard->CardGetParsedTuple (hSocket, uDesiredTuple, pBuf, &nhCount) ;
    	uhDataLen = (hStatus == CERR_SUCCESS) ? (UINT16)nhCount : 0 ;

    	UINT nBufSize ;
    	if (uhDataLen == usDataLen){
        	switch (uDesiredTuple){
            		case CISTPL_CONFIG:
              	nBufSize = usDataLen * sizeof (PARSED_CONFIG) ;
              	break ;
	            case CISTPL_CFTABLE_ENTRY:
	              	nBufSize = usDataLen * sizeof (PARSED_CFTABLE) ;
	              	break ;
	            default: // This of course never happens.
	              	nBufSize = 0 ;
	              	break ;
          	}
        	if (nBufSize) 
        		fDataMatches = !memcmp (s, pBuf, nBufSize) ;
        	else 
        		fDataMatches = 1 ;
      }
    	else {
    		nBufSize = 0  ; 
    		fDataMatches = 0 ;
    	} // Not used if the data lengths are different.

    	// s is no longer needed.
    	delete[] s ;

    	// Look for extra data.
    	if (fDataMatches){
        	unExtraData = 0 ;       // Look for extraneous extra bytes in pBuf.
        	PUCHAR pRtn = (PUCHAR) pBuf ;
        	for (UINT i = nBufSize ; i < actualBufSize ; i++) 
        		if (pRtn[i]) 
        			unExtraData++ ;
      	}
    	else 
    		unExtraData = 0 ; // A useless value since data does not match.

    	// These are not available, so they are not in error.
    	usTupleCode = uhTupleCode = 0 ;
    	usTupleLink = uhTupleLink = 0 ;

    	return hStatus ;
}

UINT8 MatchedCard::getTupleType (PCARD_TUPLE_PARMS p)
  {return pSCard->getTupleType (p) ;}

UINT8 MatchedCard::getTupleType (PCARD_DATA_PARMS p)
  {return getTupleType ((PCARD_TUPLE_PARMS) p) ;}

UINT MatchedCard::getMaxParsedItems (CARD_SOCKET_HANDLE hSocket, UINT8 uDesiredTuple){
    	UINT nItems = 6000 ; // GLITCH
    	pHCard->CardGetParsedTuple (hSocket, uDesiredTuple, 0, &nItems) ;
    	return nItems ;
}

int MatchedCard::syncronizeSoftCard (PCARD_TUPLE_PARMS p)
  {return syncronizeSoftCard ((PCARD_DATA_PARMS)p) ;}

int MatchedCard::syncronizeSoftCard (PCARD_DATA_PARMS p)
  {return pSCard->goToId (p) ;}

int MatchedCard::isPresent  (PCARD_TUPLE_PARMS p)
  {return pSCard->isPresent(p) ;}

VOID MatchedCard::guaranteePresence (PCARD_TUPLE_PARMS p)
  {if (!isPresent(p)) pSCard->addTuple (p, pHCard) ;}

VOID MatchedCard::dump () {if (pSCard) pSCard->dump () ;}

// SCARDTPL.CPP

#define TUPLE_FLAG_COMMON       0x0001    // Tuples are in common memory
VOID dumpTuple (UINT8 uTupleCode, UINT8 uTupleLink, UINT16 flags, UINT32 cisOffset, UINT32 nItems){
    	TCHAR *tplCode =  findTupleNameStr (uTupleCode) ;
    	if (!tplCode) tplCode = TEXT("Unknown") ;
    	TCHAR *pSpace = (flags & TUPLE_FLAG_COMMON) ? TEXT("C") : TEXT("A") ;

    	g_pKato->Log(LOG_DETAIL,TEXT("%s ---- %d bytes, ID: %s%ld"),
            tplCode, uTupleLink, pSpace, cisOffset
          ) ;

    	if ((uTupleCode == CISTPL_CONFIG) || (uTupleCode == CISTPL_CFTABLE_ENTRY))
      		g_pKato->Log(LOG_DETAIL,TEXT(" ---- Parsed items: %ld"), nItems) ;

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -