3

SCardTransmit function is defined in https://msdn.microsoft.com/en-us/library/windows/desktop/aa379804%28v=vs.85%29.aspx

I want to declare and use this function, I have problems with the definition of some arguments in js-ctypes (especially in type casting):

  1. LPCSCARD_IO_REQUEST: A pointer to the protocol header structure
  2. LPCBYTE: A pointer to the actual data to be written to the card
  3. LPBYTE: Pointer to a 32-byte buffer that receives the ATR string from the currently inserted card, if available. (this arg is in the status function)

How Can define, initialize and use them?

Here my code:

//-----------------define types----------------------    
Cu.import('resource://gre/modules/ctypes.jsm');
var TYPES = {
ABI: is64bit ? ctypes.default_abi : ctypes.winapi_abi,
DWORD: ctypes.uint32_t,
LONG: ctypes.long,
BYTE: ctypes.unsigned_char //ctypes.uint8_t
};
TYPES.LPDWORD = TYPES.DWORD.ptr;
TYPES.SCARDCONTEXT = TYPES.ULONG_PTR;
TYPES.SCARDHANDLE = TYPES.ULONG_PTR;
TYPES.LPBYTE = TYPES.BYTE.ptr;
var CONST = { 
SCARD_PROTOCOL_T0: 0x00000000,
SCARD_PROTOCOL_T1: 0x00000001
}

const SCARD_IO_REQUEST = new ctypes.StructType("myStruct" ,
                   [{"dwProtocol": TYPES.DWORD},
                    {"cbPciLength": TYPES.DWORD}]);

//------------------declaration-------------------------
var SCardTransmit = cardLib.declare('SCardTransmit', TYPES.ABI, TYPES.LONG, TYPES.SCARDHANDLE, SCARD_IO_REQUEST.ptr, TYPES.LPBYTE, TYPES.DWORD, SCARD_IO_REQUEST.ptr, TYPES.LPBYTE, TYPES.LPDWORD);
//------------------initializing---------------------
var _SCARD_IO_REQUEST = new SCARD_IO_REQUEST;
    _SCARD_IO_REQUEST.dwProtocol = CONST.SCARD_PROTOCOL_T0|CONST.SCARD_PROTOCOL_T1;
    _SCARD_IO_REQUEST.cbPciLength = _SCARD_IO_REQUEST.dwProtocol.toString().length;
var command = ctypes.char.array(42)("00a4040010a0000000183003010000000000000000");
var commandLength = command.toString().length;
var response = TYPES.LPBYTE;
var responseLength = TYPES.LPDWORD;      
//----------------using-------------------------
var rez_SCT = SCardTransmit(cardHandle, _SCARD_IO_REQUEST, command, commandLength, null, response, responseLength.address());
if(rez_SCT.toString() != CONST.SCARD_S_SUCCESS.toString())
    {
      console.error('cannot begin transaction, error code was: ' + rez_SCT + ' in other terms it is: 0x' + rez_SCT.toString(16) + ' you can look up this error value here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa374738%28v=vs.85%29.aspx#smart_card_return_values');
      throw new Error('failed to begin transactio!');
     }
Hosein Aqajani
  • 1,553
  • 4
  • 26
  • 46
  • 1
    What exactly don't you know/understand? The MSDN page pretty much explains how to use it. – Simon Kraemer Sep 06 '15 at 06:21
  • for example I defined LPCSCARD_IO_REQUEST as follows, is it true? const SCARD_IO_REQUEST = new ctypes.StructType("myStruct", [{"dwProtocol": TYPES.DWORD}, {"cbPciLength": TYPES.DWORD}]); – Hosein Aqajani Sep 06 '15 at 06:51
  • You have a lot of questoins, and there is missing stuff in the code above. Can you maintain your full code on github somewhere so I can help guide you. Otherwise I have to start from scratch and rebuild everytime I try to help you. I requested this in your other topic as well. – Noitidart Sep 06 '15 at 09:01
  • We sorted this out on IRC, the solution is an ongong collaboration. This topic can be deleted/closed. – Noitidart Sep 08 '15 at 20:46
  • Always I have problem with type conversion in jsctypes. even now I have problem with export function (in getAtribute and setAttribute types should be precise defined). I think it is a very good idea that you write a paper sheet for this conversion, because the referencs are sparse and vague. – Hosein Aqajani Sep 12 '15 at 04:33

0 Answers0