Diff

Differences From Artifact [0817c7d1f8]:

To Artifact [5d076538a2]:


4733
4734
4735
4736
4737
4738
4739

4740
4741
4742
4743
4744
4745
4746
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747







+







	SCARD_READERSTATE reader_states[(sizeof(cackey_slots) / sizeof(cackey_slots[0])) + 1];
	SCARDCONTEXT pcsc_handle;
	LONG scard_getstatchng_ret;
	LONG scard_est_context_ret;
	struct cackey_slot *cackey_slot;
	unsigned int currslot, reader_state_slot;
	int pcsc_connect_ret;
	int slot_changed;

	CACKEY_DEBUG_PRINTF("Called.");

	if (pReserved != NULL) {
		CACKEY_DEBUG_PRINTF("Error. pReserved is not NULL.");

		return(CKR_ARGUMENTS_BAD);
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777




4778
4779
4780
4781



4782
4783
4784


4785



4786

4787
4788
4789


4790
4791
4792
4793
4794




4795
4796
4797
4798



4799
4800
4801


4802
4803

4804
4805

4806
4807
4808


4809
4810
4811


4812
4813
4814
4815
4816
4817
4818






4819
4820
4821

4822
4823
4824
4825
4826




4827
















4828

4829
4830
4831


4832
4833

4834
4835
4836
4837
4838
4839








4840
4841
4842

4843
4844
4845
4846
4847
4848
4849
4762
4763
4764
4765
4766
4767
4768










4769
4770
4771
4772
4773



4774
4775
4776
4777


4778
4779
4780
4781
4782
4783
4784
4785
4786


4787
4788
4789




4790
4791
4792
4793
4794



4795
4796
4797
4798


4799
4800
4801

4802
4803

4804
4805


4806
4807
4808


4809
4810
4811






4812
4813
4814
4815
4816
4817
4818


4819
4820




4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841

4842
4843


4844
4845
4846

4847
4848





4849
4850
4851
4852
4853
4854
4855
4856

4857

4858
4859
4860
4861
4862
4863
4864
4865







-
-
-
-
-
-
-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
+
+

+
+
+

+

-
-
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
+
+

-
+

-
+

-
-
+
+

-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
+

-
-
-
-
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+

-
-
+
+

-
+

-
-
-
-
-
+
+
+
+
+
+
+
+
-

-
+







	pcsc_connect_ret = cackey_pcsc_connect();
	if (pcsc_connect_ret != CACKEY_PCSC_S_OK) {
		CACKEY_DEBUG_PRINTF("Connection to PC/SC failed, returning in failure");

		return(CKR_GENERAL_ERROR);
	}

	if ((flags & CKF_DONT_BLOCK) == CKF_DONT_BLOCK) {
		/* XXX TODO */
		CACKEY_DEBUG_PRINTF("Returning CKR_GENERAL_ERROR (%i) because we were asked to not block", CKR_GENERAL_ERROR);

		return(CKR_GENERAL_ERROR);
	} else {
		for (reader_state_slot = currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) {
			if (cackey_slots[currslot].internal) {
				continue;
			}
	for (reader_state_slot = currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) {
		if (cackey_slots[currslot].internal) {
			continue;
		}

			if (cackey_slots[currslot].active == 0) {
				continue;
			}
		if (cackey_slots[currslot].active == 0) {
			continue;
		}

			reader_states[reader_state_slot].szReader = cackey_slots[currslot].pcsc_reader;
			reader_states[reader_state_slot].pvUserData = &cackey_slots[currslot];
		reader_states[reader_state_slot].szReader = cackey_slots[currslot].pcsc_reader;
		reader_states[reader_state_slot].pvUserData = &cackey_slots[currslot];

		if ((flags & CKF_DONT_BLOCK) == CKF_DONT_BLOCK) {
			reader_states[reader_state_slot].dwCurrentState = SCARD_STATE_UNAWARE;
		} else {
			reader_states[reader_state_slot].dwCurrentState = cackey_slots[currslot].pcsc_state;
		}

			reader_state_slot++;
		}
		reader_state_slot++;
	}

		reader_states[reader_state_slot].szReader = "\\\\?PnP?\\Notification";
		reader_states[reader_state_slot].pvUserData = NULL;
		reader_states[reader_state_slot].dwCurrentState = SCARD_STATE_UNAWARE;
		reader_state_slot++;
	reader_states[reader_state_slot].szReader = "\\\\?PnP?\\Notification";
	reader_states[reader_state_slot].pvUserData = NULL;
	reader_states[reader_state_slot].dwCurrentState = SCARD_STATE_UNAWARE;
	reader_state_slot++;

		scard_est_context_ret = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &pcsc_handle);
		if (scard_est_context_ret != SCARD_S_SUCCESS) {
			CACKEY_DEBUG_PRINTF("Returning CKR_GENERAL_ERROR (%i) because SCardEstablishContext failed: %lx", CKR_GENERAL_ERROR, scard_est_context_ret);
	scard_est_context_ret = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &pcsc_handle);
	if (scard_est_context_ret != SCARD_S_SUCCESS) {
		CACKEY_DEBUG_PRINTF("Returning CKR_GENERAL_ERROR (%i) because SCardEstablishContext failed: %lx", CKR_GENERAL_ERROR, scard_est_context_ret);

			return(CKR_GENERAL_ERROR);
		}
		return(CKR_GENERAL_ERROR);
	}

		scard_getstatchng_ret = SCardGetStatusChange(pcsc_handle, INFINITE, reader_states, reader_state_slot);
	scard_getstatchng_ret = SCardGetStatusChange(pcsc_handle, INFINITE, reader_states, reader_state_slot);

		SCardReleaseContext(pcsc_handle);
	SCardReleaseContext(pcsc_handle);

		if (scard_getstatchng_ret != SCARD_S_SUCCESS) {
			CACKEY_DEBUG_PRINTF("Returning CKR_GENERAL_ERROR (%i) because SCardGetStatusChange failed: %lx", CKR_GENERAL_ERROR, scard_getstatchng_ret);
	if (scard_getstatchng_ret != SCARD_S_SUCCESS) {
		CACKEY_DEBUG_PRINTF("Returning CKR_GENERAL_ERROR (%i) because SCardGetStatusChange failed: %lx", CKR_GENERAL_ERROR, scard_getstatchng_ret);

			return(CKR_GENERAL_ERROR);
		}
		return(CKR_GENERAL_ERROR);
	}

		for (currslot = 0; currslot < reader_state_slot; currslot++) {
			CACKEY_DEBUG_PRINTF("[slot = %u] CurrentState = %lx, EventState = %lx",
			    currslot,
			    reader_states[currslot].dwCurrentState & 0xffff,
			    reader_states[currslot].dwEventState & 0xffff
			);
	for (currslot = 0; currslot < reader_state_slot; currslot++) {
		CACKEY_DEBUG_PRINTF("[slot = %u] CurrentState = %lx, EventState = %lx",
		    currslot,
		    reader_states[currslot].dwCurrentState & 0xffff,
		    reader_states[currslot].dwEventState & 0xffff
		);

			if (reader_states[currslot].dwCurrentState != reader_states[currslot].dwEventState) {
				cackey_slot = (struct cackey_slot *) reader_states[currslot].pvUserData;
		cackey_slot = (struct cackey_slot *) reader_states[currslot].pvUserData;

				if (cackey_slot == NULL) {
					/* XXX: TODO: Someone plugged in a new slot */
					continue;
				}
		if (cackey_slot == NULL) {
			/* XXX: TODO: Someone plugged in a new slot */
			continue;
		}

		slot_changed = 0;

		if ((flags & CKF_DONT_BLOCK) == CKF_DONT_BLOCK) {
			if (cackey_slot->pcsc_state != reader_states[currslot].dwEventState) {
				slot_changed = 1;
			}
		} else {
			if (reader_states[currslot].dwCurrentState != reader_states[currslot].dwEventState) {
				slot_changed = 1;
			}
		}

		if (slot_changed == 0) {
			continue;
		}

				CACKEY_DEBUG_PRINTF("Returning slot changed: %u", (unsigned int) cackey_slot->id);
		CACKEY_DEBUG_PRINTF("Returning slot changed: %u", (unsigned int) cackey_slot->id);

				cackey_slot->pcsc_state = reader_states[currslot].dwEventState;
				*pSlotID = (CK_SLOT_ID) cackey_slot->id;
		cackey_slot->pcsc_state = reader_states[currslot].dwEventState;
		*pSlotID = (CK_SLOT_ID) cackey_slot->id;

				CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK);
		CACKEY_DEBUG_PRINTF("Returning CKR_OK (%i)", CKR_OK);

				return(CKR_OK);
			}
		}
	}

		return(CKR_OK);
	}

	if ((flags & CKF_DONT_BLOCK) != CKF_DONT_BLOCK) {
		CACKEY_DEBUG_PRINTF("Returning CKR_NO_EVENT (%i), but asked to block !? BUG ENCOUNTERED.", CKR_NO_EVENT);
	} else {
		CACKEY_DEBUG_PRINTF("Returning CKR_NO_EVENT (%i)", CKR_NO_EVENT);
	}
	CACKEY_DEBUG_PRINTF("Returning CKR_FUNCTION_NOT_SUPPORTED (%i)", CKR_FUNCTION_NOT_SUPPORTED);

	return(CKR_FUNCTION_NOT_SUPPORTED);
	return(CKR_NO_EVENT);
}

CK_DEFINE_FUNCTION(CK_RV, C_GetMechanismList)(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMechanismList, CK_ULONG_PTR pulCount) {
	CACKEY_DEBUG_PRINTF("Called.");

	if (!cackey_initialized) {
		CACKEY_DEBUG_PRINTF("Error.  Not initialized.");