[SmartcardServices-Changes] [43] trunk/SmartCardServices/src/PCSC/ifdwrapper.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 30 05:57:27 PDT 2009


Revision: 43
          http://trac.macosforge.org/projects/smartcardservices/changeset/43
Author:   ludovic.rousseau at gmail.com
Date:     2009-07-30 05:57:26 -0700 (Thu, 30 Jul 2009)
Log Message:
-----------
reformat

Modified Paths:
--------------
    trunk/SmartCardServices/src/PCSC/ifdwrapper.c

Modified: trunk/SmartCardServices/src/PCSC/ifdwrapper.c
===================================================================
--- trunk/SmartCardServices/src/PCSC/ifdwrapper.c	2009-07-30 11:44:17 UTC (rev 42)
+++ trunk/SmartCardServices/src/PCSC/ifdwrapper.c	2009-07-30 12:57:26 UTC (rev 43)
@@ -57,11 +57,10 @@
 
 #undef PCSCLITE_STATIC_DRIVER
 
-/*
- * Function: IFDSetPTS Purpose : To set the protocol type selection (PTS).
+/**
+ * Set the protocol type selection (PTS).
  * This function sets the appropriate protocol to be used on the card.
  */
-
 LONG IFDSetPTS(PREADER_CONTEXT rContext, DWORD dwProtocol, UCHAR ucFlags,
 	UCHAR ucPTS1, UCHAR ucPTS2, UCHAR ucPTS3)
 {
@@ -93,10 +92,8 @@
 	}
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
-	SYS_MutexLock(rContext->mMutex);
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
 	ucValue[0] = rContext->dwSlot;
 
@@ -104,7 +101,7 @@
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 	        ucValue[0] = rContext->dwSlot;
-	        IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+	        (void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 	        rv = (*IFD_set_protocol_parameters) (dwProtocol,
 			ucFlags, ucPTS1, ucPTS2, ucPTS3);
 	}
@@ -119,7 +116,7 @@
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 	        ucValue[0] = rContext->dwSlot;
-	        IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+	        (void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 		rv = IFD_Set_Protocol_Parameters(dwProtocol, ucFlags, ucPTS1,
 			ucPTS2, ucPTS3);
 	}
@@ -130,19 +127,15 @@
 	}
 #endif
 
-	SYS_MutexUnLock(rContext->mMutex);
-	/*
-	 * END OF LOCKED REGION
-	 */
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
 	return rv;
 }
 
-/*
- * Function: IFDOpenIFD Purpose : This function opens a communication
- * channel to the IFD.
+/**
+ * Open a communication channel to the IFD.
  */
-
 LONG IFDOpenIFD(PREADER_CONTEXT rContext)
 {
 	RESPONSECODE rv = 0;
@@ -168,11 +161,9 @@
 		}
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
-	SYS_MutexLock(rContext->mMutex);
 #ifndef PCSCLITE_STATIC_DRIVER
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
@@ -204,26 +195,22 @@
 			rv = IFDHCreateChannel(rContext->dwSlot, rContext->dwPort);
 	}
 #endif
-	SYS_MutexUnLock(rContext->mMutex);
 
-	/*
-	 * END OF LOCKED REGION
-	 */
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
 	return rv;
 }
 
-/*
- * Function: IFDCloseIFD Purpose : This function closes a communication
- * channel to the IFD.
+/**
+ * Close a communication channel to the IFD.
  */
-
 LONG IFDCloseIFD(PREADER_CONTEXT rContext)
 {
 	RESPONSECODE rv = IFD_SUCCESS;
 
 #ifndef PCSCLITE_STATIC_DRIVER
-	RESPONSECODE(*IO_close_channel) () = NULL;
+	RESPONSECODE(*IO_close_channel) (void) = NULL;
 	RESPONSECODE(*IFDH_close_channel) (DWORD) = NULL;
 
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
@@ -232,11 +219,8 @@
 		IFDH_close_channel = rContext->psFunctions.psFunctions_v2.pvfCloseChannel;
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
-
-	SYS_MutexLock(rContext->mMutex);
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 #ifndef PCSCLITE_STATIC_DRIVER
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 
@@ -249,20 +233,16 @@
 	else
 		rv = IFDHCloseChannel(rContext->dwSlot);
 #endif
-	SYS_MutexUnLock(rContext->mMutex);
 
-	/*
-	 * END OF LOCKED REGION
-	 */
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
 	return rv;
 }
 
-/*
- * Function: IFDSetCapabilites Purpose : This function set's capabilities
- * in the reader.
+/**
+ * Set capabilities in the reader.
  */
-
 LONG IFDSetCapabilities(PREADER_CONTEXT rContext, DWORD dwTag,
 			DWORD dwLength, PUCHAR pucValue)
 {
@@ -300,20 +280,19 @@
 	return rv;
 }
 
