Diff

Differences From Artifact [60d21a7b2f]:

To Artifact [5e1ae9e427]:


   191    191   
   192    192   	if (retval != ptr) {
   193    193   		fprintf(stderr, "%s():%i: ", func, line);
   194    194   		fprintf(stderr, "REALLOC(%p) = %p", ptr, retval);
   195    195   		fprintf(stderr, "\n");
   196    196   		fflush(stderr);
   197    197   	}
          198  +
          199  +	if (retval == NULL) {
          200  +		CACKEY_DEBUG_PRINTF(" *** ERROR *** realloc returned NULL");
          201  +	}
   198    202   
   199    203   	return(retval);
   200    204   }
   201    205   
   202    206   static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) {
   203    207   	char *retval;
   204    208   
................................................................................
   559    563   typedef enum {
   560    564   	CACKEY_PCSC_S_TOKENPRESENT    = 1,
   561    565   	CACKEY_PCSC_S_OK              = 0,
   562    566   	CACKEY_PCSC_E_GENERIC         = -1,
   563    567   	CACKEY_PCSC_E_BADPIN          = -2,
   564    568   	CACKEY_PCSC_E_LOCKED          = -3,
   565    569   	CACKEY_PCSC_E_NEEDLOGIN       = -4,
   566         -	CACKEY_PCSC_E_TOKENABSENT     = -6,
          570  +	CACKEY_PCSC_E_TOKENABSENT     = -6
   567    571   } cackey_ret;
   568    572   
   569    573   struct cackey_tlv_cardurl {
   570    574   	unsigned char        rid[5];
   571    575   	cackey_tlv_apptype   apptype;
   572    576   	cackey_tlv_objectid  objectid;
   573    577   	cackey_tlv_objectid  appid;
................................................................................
   833    837   
   834    838   		return(CACKEY_PCSC_E_GENERIC);
   835    839   	}
   836    840   
   837    841   	/* Connect to reader, if needed */
   838    842   	if (!slot->pcsc_card_connected) {
   839    843   		CACKEY_DEBUG_PRINTF("SCardConnect(%s) called", slot->pcsc_reader);
   840         -		scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &slot->pcsc_card, &protocol);
          844  +		scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &slot->pcsc_card, &protocol);
   841    845   
   842    846   		if (scard_conn_ret != SCARD_S_SUCCESS) {
   843    847   			CACKEY_DEBUG_PRINTF("Connection to card failed, returning in failure (SCardConnect() = %s/%li)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_conn_ret), (long) scard_conn_ret);
   844    848   
   845    849   			return(CACKEY_PCSC_E_GENERIC);
   846    850   		}
   847    851   
................................................................................
  1071   1075   	if (class == GSCIS_CLASS_ISO7816 && instruction == GSCIS_INSTR_VERIFY && p1 == 0x00 && p2 == 0x00) {
  1072   1076   		CACKEY_DEBUG_PRINTF("Sending APDU: <<censored>>");
  1073   1077   	} else {
  1074   1078   		CACKEY_DEBUG_PRINTBUF("Sending APDU:", xmit_buf, xmit_len);
  1075   1079   	}
  1076   1080   
  1077   1081   	recv_len = sizeof(recv_buf);
  1078         -	scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, SCARD_PCI_T1, recv_buf, &recv_len);
         1082  +	scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, NULL, recv_buf, &recv_len);
  1079   1083   	if (scard_xmit_ret != SCARD_S_SUCCESS) {
  1080   1084   		CACKEY_DEBUG_PRINTF("Failed to send APDU to card (SCardTransmit() = %s/%lx)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (unsigned long) scard_xmit_ret);
  1081   1085   		CACKEY_DEBUG_PRINTF("Marking slot as having been reset");
  1082   1086   
  1083   1087   		slot->transaction_depth = 0;
  1084   1088   		slot->slot_reset = 1;
  1085   1089   
  1086   1090   		if (scard_xmit_ret == SCARD_W_RESET_CARD) {
  1087   1091   			CACKEY_DEBUG_PRINTF("Reset required, please hold...");
  1088   1092   
  1089         -			scard_reconn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &protocol);
         1093  +			scard_reconn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, SCARD_RESET_CARD, &protocol);
  1090   1094   			if (scard_reconn_ret == SCARD_S_SUCCESS) {
  1091   1095   				/* Re-establish transaction, if it was present */
  1092   1096   				if (slot->transaction_depth > 0) {
  1093   1097   					slot->transaction_depth--;
  1094   1098   					cackey_begin_transaction(slot);
  1095   1099   				}
  1096   1100   
  1097   1101   				CACKEY_DEBUG_PRINTF("Reset successful, retransmitting");
  1098   1102   
  1099   1103   				recv_len = sizeof(recv_buf);
  1100         -				scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, SCARD_PCI_T0, recv_buf, &recv_len);
         1104  +				scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, NULL, recv_buf, &recv_len);
  1101   1105   
  1102   1106   				if (scard_xmit_ret != SCARD_S_SUCCESS) {
  1103   1107   					CACKEY_DEBUG_PRINTF("Retransmit failed, returning in failure after disconnecting the card (SCardTransmit = %s/%li)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (long) scard_xmit_ret);
  1104   1108   
  1105   1109   					SCardDisconnect(slot->pcsc_card, SCARD_RESET_CARD);
  1106   1110   					slot->pcsc_card_connected = 0;
  1107   1111