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.

107 lines
4.1 KiB

  1. #ifndef _MARSHAL_H_DEF
  2. #define _MARSHAL_H_DEF
  3. // Card SCODEs are 8 bits with msb meaning error
  4. // Win32 SCODEs are 32 bits with msb meaning error
  5. #define MAKESCODE(r) ((SCODE)((((r) & 0x80) != 0) ? (r) | 0xC0000000L : (r)))
  6. #include "wpscproxy.h"
  7. // Smart Card Marshaling structure
  8. typedef struct {
  9. WORD wGenLen; // Size of the generated buffer
  10. WORD wExpLen; // Size of the expanded buffer (after unmarshaling in the card)
  11. WORD wResLen; // Size of the reserved buffer (as returned by the card)
  12. BYTE *pbBuffer; // Pointer where the next argument will be added
  13. } XSCM;
  14. typedef XSCM *LPXSCM;
  15. #define FLAG_REALPCSC 0
  16. #define FLAG_FAKEPCSC 1
  17. #define FLAG_NOT_PCSC 2
  18. #define FLAG_MASKPCSC 1 // To get the PC/SC index in the array below
  19. #define FLAG_TYPEPCSC 3 // To get the PC/SC type
  20. #define FLAG_BIGENDIAN 0x80000000L
  21. #define FLAG_MY_ATTACH 0x40000000L
  22. #define FLAG_ISPROXY 0x20000000L
  23. #define FLAG_MASKVER 0x00FF0000L
  24. #define FLAG2VERSION(dw) ((dw)&FLAG_MASKVER)
  25. #define VERSION_1_0 0x00100000L
  26. #define VERSION_1_1 0x00110000L
  27. typedef struct {
  28. SCARDCONTEXT hCtx; // Associated ResMgr context
  29. SCARDHANDLE hCard; // Associated PC/SC card handle
  30. DWORD dwFlags; //
  31. DWORD dwProtocol;
  32. LPFNSCWTRANSMITPROC lpfnTransmit;
  33. BYTE bResLen; // Reserved length in TheBuffer in the card
  34. BYTE *pbLc; // Stores Crt SCM pointer for future update
  35. XSCM xSCM;
  36. BYTE byINS; // INS to be used for proxy
  37. BYTE byCryptoM; // Last Crypto mechanism
  38. } MYSCARDHANDLE;
  39. typedef MYSCARDHANDLE *LPMYSCARDHANDLE;
  40. //
  41. // Copies the current SCARDHANDLE, owned by the caller, into the proxy
  42. // MYSCARDHANDLE context structure. This is necessary in case the original
  43. // SCARDHANDLE used to connect has become invalid and subsequently reconnected.
  44. //
  45. static void ProxyUpdateScardHandle(
  46. IN SCARDHANDLE hProxy,
  47. IN SCARDHANDLE hScardHandle)
  48. {
  49. ((LPMYSCARDHANDLE) hProxy)->hCard = hScardHandle;
  50. }
  51. // Raisable exceptions
  52. #define STATUS_INSUFFICIENT_MEM 0xE0000001
  53. #define STATUS_INVALID_PARAM 0xE0000002
  54. #define STATUS_NO_SERVICE 0xE0000003
  55. #define STATUS_INTERNAL_ERROR 0xE0000004
  56. // len will set wResLen in the above structure
  57. // If wExpLen gets bigger than wResLen, an exception will be generated (marshaling)
  58. // If wResLen indicates that the buffer cannot hold the parameter, an exception
  59. // will be raised too (unmarshaling)
  60. void InitXSCM(LPMYSCARDHANDLE phTmp, const BYTE *pbBuffer, WORD len);
  61. // Generated buffer length
  62. WORD GetSCMBufferLength(LPXSCM pxSCM);
  63. BYTE *GetSCMCrtPointer(LPXSCM pxSCM);
  64. // Extraction of data from the returned buffer (PC unmarshaling)
  65. // helper functions
  66. SCODE XSCM2SCODE(LPXSCM pxSCM);
  67. UINT8 XSCM2UINT8(LPXSCM pxSCM);
  68. HFILE XSCM2HFILE(LPXSCM pxSCM);
  69. UINT16 XSCM2UINT16(LPXSCM pxSCM, BOOL fBigEndian);
  70. WCSTR XSCM2String(LPXSCM pxSCM, UINT8 *plen, BOOL fBigEndian);
  71. TCOUNT XSCM2ByteArray(LPXSCM pxSCM, UINT8 **ppb);
  72. // Laying out of data in the buffer to be sent (PC marshaling)
  73. // helper functions
  74. #define TYPE_NOTYPE_NOCOUNT 0 // Not prefixed with type, not data
  75. #define TYPE_TYPED 1 // Prefixed with type (always counts)
  76. #define TYPE_NOTYPE_COUNT 2 // Not prefixed with type, but is data
  77. void UINT82XSCM(LPXSCM pxSCM, UINT8 val, int type);
  78. void HFILE2XSCM(LPXSCM pxSCM, HFILE val);
  79. void UINT162XSCM(LPXSCM pxSCM, UINT16 val, BOOL fBigEndian);
  80. void ByteArray2XSCM(LPXSCM pxSCM, const BYTE *pbBuffer, TCOUNT len);
  81. void String2XSCM(LPXSCM pxSCM, WCSTR wsz, BOOL fBigEndian);
  82. void SW2XSCM(LPXSCM pxSCM, UINT16 wSW);
  83. void UINT8BYREF2XSCM(LPXSCM pxSCM, UINT8 *val);
  84. void HFILEBYREF2XSCM(LPXSCM pxSCM, HFILE *val);
  85. void UINT16BYREF2XSCM(LPXSCM pxSCM, UINT16 *val, BOOL fBigEndian);
  86. void ByteArrayOut2XSCM(LPXSCM pxSCM, BYTE *pb, TCOUNT len);
  87. void StringOut2XSCM(LPXSCM pxSCM, WSTR wsz, TCOUNT len, BOOL fBigEndian);
  88. void NULL2XSCM(LPXSCM pxSCM);
  89. #endif