-/*
- * Function: IFDGetCapabilites Purpose : This function get's capabilities
- * in the reader. Other functions int this file will call the driver
- * directly to not cause a deadlock.
+/**
+ * Get's capabilities in the reader.
+ * Other functions int this file will call
+ * the driver directly to not cause a deadlock.
  */
-
 LONG IFDGetCapabilities(PREADER_CONTEXT rContext, DWORD dwTag,
 	PDWORD pdwLength, PUCHAR pucValue)
 {
 	RESPONSECODE rv = IFD_SUCCESS;
 
 #ifndef PCSCLITE_STATIC_DRIVER
-	RESPONSECODE(*IFD_get_capabilities) (DWORD, PUCHAR) = NULL;
-	RESPONSECODE(*IFDH_get_capabilities) (DWORD, DWORD, PDWORD, PUCHAR) = NULL;
+	RESPONSECODE(*IFD_get_capabilities) (DWORD, /*@out@*/ PUCHAR) = NULL;
+	RESPONSECODE(*IFDH_get_capabilities) (DWORD, DWORD, PDWORD, /*@out@*/ PUCHAR) = NULL;
 
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 		IFD_get_capabilities =
@@ -323,12 +302,9 @@
 			rContext->psFunctions.psFunctions_v2.pvfGetCapabilities;
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
-	SYS_MutexLock(rContext->mMutex);
-
 #ifndef PCSCLITE_STATIC_DRIVER
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 		rv = (*IFD_get_capabilities) (dwTag, pucValue);
@@ -343,20 +319,15 @@
 			pucValue);
 #endif
 
-	SYS_MutexUnLock(rContext->mMutex);
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
-	/*
-	 * END OF LOCKED REGION
-	 */
-
 	return rv;
 }
 
-/*
- * Function: IFDPowerICC Purpose : This function powers up/down or reset's
- * an ICC located in the IFD.
+/**
+ * Power up/down or reset's an ICC located in the IFD.
  */
-
 LONG IFDPowerICC(PREADER_CONTEXT rContext, DWORD dwAction,
 	const unsigned char *pucAtr, PDWORD pdwAtrLen)
 {
@@ -381,7 +352,7 @@
 	/*
 	 * Check that the card is inserted first
 	 */
-	IFDStatusICC(rContext, &dwStatus, pucAtr, pdwAtrLen);
+	(void)IFDStatusICC(rContext, &dwStatus, pucAtr, pdwAtrLen);
 
 	if (dwStatus & SCARD_ABSENT)
 		return SCARD_W_REMOVED_CARD;
@@ -392,17 +363,14 @@
 		IFDH_power_icc = rContext->psFunctions.psFunctions_v2.pvfPowerICC;
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
-	SYS_MutexLock(rContext->mMutex);
-
 #ifndef PCSCLITE_STATIC_DRIVER
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 		ucValue[0] = rContext->dwSlot;
-		IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+		(void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 		rv = (*IFD_power_icc) (dwAction);
 	}
 	else
@@ -416,17 +384,15 @@
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 		ucValue[0] = rContext->dwSlot;
-		IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+		(void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 		rv = IFD_Power_ICC(dwAction);
 	}
 	else
 		rv = IFDHPowerICC(rContext->dwSlot, dwAction, pucAtr, pdwAtrLen);
 #endif
-	SYS_MutexUnLock(rContext->mMutex);
 
-	/*
-	 * END OF LOCKED REGION
-	 */
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
 	/* use clean values in case of error */
 	if (rv != IFD_SUCCESS)
@@ -436,7 +402,7 @@
 
 		if (rv == IFD_NO_SUCH_DEVICE)
 		{
-		//	SendHotplugSignal();
+		//	(void)SendHotplugSignal();
 			return SCARD_E_READER_UNAVAILABLE;
 		}
 
@@ -447,17 +413,15 @@
 	 * Get the ATR and it's length
 	 */
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
-		IFDStatusICC(rContext, &dwStatus, pucAtr, pdwAtrLen);
+		(void)IFDStatusICC(rContext, &dwStatus, pucAtr, pdwAtrLen);
 
 	return rv;
 }
 
-/*
- * Function: IFDStatusICC Purpose : This function provides statistical
- * information about the IFD and ICC including insertions, atr, powering
- * status/etc.
+/**
+ * Provide statistical information about the IFD and ICC including insertions,
+ * atr, powering status/etc.
  */
