Class Smartcard::Iso::JcopRemoteTransport
In: lib/smartcard/iso/jcop_remote_transport.rb
Parent: Object

Implements the transport layer for a JCOP simulator instance.

Methods

card_atr   connect   disconnect   exchange_apdu   new   to_s  

Included Modules

IsoCardMixin JcopRemoteProtocol

Public Class methods

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

[Source]

    # File lib/smartcard/iso/jcop_remote_transport.rb, line 23
23:   def initialize(options)
24:     @host, @port = options[:host], options[:port]
25:     @socket = nil
26:     @atr = nil
27:   end

Public Instance methods

:nodoc: standard transport method

[Source]

    # File lib/smartcard/iso/jcop_remote_transport.rb, line 39
39:   def card_atr
40:     @atr
41:   end

Makes a transport-level connection to the TEM.

[Source]

    # File lib/smartcard/iso/jcop_remote_transport.rb, line 44
44:   def connect
45:     begin
46:       Socket.getaddrinfo(@host, @port, Socket::AF_INET,
47:                          Socket::SOCK_STREAM).each do |addr_info|
48:         begin
49:           @socket = Socket.new(addr_info[4], addr_info[5], addr_info[6])
50:           @socket.connect Socket.pack_sockaddr_in(addr_info[1], addr_info[3])
51:           break
52:         rescue
53:           @socket = nil
54:         end
55:       end  
56:       raise 'Connection refused' unless @socket
57:       
58:       # Wait for the card to be inserted.

59:       send_message @socket, :type => 0, :node => 0, :data => [0, 1, 0, 0]
60:       message = recv_message @socket
61:       @atr = message[:data].pack('C*')
62:     rescue Exception
63:       @socket = nil
64:       raise
65:     end
66:   end

Breaks down the transport-level connection to the TEM.

[Source]

    # File lib/smartcard/iso/jcop_remote_transport.rb, line 69
69:   def disconnect
70:     if @socket
71:       @socket.close
72:       @socket = nil
73:       @atr = nil
74:     end
75:   end

:nodoc: standard transport method

[Source]

    # File lib/smartcard/iso/jcop_remote_transport.rb, line 30
30:   def exchange_apdu(apdu)
31:     send_message @socket, :type => 1, :node => 0, :data => apdu
32:     loop do
33:       message = recv_message @socket
34:       return message[:data] if message[:type] == 1
35:     end
36:   end

[Source]

    # File lib/smartcard/iso/jcop_remote_transport.rb, line 77
77:   def to_s
78:     "#<JCOP Remote Terminal: disconnected>" if @socket.nil?
79:     "#<JCOP Remote Terminal: #{@host}:#{@port}>"
80:   end

[Validate]