Class: Smartcard::Iso::JcopRemoteTransport

Inherits:
Object
  • Object
show all
Includes:
IsoCardMixin, JcopRemoteProtocol
Defined in:
lib/smartcard/iso/jcop_remote_transport.rb

Overview

Implements the transport layer for a JCOP simulator instance.

Instance Method Summary (collapse)

Methods included from JcopRemoteProtocol

#recv_message, #send_message

Methods included from IsoCardMixin

deserialize_response, #iso_apdu, #iso_apdu!, serialize_apdu

Constructor Details

- (JcopRemoteTransport) initialize(options)

Creates a new unconnected transport for a JCOP simulator serving TCP/IP.

The options parameter must have the following keys:

host:: the DNS name or IP of the host running the JCOP simulator
port:: the TCP/IP port of the JCOP simulator server


23
24
25
26
27
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 23

def initialize(options)
  @host, @port = options[:host], options[:port]
  @socket = nil
  @atr = nil
end

Instance Method Details

- (Object) card_atr

:nodoc: standard transport method



39
40
41
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 39

def card_atr
  @atr
end

- (Object) connect

Makes a transport-level connection to the TEM.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 44

def connect
  begin
    @socket = Zerg::Support::SocketFactory.socket :out_addr => @host,
        :out_port => @port, :no_delay => true
    raise 'Connection refused' unless @socket
    
    # Wait for the card to be inserted.
    send_message @socket, :type => 0, :node => 0, :data => [0, 1, 0, 0]
    message = recv_message @socket
    @atr = message[:data].pack('C*')
  rescue Exception
    @socket = nil
    raise
  end
end

- (Object) disconnect

Breaks down the transport-level connection to the TEM.



61
62
63
64
65
66
67
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 61

def disconnect
  if @socket
    @socket.close
    @socket = nil
    @atr = nil
  end
end

- (Object) exchange_apdu(apdu)

:nodoc: standard transport method



30
31
32
33
34
35
36
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 30

def exchange_apdu(apdu)
  send_message @socket, :type => 1, :node => 0, :data => apdu
  loop do
    message = recv_message @socket
    return message[:data] if message[:type] == 1
  end
end

- (Object) to_s



69
70
71
72
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 69

def to_s
  "#<JCOP Remote Terminal: disconnected>" if @socket.nil?
  "#<JCOP Remote Terminal: #{@host}:#{@port}>"
end