ctapi 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -4
- data/{GPL → COPYING} +7 -7
- data/README +49 -0
- data/Rakefile +76 -57
- data/VERSION +1 -1
- data/{examples → bin}/cardinfo.rb +2 -2
- data/bin/ctsh.rb +21 -0
- data/ctapi.gemspec +31 -0
- data/doc-main.txt +39 -0
- data/ext/ctapicore.c +164 -163
- data/ext/extconf.rb +5 -2
- data/install.rb +9 -5
- data/lib/ctapi.rb +521 -560
- data/lib/ctapi/version.rb +8 -0
- data/tests/test.rb +36 -36
- metadata +68 -45
- data/README.en +0 -31
- data/examples/ctsh.rb +0 -10
- data/make_doc.rb +0 -6
data/CHANGES
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
2004-
|
1
|
+
2009-07-25 (0.2.3)
|
2
|
+
* Build gemspec file.
|
3
|
+
* Some cleanup.
|
4
|
+
2004-09-30 (0.2.2)
|
5
|
+
* First Rubyforge Release
|
6
|
+
* Rakefile added.
|
7
|
+
* Rubygems support
|
8
|
+
2004-04-20 (0.2.1)
|
9
|
+
* Initial Release
|
data/{GPL → COPYING}
RENAMED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
Version 2, June 1991
|
3
3
|
|
4
4
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5
5
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
6
6
|
Everyone is permitted to copy and distribute verbatim copies
|
7
7
|
of this license document, but changing it is not allowed.
|
8
8
|
|
9
|
-
|
9
|
+
Preamble
|
10
10
|
|
11
11
|
The licenses for most software are designed to take away your
|
12
12
|
freedom to share and change it. By contrast, the GNU General Public
|
@@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all.
|
|
56
56
|
The precise terms and conditions for copying, distribution and
|
57
57
|
modification follow.
|
58
58
|
|
59
|
-
|
59
|
+
GNU GENERAL PUBLIC LICENSE
|
60
60
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61
61
|
|
62
62
|
0. This License applies to any program or other work which contains
|
@@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
|
|
255
255
|
of preserving the free status of all derivatives of our free software and
|
256
256
|
of promoting the sharing and reuse of software generally.
|
257
257
|
|
258
|
-
|
258
|
+
NO WARRANTY
|
259
259
|
|
260
260
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261
261
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
277
277
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278
278
|
POSSIBILITY OF SUCH DAMAGES.
|
279
279
|
|
280
|
-
|
280
|
+
END OF TERMS AND CONDITIONS
|
281
281
|
|
282
|
-
|
282
|
+
How to Apply These Terms to Your New Programs
|
283
283
|
|
284
284
|
If you develop a new program, and you want it to be of the greatest
|
285
285
|
possible use to the public, the best way to achieve this is to make it
|
data/README
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Requirements
|
2
|
+
============
|
3
|
+
|
4
|
+
You need to install a driver library, that supports the CTAPI interface for
|
5
|
+
this extension to link against. The newest version of the towitoko library,
|
6
|
+
that is required to drive the Towitoko Chipdrive Micro, Extern, Extern II,
|
7
|
+
Intern, Twin, and the "Kartenzwerg", can be download at this URL:
|
8
|
+
|
9
|
+
http://www.geocities.com/cprados
|
10
|
+
|
11
|
+
Installation
|
12
|
+
============
|
13
|
+
|
14
|
+
Install the gem with
|
15
|
+
|
16
|
+
# CTAPI_LIBRARY=LIBRARYNAME gem install ctapi
|
17
|
+
|
18
|
+
and the extension should be built and installed.
|
19
|
+
|
20
|
+
Alternatively you can just type into the command line as root:
|
21
|
+
|
22
|
+
# CTAPI_LIBRARY=LIBRARYNAME ruby install.rb
|
23
|
+
|
24
|
+
where LIBRARYNAME is the name of the ctapi driver library to use. If you want
|
25
|
+
to link against the towitoko library, this would be, e. g.,
|
26
|
+
|
27
|
+
# CTAPI_LIBRARY=LIBRARYNAME ruby install.rb
|
28
|
+
|
29
|
+
towitoko is also the default choice for the library.
|
30
|
+
|
31
|
+
Documentation
|
32
|
+
=============
|
33
|
+
|
34
|
+
To generate the documentation in doc/ type:
|
35
|
+
$ ruby make_doc.rb
|
36
|
+
|
37
|
+
Also look into the cardinfo.rb and ctsh.rb executables if you want to see how
|
38
|
+
to use this library.
|
39
|
+
|
40
|
+
Author
|
41
|
+
======
|
42
|
+
|
43
|
+
Florian Frank <flori@ping.de>
|
44
|
+
|
45
|
+
License
|
46
|
+
=======
|
47
|
+
|
48
|
+
GNU General Public License (GPL), Version 2
|
49
|
+
|
data/Rakefile
CHANGED
@@ -1,54 +1,58 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
begin
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
3
5
|
require 'rake/clean'
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rake/gempackagetask'
|
6
6
|
require 'rbconfig'
|
7
|
-
|
8
7
|
include Config
|
9
8
|
|
10
9
|
PKG_NAME = 'ctapi'
|
11
10
|
PKG_VERSION = File.read('VERSION').chomp
|
12
|
-
PKG_FILES =
|
13
|
-
|
14
|
-
|
15
|
-
task :default => [:compile]
|
11
|
+
PKG_FILES = FileList['**/*'].exclude(/(CVS|\.svn|pkg|coverage|doc)/)
|
12
|
+
CLEAN.include 'coverage', 'doc'
|
16
13
|
|
17
14
|
desc "Run unit tests"
|
18
|
-
task(:test => [:compile]) do
|
15
|
+
task(:test => [ :compile ]) do
|
19
16
|
ruby %{-Iext tests/test.rb}
|
20
17
|
end
|
21
18
|
|
19
|
+
desc "Run unit tests with rcov"
|
20
|
+
task(:coverage => [:compile]) do
|
21
|
+
system %{rcov -x tests -Ilib -Iext tests/test.rb}
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Creating documentation"
|
25
|
+
task :doc do
|
26
|
+
ruby 'make_doc.rb'
|
27
|
+
end
|
28
|
+
|
22
29
|
desc "Compiling library"
|
23
30
|
task :compile do
|
24
31
|
cd 'ext' do
|
25
|
-
ruby %Q{extconf.rb
|
32
|
+
ruby %Q{extconf.rb}
|
26
33
|
system "make"
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
30
37
|
desc "Installing library"
|
31
38
|
task(:install => [:compile]) do
|
32
|
-
|
33
|
-
filename = File.basename(src)
|
34
|
-
dst = File.join(CONFIG["sitelibdir"], filename)
|
35
|
-
install(src, dst, :verbose => true)
|
39
|
+
ruby 'install.rb'
|
36
40
|
end
|
37
41
|
|
38
42
|
desc "Cleaning built files"
|
39
43
|
task :clean do
|
40
44
|
cd 'ext' do
|
41
|
-
system "make distclean"
|
45
|
+
File.exist?('Makefile') and system "make distclean"
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
s.name = '
|
50
|
-
s.version = PKG_VERSION
|
51
|
-
s.summary =
|
49
|
+
if defined? Gem
|
50
|
+
spec_src =<<GEM
|
51
|
+
# -*- encoding: utf-8 -*-
|
52
|
+
Gem::Specification.new do |s|
|
53
|
+
s.name = '#{PKG_NAME}'
|
54
|
+
s.version = '#{PKG_VERSION}'
|
55
|
+
s.summary = 'Ruby extension for Chipcard Cardterminal-API (CTAPI)'
|
52
56
|
s.description = <<EOF
|
53
57
|
These are Ruby bindings to a library that supports the Cardterminal-API (CTAPI)
|
54
58
|
for chipcards. It should be possible to link this against any carddriver
|
@@ -56,45 +60,60 @@ library that supports this standard, but I have actually only tested with
|
|
56
60
|
libtowitoko.
|
57
61
|
EOF
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
#s.add_dependency('log4r', '> 1.0.4')
|
62
|
-
#s.requirements << ""
|
63
|
-
|
64
|
-
s.files = PKG_FILES
|
63
|
+
s.files = #{PKG_FILES.to_a.sort.inspect}
|
65
64
|
|
66
|
-
|
65
|
+
s.extensions << 'ext/extconf.rb'
|
66
|
+
s.require_path = 'lib'
|
67
67
|
|
68
|
-
s.
|
68
|
+
s.bindir = "bin"
|
69
|
+
s.executables = %w[cardinfo.rb ctsh.rb]
|
70
|
+
s.default_executable = "ctsh.rb"
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
s.
|
73
|
-
s.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
s.has_rdoc = true
|
73
|
+
s.rdoc_options << '--main' << 'doc-main.txt'
|
74
|
+
s.extra_rdoc_files << 'doc-main.txt'
|
75
|
+
s.test_files << 'tests/test.rb'
|
76
|
+
|
77
|
+
s.author = 'Florian Frank'
|
78
|
+
s.email = 'flori@ping.de'
|
79
|
+
s.homepage = 'http://#{PKG_NAME}.rubyforge.org'
|
80
|
+
s.rubyforge_project = '#{PKG_NAME}'
|
81
|
+
end
|
82
|
+
GEM
|
78
83
|
|
79
|
-
|
84
|
+
desc 'Create a gemspec file'
|
85
|
+
task :gemspec do
|
86
|
+
File.open("#{PKG_NAME}.gemspec", 'w') do |f|
|
87
|
+
f.puts spec_src
|
88
|
+
end
|
89
|
+
end
|
80
90
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
# '--line-numbers'
|
87
|
-
|
88
|
-
#### Author and project details.
|
89
|
-
|
90
|
-
s.author = "Florian Frank"
|
91
|
-
s.email = "flori@ping.de"
|
92
|
-
s.homepage = "http://ctapi.rubyforge.org"
|
93
|
-
s.rubyforge_project = "ctapi"
|
91
|
+
spec = eval(spec_src)
|
92
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
93
|
+
pkg.need_tar = true
|
94
|
+
pkg.package_files += PKG_FILES
|
95
|
+
end
|
94
96
|
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
|
98
|
+
desc m = "Writing version information for #{PKG_VERSION}"
|
99
|
+
task :version do
|
100
|
+
puts m
|
101
|
+
File.open(File.join('lib', 'ctapi', 'version.rb'), 'w') do |v|
|
102
|
+
v.puts <<EOT
|
103
|
+
module CTAPI
|
104
|
+
# CTAPI version
|
105
|
+
VERSION = '#{PKG_VERSION}'
|
106
|
+
VERSION_ARRAY = VERSION.split(/\\./).map { |x| x.to_i } # :nodoc:
|
107
|
+
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
108
|
+
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
109
|
+
VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
|
110
|
+
end
|
111
|
+
EOT
|
112
|
+
end
|
99
113
|
end
|
100
|
-
|
114
|
+
|
115
|
+
desc "Default"
|
116
|
+
task :default => [ :version, :gemspec, :test ]
|
117
|
+
|
118
|
+
desc "Prepare a release"
|
119
|
+
task :release => [ :clean, :version, :gemspec, :package ]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -3,7 +3,8 @@
|
|
3
3
|
require 'ctapi'
|
4
4
|
include CTAPI
|
5
5
|
|
6
|
-
|
6
|
+
interface = (ARGV.shift || PORT_COM1).to_i
|
7
|
+
Cardterminal.open(interface) do |ct|
|
7
8
|
puts "Cardterminal Manufacturer: " + ct.manufacturer.to_s
|
8
9
|
if ct.card_inserted?
|
9
10
|
card = ct.card
|
@@ -23,4 +24,3 @@ Cardterminal.open(PORT_COM1) do |ct|
|
|
23
24
|
puts "Please insert a card into your cardterminal!"
|
24
25
|
end
|
25
26
|
end
|
26
|
-
# vim: set et sw=2 ts=2:
|
data/bin/ctsh.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'irb'
|
4
|
+
require 'irb/completion'
|
5
|
+
require 'ctapi'
|
6
|
+
|
7
|
+
module ::IRB
|
8
|
+
def self.examine(binding = TOPLEVEL_BINDING)
|
9
|
+
setup nil
|
10
|
+
workspace = WorkSpace.new binding
|
11
|
+
irb = Irb.new workspace
|
12
|
+
@CONF[:MAIN_CONTEXT] = irb.context
|
13
|
+
catch(:IRB_EXIT) { irb.eval_input }
|
14
|
+
rescue Interrupt
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
include CTAPI
|
20
|
+
|
21
|
+
IRB.examine Cardterminal.new((ARGV.shift || PORT_COM1).to_i)
|
data/ctapi.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'ctapi'
|
4
|
+
s.version = '0.2.3'
|
5
|
+
s.summary = 'Ruby extension for Chipcard Cardterminal-API (CTAPI)'
|
6
|
+
s.description = <<EOF
|
7
|
+
These are Ruby bindings to a library that supports the Cardterminal-API (CTAPI)
|
8
|
+
for chipcards. It should be possible to link this against any carddriver
|
9
|
+
library that supports this standard, but I have actually only tested with
|
10
|
+
libtowitoko.
|
11
|
+
EOF
|
12
|
+
|
13
|
+
s.files = ["CHANGES", "COPYING", "README", "Rakefile", "VERSION", "bin", "bin/cardinfo.rb", "bin/ctsh.rb", "ctapi.gemspec", "ext", "ext/ctapicore.c", "ext/extconf.rb", "install.rb", "lib", "lib/ctapi", "lib/ctapi.rb", "lib/ctapi/version.rb", "tests", "tests/test.rb"]
|
14
|
+
|
15
|
+
s.extensions << 'ext/extconf.rb'
|
16
|
+
s.require_path = 'lib'
|
17
|
+
|
18
|
+
s.bindir = "bin"
|
19
|
+
s.executables = %w[cardinfo.rb ctsh.rb]
|
20
|
+
s.default_executable = "ctsh.rb"
|
21
|
+
|
22
|
+
s.has_rdoc = true
|
23
|
+
s.rdoc_options << '--main' << 'doc-main.txt'
|
24
|
+
s.extra_rdoc_files << 'doc-main.txt'
|
25
|
+
s.test_files << 'tests/test.rb'
|
26
|
+
|
27
|
+
s.author = 'Florian Frank'
|
28
|
+
s.email = 'flori@ping.de'
|
29
|
+
s.homepage = 'http://ctapi.rubyforge.org'
|
30
|
+
s.rubyforge_project = 'ctapi'
|
31
|
+
end
|
data/doc-main.txt
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
There are two possible ways to use this library:
|
2
|
+
|
3
|
+
- You can require 'ctapicore' and directly use the ct_init, ct_data and
|
4
|
+
ct_close methods . That will give you access to the very simple C-Interface
|
5
|
+
in Ruby, but you have to send APDU commands and receive and interpret APDU
|
6
|
+
Responses yourself:
|
7
|
+
|
8
|
+
require 'ctapicore'
|
9
|
+
include CTAPICore
|
10
|
+
ct_init(PORT_COM1, 0)
|
11
|
+
response = ct_data(0, CT, HOST, "\x12\x34\x56")
|
12
|
+
p response
|
13
|
+
ct_close(0)
|
14
|
+
|
15
|
+
- You can require 'ctapi' and the module CTAPI has some nice abstractions to
|
16
|
+
deal with cardterminals, cards and APDUs, which are much more the Ruby Way:
|
17
|
+
|
18
|
+
require 'ctapi'
|
19
|
+
include CTAPI
|
20
|
+
Cardterminal.open(PORT_COM1) do |ct|
|
21
|
+
puts "Cardterminal Manufacturer: " + ct.manufacturer.to_s
|
22
|
+
if ct.card_inserted?
|
23
|
+
card = ct.card
|
24
|
+
puts "My Cardterminal object: #{ct.inspect}"
|
25
|
+
puts "Current card status is: #{ct.card_status}"
|
26
|
+
puts "Answer to Reset is #{card.atr}."
|
27
|
+
puts "ATR ok? #{card.atr_ok?}."
|
28
|
+
puts "Memory size of this card is #{card.memory_size} bytes" +
|
29
|
+
(#{card.memory_blocks} blocks x #{card.memory_bits} bit)."
|
30
|
+
puts "Structure of this card is #{card.structure}."
|
31
|
+
puts "Supported protocol type of this card is #{card.protocol}."
|
32
|
+
puts "Trying to read(0, 16):"
|
33
|
+
data = ct.read(0, 16)
|
34
|
+
puts "Have read #{data.size} bytes:"
|
35
|
+
p data
|
36
|
+
else
|
37
|
+
puts "Please insert a card into your cardterminal!"
|
38
|
+
end
|
39
|
+
end
|
data/ext/ctapicore.c
CHANGED
@@ -69,48 +69,48 @@
|
|
69
69
|
* CTBCS_SW2_REQUEST_CARD_PRESENT
|
70
70
|
* CTBCS_SW2_REQUEST_ERROR
|
71
71
|
* CTBCS_SW2_REQUEST_NO_CARD
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
72
|
+
* CTBCS_SW2_REQUEST_SYNC_OK
|
73
|
+
* CTBCS_SW2_REQUEST_TIMER_ERROR
|
74
|
+
* CTBCS_SW2_RESET_ASYNC_OK
|
75
|
+
* CTBCS_SW2_RESET_CT_OK
|
76
|
+
* CTBCS_SW2_RESET_ERROR
|
77
|
+
* CTBCS_SW2_RESET_SYNC_OK
|
78
|
+
* CTBCS_SW2_WRONG_CLA
|
79
|
+
* CTBCS_SW2_WRONG_INS
|
80
|
+
* CTBCS_SW2_WRONG_LENGTH
|
81
|
+
* CTBCS_SW2_WRONG_PARAM
|
82
|
+
* ERR_CT
|
83
|
+
* ERR_HTSI
|
84
|
+
* ERR_INVALID
|
85
|
+
* ERR_MEMORY
|
86
|
+
* ERR_TRANS
|
87
|
+
* HOST
|
88
|
+
* HTSIError
|
89
|
+
* ICC1
|
90
|
+
* ICC10
|
91
|
+
* ICC11
|
92
|
+
* ICC12
|
93
|
+
* ICC13
|
94
|
+
* ICC14
|
95
|
+
* ICC2
|
96
|
+
* ICC3
|
97
|
+
* ICC4
|
98
|
+
* ICC5
|
99
|
+
* ICC6
|
100
|
+
* ICC7
|
101
|
+
* ICC8
|
102
|
+
* ICC9
|
103
|
+
* MAX_APDULEN
|
104
|
+
* OK
|
105
|
+
* PORT_COM1
|
106
|
+
* PORT_COM2
|
107
|
+
* PORT_COM3
|
108
|
+
* PORT_COM4
|
109
|
+
* PORT_LPT1
|
110
|
+
* PORT_LPT2
|
111
|
+
* PORT_Modem
|
112
|
+
* PORT_Printer
|
113
|
+
*/
|
114
114
|
|
115
115
|
#include "ruby.h"
|
116
116
|
#include <ctapi.h>
|
@@ -118,35 +118,35 @@
|
|
118
118
|
#define NUM2USHRT(n) NUM2UINT(n)
|
119
119
|
|
120
120
|
static VALUE mCTAPICore, eCTAPIError, eInvalidError, eCardterminalError,
|
121
|
-
|
121
|
+
eTransmissionError, eMemoryError, eHTSIError, eUnknownError;
|
122
122
|
|
123
123
|
/*
|
124
124
|
* Wrap the returned errors into a nice Ruby Exception and throw it.
|
125
125
|
*/
|
126
126
|
void try(char rv) {
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
127
|
+
switch (rv) {
|
128
|
+
case OK:
|
129
|
+
return;
|
130
|
+
case ERR_INVALID:
|
131
|
+
rb_raise(eInvalidError, "Invalid Data: %d", rv);
|
132
|
+
case ERR_CT:
|
133
|
+
rb_raise(eCardterminalError, "Cardterminal Error: %d", rv);
|
134
|
+
case ERR_TRANS:
|
135
|
+
rb_raise(eTransmissionError, "Transmission Error: %d", rv);
|
136
|
+
case ERR_MEMORY:
|
137
|
+
rb_raise(eMemoryError, "Memory Allocate Error: %d", rv);
|
138
|
+
case ERR_HTSI:
|
139
|
+
rb_raise(eHTSIError, "Host Transport Service Interface Error:: %d",
|
140
|
+
rv); default:
|
141
|
+
rb_raise(eUnknownError, "Unknown Error: %d", rv);
|
142
|
+
}
|
143
143
|
}
|
144
144
|
|
145
145
|
/*
|
146
146
|
* We wrap CT_init to get the exceptions right.
|
147
147
|
*/
|
148
148
|
void ct_init(unsigned short Ctn, unsigned short pn) {
|
149
|
-
|
149
|
+
try(CT_init(Ctn, pn));
|
150
150
|
}
|
151
151
|
|
152
152
|
/*
|
@@ -156,51 +156,51 @@ void ct_init(unsigned short Ctn, unsigned short pn) {
|
|
156
156
|
void
|
157
157
|
debug_command (unsigned char * buffer, unsigned length)
|
158
158
|
{
|
159
|
-
|
159
|
+
unsigned i;
|
160
160
|
|
161
|
-
|
162
|
-
|
161
|
+
if (length > 16)
|
162
|
+
fprintf (stderr, "\n");
|
163
163
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
164
|
+
for (i=0; i<length; i++)
|
165
|
+
{
|
166
|
+
fprintf (stderr, "%02X ", buffer[i]);
|
167
|
+
if (i%16 == 15)
|
168
|
+
fprintf (stderr, "\n");
|
169
|
+
}
|
170
170
|
|
171
|
-
|
172
|
-
|
171
|
+
if (i%16 != 0)
|
172
|
+
fprintf (stderr, "\n");
|
173
173
|
}
|
174
174
|
|
175
175
|
/*
|
176
176
|
* We wrap CT_data to get the exceptions and debugging right.
|
177
177
|
*/
|
178
178
|
char *ct_data(
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
179
|
+
unsigned short Ctn, /* Terminal Number */
|
180
|
+
unsigned char dad, /* Destination */
|
181
|
+
unsigned char sad, /* Source */
|
182
|
+
unsigned char *cmd, /* Command/Data Buffer */
|
183
|
+
unsigned short lc, /* Length of Command */
|
184
|
+
unsigned short *lr /* Length of Response */
|
185
|
+
)
|
186
186
|
{
|
187
|
-
|
188
|
-
|
187
|
+
*lr = MAX_APDULEN;
|
188
|
+
unsigned char *rsp = ALLOC_N(unsigned char, *lr); /* Response */
|
189
189
|
#if DEBUG
|
190
|
-
|
190
|
+
debug_command(cmd, lc);
|
191
191
|
#endif
|
192
|
-
|
192
|
+
try(CT_data(Ctn, &dad, &sad, lc, cmd, lr, rsp));
|
193
193
|
#if DEBUG
|
194
|
-
|
194
|
+
debug_command(rsp, *lr);
|
195
195
|
#endif
|
196
|
-
|
196
|
+
return (char *) rsp;
|
197
197
|
}
|
198
198
|
|
199
199
|
/*
|
200
200
|
* We wrap CT_close to get the exceptions right.
|
201
201
|
*/
|
202
202
|
void ct_close(unsigned short Ctn) {
|
203
|
-
|
203
|
+
try(CT_close(Ctn));
|
204
204
|
}
|
205
205
|
|
206
206
|
/*
|
@@ -212,13 +212,13 @@ static VALUE
|
|
212
212
|
ctapi_ct_init(int argc, VALUE *argv, VALUE self) {
|
213
213
|
unsigned short arg1 ;
|
214
214
|
unsigned short arg2 ;
|
215
|
-
|
215
|
+
|
216
216
|
if ((argc < 2) || (argc > 2))
|
217
|
-
|
217
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)", argc);
|
218
218
|
arg1 = NUM2USHRT(argv[0]);
|
219
219
|
arg2 = NUM2USHRT(argv[1]);
|
220
220
|
ct_init(arg1, arg2);
|
221
|
-
|
221
|
+
|
222
222
|
return Qnil;
|
223
223
|
}
|
224
224
|
|
@@ -237,19 +237,19 @@ ctapi_ct_data(int argc, VALUE *argv, VALUE self) {
|
|
237
237
|
char *arg4 ;
|
238
238
|
unsigned short length;
|
239
239
|
char *result;
|
240
|
-
|
240
|
+
unsigned short lr;
|
241
241
|
VALUE vresult = Qnil;
|
242
|
-
|
242
|
+
|
243
243
|
if ((argc < 4) || (argc > 4))
|
244
|
-
|
244
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 4)", argc);
|
245
245
|
arg1 = NUM2USHRT(argv[0]);
|
246
246
|
arg2 = NUM2UINT(argv[1]);
|
247
247
|
arg3 = NUM2UINT(argv[2]);
|
248
|
-
|
249
|
-
|
248
|
+
arg4 = RSTRING(argv[3])->ptr;
|
249
|
+
length = RSTRING(argv[3])->len;
|
250
250
|
result = (char *) ct_data(arg1, arg2, arg3, arg4, length, &lr);
|
251
251
|
vresult = rb_str_new(result, lr);
|
252
|
-
|
252
|
+
ruby_xfree(result);
|
253
253
|
return vresult;
|
254
254
|
}
|
255
255
|
|
@@ -260,12 +260,12 @@ ctapi_ct_data(int argc, VALUE *argv, VALUE self) {
|
|
260
260
|
static VALUE
|
261
261
|
ctapi_ct_close(int argc, VALUE *argv, VALUE self) {
|
262
262
|
unsigned short arg1 ;
|
263
|
-
|
263
|
+
|
264
264
|
if ((argc < 1) || (argc > 1))
|
265
|
-
|
265
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc);
|
266
266
|
arg1 = NUM2USHRT(argv[0]);
|
267
267
|
ct_close(arg1);
|
268
|
-
|
268
|
+
|
269
269
|
return Qnil;
|
270
270
|
}
|
271
271
|
|
@@ -347,71 +347,72 @@ void Init_ctapicore(void) {
|
|
347
347
|
rb_define_const(mCTAPICore, "CTBCS_DATA_STATUS_CARD", INT2NUM(0x01));
|
348
348
|
rb_define_const(mCTAPICore, "CTBCS_DATA_STATUS_CARD_CONNECT", INT2NUM(0x05));
|
349
349
|
rb_define_const(mCTAPICore, "MAX_APDULEN", INT2NUM(MAX_APDULEN));
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
350
|
+
rb_define_const(mCTAPICore, "OK", INT2NUM(0));
|
351
|
+
rb_define_const(mCTAPICore, "ERR_INVALID", INT2NUM(-1));
|
352
|
+
rb_define_const(mCTAPICore, "ERR_CT", INT2NUM(-8));
|
353
|
+
rb_define_const(mCTAPICore, "ERR_TRANS", INT2NUM(-10));
|
354
|
+
rb_define_const(mCTAPICore, "ERR_MEMORY", INT2NUM(-11));
|
355
|
+
rb_define_const(mCTAPICore, "ERR_HTSI", INT2NUM(-128));
|
356
|
+
/*
|
357
|
+
* Document-class: CTAPICore::CTAPIError
|
358
|
+
*
|
359
|
+
* All error exceptions in CTAPICore are of class CTAPIError which is a
|
360
|
+
* child of StandardError.
|
361
|
+
*/
|
362
|
+
eCTAPIError =
|
363
|
+
rb_define_class_under(mCTAPICore, "CTAPIError", rb_eStandardError);
|
364
|
+
/*
|
365
|
+
* Document-class: CTAPICore::InvalidError
|
366
|
+
*
|
367
|
+
* This exception is raised if an invalid parameter was used for
|
368
|
+
* CTAPICore function.
|
369
|
+
*/
|
370
|
+
eInvalidError =
|
371
|
+
rb_define_class_under(mCTAPICore, "InvalidError", eCTAPIError);
|
372
|
+
/*
|
373
|
+
* Document-class: CTAPICore::CardterminalError
|
374
|
+
*
|
375
|
+
* This exception is raised if the cardterminal is temporarily not
|
376
|
+
* accessible (busy with other or internal processes). The problem can
|
377
|
+
* be solved by the application. Just retry.
|
378
|
+
*/
|
379
|
+
eCardterminalError =
|
380
|
+
rb_define_class_under(mCTAPICore, "CardterminalError", eCTAPIError);
|
381
|
+
/*
|
382
|
+
* Document-class: CTAPICore::TransmissionError
|
383
|
+
*
|
384
|
+
* This exception is raised if a mechanical, electrical or protocol
|
385
|
+
* failures. Reset of the cardterminal is necessary.
|
386
|
+
*/
|
387
|
+
eTransmissionError =
|
388
|
+
rb_define_class_under(mCTAPICore, "TransmissionError", eCTAPIError);
|
389
|
+
/*
|
390
|
+
* Document-class: CTAPICore::MemoryError
|
391
|
+
*
|
392
|
+
* This exception is raised if a memory error occurred (f.i. the
|
393
|
+
* allocated buffer is too small for the returned data). This should
|
394
|
+
* NOT happen. If it does, it's a bug. Please tell me.
|
395
|
+
*/
|
396
|
+
eMemoryError =
|
397
|
+
rb_define_class_under(mCTAPICore, "MemoryError", eCTAPIError);
|
398
|
+
/*
|
399
|
+
* Document-class: CTAPICore::HTSIError
|
400
|
+
*
|
401
|
+
* This exception (HTSI = Host Transport Service Interface) is raised if
|
402
|
+
* the error is produced by the software layer and not in the
|
403
|
+
* communication with the hardware.
|
404
|
+
*/
|
405
|
+
eHTSIError =
|
406
|
+
rb_define_class_under(mCTAPICore, "HTSIError", eCTAPIError);
|
407
|
+
/*
|
408
|
+
* Document-class: CTAPICore::UnknownError
|
409
|
+
*
|
410
|
+
* This exception is raised if an unkown error occurrs. This also should
|
411
|
+
* NOT happen. If it does, it's a bug. Please tell me.
|
412
|
+
*/
|
413
|
+
eUnknownError =
|
414
|
+
rb_define_class_under(mCTAPICore, "UnknownError", eCTAPIError);
|
415
|
+
|
415
416
|
rb_define_const(mCTAPICore, "PORT_COM1", INT2NUM(0));
|
416
417
|
rb_define_const(mCTAPICore, "PORT_COM2", INT2NUM(1));
|
417
418
|
rb_define_const(mCTAPICore, "PORT_COM3", INT2NUM(2));
|
@@ -440,4 +441,4 @@ void Init_ctapicore(void) {
|
|
440
441
|
rb_define_module_function(mCTAPICore, "ct_data", ctapi_ct_data, -1);
|
441
442
|
rb_define_module_function(mCTAPICore, "ct_close", ctapi_ct_close, -1);
|
442
443
|
}
|
443
|
-
|
444
|
+
/* vim: set et cin sw=4 ts=4: */
|