-
 LONG IFDStatusICC(PREADER_CONTEXT rContext, PDWORD pdwStatus,
 	const unsigned char *pucAtr, PDWORD pdwAtrLen)
 {
@@ -467,9 +431,9 @@
 	UCHAR ucValue[1] = "\x00";
 
 #ifndef PCSCLITE_STATIC_DRIVER
-	RESPONSECODE(*IFD_is_icc_present) () = NULL;
+	RESPONSECODE(*IFD_is_icc_present) (void) = NULL;
 	RESPONSECODE(*IFDH_icc_presence) (DWORD) = NULL;
-	RESPONSECODE(*IFD_get_capabilities) (DWORD, PUCHAR) = NULL;
+	RESPONSECODE(*IFD_get_capabilities) (DWORD, /*@out@*/ PUCHAR) = NULL;
 
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
@@ -487,17 +451,14 @@
 	}
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
-	SYS_MutexLock(rContext->mMutex);
-
 #ifndef PCSCLITE_STATIC_DRIVER
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 		ucValue[0] = rContext->dwSlot;
-		IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+		(void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 		rv = (*IFD_is_icc_present) ();
 	}
 	else
@@ -506,17 +467,15 @@
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 		ucValue[0] = rContext->dwSlot;
-		IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+		(void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 		rv = IFD_Is_ICC_Present();
 	}
 	else
 		rv = IFDHICCPresence(rContext->dwSlot);
 #endif
-	SYS_MutexUnLock(rContext->mMutex);
 
-	/*
-	 * END OF LOCKED REGION
-	 */
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
 	if (rv == IFD_SUCCESS || rv == IFD_ICC_PRESENT)
 		dwCardStatus |= SCARD_PRESENT;
@@ -530,7 +489,7 @@
 
 			if (rv == IFD_NO_SUCH_DEVICE)
 			{
-			//	SendHotplugSignal();
+			//	(void)SendHotplugSignal();
 				return SCARD_E_READER_UNAVAILABLE;
 			}
 
@@ -551,25 +510,20 @@
 
 			dwTag = TAG_IFD_ATR;
 
-			/*
-			 * LOCK THIS CODE REGION
-			 */
+			/* LOCK THIS CODE REGION */
+			(void)SYS_MutexLock(rContext->mMutex);
 
-			SYS_MutexLock(rContext->mMutex);
-
 			ucValue[0] = rContext->dwSlot;
-			IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+			(void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 
 #ifndef PCSCLITE_STATIC_DRIVER
 			rv = (*IFD_get_capabilities) (dwTag, pucAtr);
 #else
 			rv = IFD_Get_Capabilities(dwTag, pucAtr);
 #endif
-			SYS_MutexUnLock(rContext->mMutex);
 
-			/*
-			 * END OF LOCKED REGION
-			 */
+			/* END OF LOCKED REGION */
+			(void)SYS_MutexUnLock(rContext->mMutex);
 
 			/*
 			 * FIX :: This is a temporary way to return the correct size
@@ -619,7 +573,8 @@
 	RESPONSECODE rv = IFD_SUCCESS;
 
 #ifndef PCSCLITE_STATIC_DRIVER
-	RESPONSECODE(*IFDH_control_v2) (DWORD, PUCHAR, DWORD, PUCHAR, PDWORD);
+	RESPONSECODE(*IFDH_control_v2) (DWORD, PUCHAR, DWORD, /*@out@*/ PUCHAR,
+		PDWORD);
 #endif
 
 	if (rContext->dwVersion != IFD_HVERSION_2_0)
@@ -629,10 +584,8 @@
 	IFDH_control_v2 = rContext->psFunctions.psFunctions_v2.pvfControl;
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
-	SYS_MutexLock(rContext->mMutex);
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
 #ifndef PCSCLITE_STATIC_DRIVER
 	rv = (*IFDH_control_v2) (rContext->dwSlot, TxBuffer, TxLength,
@@ -641,24 +594,24 @@
 	rv = IFDHControl_v2(rContext->dwSlot, TxBuffer, TxLength,
 		RxBuffer, RxLength);
 #endif
-	SYS_MutexUnLock(rContext->mMutex);
-	/*
-	 * END OF LOCKED REGION
-	 */
 
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
+
 	if (rv == IFD_SUCCESS)
 		return SCARD_S_SUCCESS;
 	else
 	{
 		Log2(PCSC_LOG_ERROR, "Card not transacted: %ld", rv);
+		LogXxd(PCSC_LOG_DEBUG, "TxBuffer ", TxBuffer, TxLength);
+		LogXxd(PCSC_LOG_DEBUG, "RxBuffer ", RxBuffer, *RxLength);
 		return SCARD_E_NOT_TRANSACTED;
 	}
 }
 
