Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. example.cpp
  5. Abstract:
  6. This is a plug-in for the smart card driver test suite.
  7. This plug-in is smart card dependent
  8. Author:
  9. Klaus U. Schutz
  10. Environment:
  11. Win32 application
  12. Revision History :
  13. Nov. 1997 - initial version
  14. --*/
  15. #include <stdarg.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <time.h>
  19. #include <afx.h>
  20. #include <afxtempl.h>
  21. #include <winioctl.h>
  22. #include <winsmcrd.h>
  23. #include "ifdtest.h"
  24. #define BYTES_PER_BLOCK 64
  25. void
  26. MondexTestCardEntry(
  27. class CCardProvider& in_CCardProvider
  28. );
  29. //
  30. // Create a card provider object
  31. // Note: all global varibales and all functions have to be static
  32. //
  33. static class CCardProvider MondexTestCard(MondexTestCardEntry);
  34. static ULONG
  35. MondexTestCardSetProtocol(
  36. class CCardProvider& in_CCardProvider,
  37. class CReader& in_CReader
  38. )
  39. /*++
  40. Routine Description:
  41. This function will be called after the card has been correctly
  42. identified. We should here set the protocol that we need
  43. for further transmissions
  44. Arguments:
  45. in_CCardProvider - ref. to our card provider object
  46. in_CReader - ref. to the reader object
  47. Return Value:
  48. IFDSTATUS_FAILED - we were unable to set the protocol correctly
  49. IFDSTATUS_SUCCESS - protocol set correctly
  50. --*/
  51. {
  52. ULONG l_lResult;
  53. TestStart("Set protocol to T=0");
  54. l_lResult = in_CReader.SetProtocol(SCARD_PROTOCOL_T0);
  55. TEST_CHECK_SUCCESS("Set protocol failed", l_lResult);
  56. TestEnd();
  57. if (l_lResult != ERROR_SUCCESS) {
  58. return IFDSTATUS_FAILED;
  59. }
  60. return IFDSTATUS_SUCCESS;
  61. }
  62. static
  63. ULONG
  64. MondexTestCardTest(
  65. class CCardProvider& in_CCardProvider,
  66. class CReader& in_CReader
  67. )
  68. /*++
  69. Routine Description:
  70. This serves as the test function for a particular smart card
  71. Arguments:
  72. in_CReader - ref. to class that provides all information for the test
  73. Return Value:
  74. IFDSTATUS value
  75. --*/
  76. {
  77. ULONG l_lResult;
  78. switch (in_CCardProvider.GetTestNo()) {
  79. case 1: {
  80. TestStart("Cold reset");
  81. l_lResult = in_CReader.ColdResetCard();
  82. TEST_CHECK_SUCCESS("Cold reset failed", l_lResult);
  83. TestEnd();
  84. ULONG l_uState;
  85. TestStart("Check reader state");
  86. l_lResult = in_CReader.GetState(&l_uState);
  87. TEST_CHECK_SUCCESS(
  88. "Ioctl IOCTL_SMARTCARD_GET_STATE failed",
  89. l_lResult
  90. );
  91. TestCheck(
  92. l_uState == SCARD_SPECIFIC,
  93. "Invalid reader state.\nReturned %d\nExpected %d",
  94. l_uState,
  95. SCARD_SPECIFIC
  96. );
  97. TestEnd();
  98. return IFDSTATUS_END;
  99. }
  100. default:
  101. return IFDSTATUS_FAILED;
  102. }
  103. return IFDSTATUS_SUCCESS;
  104. }
  105. static void
  106. MondexTestCardEntry(
  107. class CCardProvider& in_CCardProvider
  108. )
  109. /*++
  110. Routine Description:
  111. This function registers all callbacks from the test suite
  112. Arguments:
  113. CCardProvider - ref. to card provider class
  114. Return Value:
  115. -
  116. --*/
  117. {
  118. // Set protocol callback
  119. in_CCardProvider.SetProtocol(MondexTestCardSetProtocol);
  120. // Card test callback
  121. in_CCardProvider.SetCardTest(MondexTestCardTest);
  122. // Name of our card
  123. in_CCardProvider.SetCardName("Mondex");
  124. // ATR of our card
  125. in_CCardProvider.SetAtr((PBYTE) "\x3b\xff\x32\x00\x00\x10\x80\x80\x31\xe0\x5b\x55\x53\x44\x00\x00\x00\x00\x13\x88\x02\x55", 22);
  126. }