Leaked source code of windows server 2003
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.

149 lines
2.9 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation 1999
  3. Module Name:
  4. Proto_T1
  5. Abstract:
  6. This module provides the mapping from an APDU to a T=1 TPDU.
  7. Author:
  8. Doug Barlow (dbarlow) 6/28/1999
  9. Notes:
  10. ?Notes?
  11. --*/
  12. #ifndef WIN32_LEAN_AND_MEAN
  13. #define WIN32_LEAN_AND_MEAN
  14. #endif
  15. #include "stdafx.h"
  16. #include "Conversion.h"
  17. static DWORD l_dwDefaultIOMax = 0;
  18. /*++
  19. ApduToTpdu_T1:
  20. This routine takes an APDU, converts it to a T=1 TPDU, and performs the
  21. exchange to the specified card.
  22. Arguments:
  23. hCard supplies a handle to the card to be used in the exchange.
  24. pbPciRqst supplies the PCI Request structure
  25. cbPciRqst supplies the length of pbPciRqst, in bytes
  26. pbApdu supplies the APDU to be sent to the card.
  27. cbApdu supplies the length of the APDU in pbApdu.
  28. dwFlags supplies any special flags used to modify the operation.
  29. bfPciRsp receives the response PCI.
  30. bfReply receives the response from the card.
  31. Return Value:
  32. None
  33. Throws:
  34. Errors are thrown as HRESULT status codes.
  35. Remarks:
  36. ?Remarks?
  37. Author:
  38. Doug Barlow (dbarlow) 6/28/1999
  39. --*/
  40. #undef __SUBROUTINE__
  41. #define __SUBROUTINE__ TEXT("ApduToTpdu_T1")
  42. void
  43. ApduToTpdu_T1(
  44. IN SCARDHANDLE hCard,
  45. IN const SCARD_IO_REQUEST *pPciRqst,
  46. IN LPCBYTE pbApdu,
  47. IN DWORD cbApdu,
  48. IN DWORD dwFlags,
  49. OUT CBuffer bfPciRsp,
  50. OUT CBuffer &bfReply)
  51. {
  52. LONG lSts;
  53. DWORD dwLen, dwXmitFlags;
  54. WORD wLe;
  55. //
  56. // Figure out how big the receive buffers should be.
  57. //
  58. bfPciRsp.Set((LPCBYTE)pPciRqst, pPciRqst->cbPciLength);
  59. ParseRequest(
  60. pbApdu,
  61. cbApdu,
  62. NULL,
  63. NULL,
  64. NULL,
  65. NULL,
  66. NULL,
  67. NULL,
  68. &wLe,
  69. &dwXmitFlags);
  70. if ((0 == wLe) && (0 != (dwXmitFlags & APDU_MAXIMUM_LE)))
  71. {
  72. if (0 == l_dwDefaultIOMax)
  73. {
  74. try
  75. {
  76. CRegistry regCalais(
  77. HKEY_LOCAL_MACHINE,
  78. TEXT("SOFTWARE\\Microsoft\\Cryptography\\Calais"),
  79. KEY_READ);
  80. l_dwDefaultIOMax = regCalais.GetNumericValue(
  81. TEXT("MaxDefaultBuffer"));
  82. }
  83. catch (...)
  84. {
  85. l_dwDefaultIOMax = 264;
  86. }
  87. }
  88. wLe = (WORD)l_dwDefaultIOMax;
  89. }
  90. bfReply.Presize(wLe + 2);
  91. //
  92. // Perform the I/O
  93. dwLen = bfReply.Space();
  94. lSts = SCardTransmit(
  95. hCard,
  96. pPciRqst,
  97. pbApdu,
  98. cbApdu,
  99. (LPSCARD_IO_REQUEST)bfPciRsp.Access(),
  100. bfReply.Access(),
  101. &dwLen);
  102. if (SCARD_S_SUCCESS != lSts)
  103. throw (HRESULT)HRESULT_FROM_WIN32(lSts);
  104. bfReply.Resize(dwLen, TRUE);
  105. }