-/*
- * Function: IFDControl Purpose : This function provides a means for
- * toggling a specific action on the reader such as swallow, eject,
- * biometric.
+/**
+ * Provide a means for toggling a specific action on the reader such as
+ * swallow, eject, biometric.
  */
 
 /*
@@ -682,12 +635,9 @@
 	IFDH_control = rContext->psFunctions.psFunctions_v3.pvfControl;
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
-	SYS_MutexLock(rContext->mMutex);
-
 #ifndef PCSCLITE_STATIC_DRIVER
 	rv = (*IFDH_control) (rContext->dwSlot, ControlCode, TxBuffer,
 		TxLength, RxBuffer, RxLength, BytesReturned);
@@ -695,21 +645,23 @@
 	rv = IFDHControl(rContext->dwSlot, ControlCode, TxBuffer,
 		TxLength, RxBuffer, RxLength, BytesReturned);
 #endif
-	SYS_MutexUnLock(rContext->mMutex);
 
-	/*
-	 * END OF LOCKED REGION
-	 */
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
 	if (rv == IFD_SUCCESS)
 		return SCARD_S_SUCCESS;
 	else
 	{
 		Log2(PCSC_LOG_ERROR, "Card not transacted: %ld", rv);
+		Log3(PCSC_LOG_DEBUG, "ControlCode: 0x%.8LX BytesReturned: %ld",
+			ControlCode, *BytesReturned);
+		LogXxd(PCSC_LOG_DEBUG, "TxBuffer ", TxBuffer, TxLength);
+		LogXxd(PCSC_LOG_DEBUG, "RxBuffer ", RxBuffer, *BytesReturned);
 
 		if (rv == IFD_NO_SUCH_DEVICE)
 		{
-//			SendHotplugSignal();
+//			(void)SendHotplugSignal();
 			return SCARD_E_READER_UNAVAILABLE;
 		}
 
@@ -717,11 +669,9 @@
 	}
 }
 
-/*
- * Function: IFDTransmit Purpose : This function transmits an APDU to the
- * ICC.
+/**
+ * Transmit an APDU to the ICC.
  */
-
 LONG IFDTransmit(PREADER_CONTEXT rContext, SCARD_IO_HEADER pioTxPci,
 	PUCHAR pucTxBuffer, DWORD dwTxLength, PUCHAR pucRxBuffer,
 	PDWORD pdwRxLength, PSCARD_IO_HEADER pioRxPci)
@@ -731,9 +681,9 @@
 
 #ifndef PCSCLITE_STATIC_DRIVER
 	RESPONSECODE(*IFD_transmit_to_icc) (SCARD_IO_HEADER, PUCHAR, DWORD,
-		PUCHAR, PDWORD, PSCARD_IO_HEADER) = NULL;
+		/*@out@*/ PUCHAR, PDWORD, PSCARD_IO_HEADER) = NULL;
 	RESPONSECODE(*IFDH_transmit_to_icc) (DWORD, SCARD_IO_HEADER, PUCHAR,
-		DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER) = NULL;
+		DWORD, /*@out@*/ PUCHAR, PDWORD, PSCARD_IO_HEADER) = NULL;
 #endif
 
 	/* log the APDU */
@@ -748,18 +698,14 @@
 			rContext->psFunctions.psFunctions_v2.pvfTransmitToICC;
 #endif
 
-	/*
-	 * LOCK THIS CODE REGION
-	 */
+	/* LOCK THIS CODE REGION */
+	(void)SYS_MutexLock(rContext->mMutex);
 
-	SYS_MutexLock(rContext->mMutex);
-
-
 #ifndef PCSCLITE_STATIC_DRIVER
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 		ucValue[0] = rContext->dwSlot;
-		IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+		(void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 		rv = (*IFD_transmit_to_icc) (pioTxPci, (LPBYTE) pucTxBuffer,
 			dwTxLength, pucRxBuffer, pdwRxLength, pioRxPci);
 	}
@@ -771,7 +717,7 @@
 	if (rContext->dwVersion == IFD_HVERSION_1_0)
 	{
 		ucValue[0] = rContext->dwSlot;
-		IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+		(void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
 		rv = IFD_Transmit_to_ICC(pioTxPci, (LPBYTE) pucTxBuffer,
 			dwTxLength, pucRxBuffer, pdwRxLength, pioRxPci);
 	}
@@ -780,11 +726,9 @@
 			(LPBYTE) pucTxBuffer, dwTxLength,
 			pucRxBuffer, pdwRxLength, pioRxPci);
 #endif
-	SYS_MutexUnLock(rContext->mMutex);
 
-	/*
-	 * END OF LOCKED REGION
-	 */
+	/* END OF LOCKED REGION */
+	(void)SYS_MutexUnLock(rContext->mMutex);
 
 	/* log the returned status word */
 	DebugLogCategory(DEBUG_CATEGORY_SW, pucRxBuffer, *pdwRxLength);
@@ -797,7 +741,7 @@
 
 		if (rv == IFD_NO_SUCH_DEVICE)
 		{
-	//		SendHotplugSignal();
+	//		(void)SendHotplugSignal();
 			return SCARD_E_READER_UNAVAILABLE;
 		}
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/smartcardservices-changes/attachments/20090730/36403a12/attachment.html>


More information about the SmartcardServices-Changes mailing list