aboutsummaryrefslogtreecommitdiffstats
path: root/src/demo_client.rb
blob: e04e30293a745b9f48f132e3c4fc6b2edf96c9ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
#!/usr/bin/env ruby
=begin
This file is part of SAP.

SAP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SAP.  If not, see <http://www.gnu.org/licenses/>.

Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end
# This programm will create a client which can be used to test servers
require 'lib/client'
require 'lib/apdu'

#=================
#== client type ==
#=================

# wich IO to use
client_io = :tcp
# the IO itself
io = nil
# create IO
case client_io
when :tcp
  require 'socket'
  host = "localhost"
  port = 1337
  io = TCPSocket.open(host,port)
when :bt
  require 'lib/bluetooth_sap_serial'
  #sudo gem install serialport (http://rubygems.org/gems/serialport)
  require 'rubygems'
  require 'serialport'
=begin
to monitor bluetooth traffic
sudo aptitude install bluez-hcidump
sudo hcidump -x -i hci0 rfcomm
=end
  bt = BluetoothSAPSerial.new
  # using SerialPort because reading the File does not work (have to find right stty options)
  io = SerialPort.new(bt.connect)
else
  raise "please defined which client to use"
end

#===============
#== constants ==
#===============

# to debug the program
# shows APDU IO
DEBUG = true
# the verbosity from common
VERBOSE = 0

#=============
#== methods ==
#=============

include APDU

def transmit_apdu(apdu)
  return @client.apdu(apdu)
end

#==========
#== main ==
#==========

@client = Client.new(io,VERBOSE)
@client.start
@client.connect
atr = @client.atr
puts atr ? "ATR : #{atr.to_hex_disp}" :  "could not get ATR"
# select MF
transmit(GET_RESPONSE+[0x1a])
select(MF)
@client.disconnect

# close client_io
case client_io
when :tcp
  io.close
when :bt
  io.close
  bt.close
end