updated to ruby1.9 (I may have missed some), and fixed some bugs/typos
This commit is contained in:
parent
9bb57d7ac6
commit
81db0e7926
|
@ -18,7 +18,7 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
|
|||
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
|
||||
=end
|
||||
# this programm will forward APDU from an IO to a SAP server
|
||||
require 'sap/client'
|
||||
require './sap/client.rb'
|
||||
require 'socket'
|
||||
|
||||
SAP_HOST = "localhost"
|
||||
|
|
|
@ -17,8 +17,8 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
|
|||
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
|
||||
=end
|
||||
# this class copies all files from the SIM to an xml file
|
||||
require 'sap/client'
|
||||
require 'lib/apdu'
|
||||
require './sap/client.rb'
|
||||
require './lib/apdu.rb'
|
||||
require 'xml'
|
||||
|
||||
class Copy
|
||||
|
@ -254,7 +254,7 @@ class Copy
|
|||
@nb_files = 0 unless @nb_files
|
||||
@nb_files += 1
|
||||
rescue Exception => e
|
||||
puts "file error : #{e.to_s}"
|
||||
puts "file errors: #{e.to_s}"
|
||||
select_decode(select(id))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,10 +18,10 @@ along with sofSIM. 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 'sap/client'
|
||||
require 'lib/apdu'
|
||||
require 'info_client'
|
||||
require 'copy_client'
|
||||
require './sap/client.rb'
|
||||
require './lib/apdu.rb'
|
||||
require './info_client.rb'
|
||||
require './copy_client.rb'
|
||||
|
||||
#=============
|
||||
#== default ==
|
||||
|
@ -130,7 +130,7 @@ when "bt"
|
|||
if @bt then
|
||||
io = SerialPort.new(@bt)
|
||||
else
|
||||
require 'lib/bluetooth_sap_serial'
|
||||
require './tools/bluetooth_sap_serial.rb'
|
||||
bt = BluetoothSAPSerial.new
|
||||
# using SerialPort because reading the File does not work (have to find right stty options)
|
||||
io = SerialPort.new(bt.connect)
|
||||
|
|
|
@ -49,7 +49,7 @@ def print_help
|
|||
puts "options :"
|
||||
puts " --help,-h\t\tprint this help"
|
||||
puts " --type,-t type\tserver type: pcsc,sim (default #{@type})"
|
||||
puts " --socket,-s type\tsocket type : tcp,unix,bt (default #{@socket})"
|
||||
puts " --socket,-s type\tsocket type: tcp,unix (default #{@socket})"
|
||||
puts " --port,-p port\t\ttcp listeing port (default #{@port})"
|
||||
puts " --unix,-u file\t\tunix socket (default #{@unix})"
|
||||
puts " --file,-f file\t\tfile for sim type (default #{@file})"
|
||||
|
@ -107,10 +107,10 @@ io = socket.accept
|
|||
|
||||
case @type
|
||||
when "pcsc"
|
||||
require 'pcsc_server'
|
||||
require './pcsc_server.rb'
|
||||
server = PCSCServer.new(io)
|
||||
when "sim"
|
||||
require 'simos_server'
|
||||
require './simos_server.rb'
|
||||
server = SIMServer.new(io)
|
||||
else
|
||||
raise "unkown server type"
|
||||
|
|
|
@ -18,8 +18,8 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
|
|||
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
|
||||
=end
|
||||
# this programm will display information stored in the SIM
|
||||
require 'sap/client'
|
||||
require 'lib/apdu'
|
||||
require './sap/client.rb'
|
||||
require './lib/apdu.rb'
|
||||
|
||||
#=============
|
||||
#== methods ==
|
||||
|
|
|
@ -17,7 +17,7 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
|
||||
=end
|
||||
require 'sap/server'
|
||||
require './sap/server.rb'
|
||||
require 'rubygems'
|
||||
require 'smartcard'
|
||||
=begin
|
||||
|
|
|
@ -18,7 +18,7 @@ Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
|
|||
=end
|
||||
# this is the client part of the SAP
|
||||
# it implements the state machine for the client
|
||||
require 'sap/common'
|
||||
require './sap/common.rb'
|
||||
|
||||
# this is an abstract class
|
||||
# TODO :
|
||||
|
|
|
@ -19,7 +19,7 @@ Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
|
|||
# this is the server part of the SAP
|
||||
# it implements the state machine for the server
|
||||
# this is an abstract class
|
||||
require 'sap/common'
|
||||
require './sap/common.rb'
|
||||
|
||||
# this is an bastract class
|
||||
# TODO (not implemented) :
|
||||
|
|
|
@ -17,8 +17,8 @@ along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
|
||||
=end
|
||||
require 'sap/server'
|
||||
require 'lib/apdu'
|
||||
require './sap/server.rb'
|
||||
require './lib/apdu.rb'
|
||||
require 'socket'
|
||||
require 'xml'
|
||||
|
||||
|
|
|
@ -84,7 +84,6 @@ class BluetoothSAPSerial
|
|||
bt_adapter = bt_service.object(adapter)
|
||||
bt_adapter.introspect
|
||||
bt_adapter.default_iface = "org.bluez.Adapter"
|
||||
#$stdout.puts bt_abapter_object["org.bluez.Adapter"].Address
|
||||
bt_adapter = bt_adapter.GetProperties()[0]
|
||||
bt_adapters << {
|
||||
:object => adapter,
|
||||
|
@ -101,7 +100,7 @@ class BluetoothSAPSerial
|
|||
elsif bt_adapters.size==1 then
|
||||
bt_adapter = bt_adapters[0]
|
||||
else
|
||||
$stdout.puts "multiple bluetooth adapter "
|
||||
$stdout.puts "multiple bluetooth adapter:"
|
||||
bt_adapters.each_index do |i|
|
||||
bt_adapter = bt_adapters[i]
|
||||
$stdout.puts "#{i}) #{bt_adapter[:adapter]} (#{bt_adapter[:address]} - #{bt_adapter[:name]})#{bt_adapter[:default] ? ' [default]' : ''}"
|
||||
|
@ -171,7 +170,25 @@ class BluetoothSAPSerial
|
|||
end
|
||||
# get the device (create it if it does not exist)
|
||||
if !device_exists then
|
||||
tries = 3
|
||||
wait_time = 1
|
||||
begin
|
||||
device_object = bt_adapter.CreateDevice(properties["Address"])[0]
|
||||
rescue DBus::Error => e
|
||||
if e.to_s.include? "Host is down" then
|
||||
if tries>0 then
|
||||
puts "host is down, retrying #{tries} in #{wait_time}s"
|
||||
tries -= 1;
|
||||
sleep wait_time;
|
||||
retry
|
||||
else
|
||||
puts "host is down, exiting"
|
||||
exit 1
|
||||
end
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
else
|
||||
device_object = bt_adapter.path+"/"+device_object
|
||||
end
|
||||
|
@ -203,12 +220,12 @@ class BluetoothSAPSerial
|
|||
elsif sap_devices.size == 1 then
|
||||
sap_device = sap_devices[0]
|
||||
else
|
||||
$stdout.puts "multiple devices possible"
|
||||
$stdout.puts "multiple devices possible:"
|
||||
sap_devices.each_index do |i|
|
||||
$stdout.puts "- #{sap_devices[0][:name]} (#{sap_devices[0][:addr]}"
|
||||
$stdout.puts "#{i}) #{sap_devices[i][:name]} (#{sap_devices[i][:addr]})"
|
||||
end
|
||||
$stdout.print "select device: "
|
||||
sap_device = $stdin.gets.chomp
|
||||
sap_device = $stdin.gets.chomp.to_i
|
||||
sap_device = sap_devices[sap_device]
|
||||
end
|
||||
$stdout.puts "using device #{sap_device[:name]} (#{sap_device[:addr]})"
|
||||
|
@ -249,10 +266,10 @@ class BluetoothSAPSerial
|
|||
begin
|
||||
@rfcomm = @bt_sap.Connect(SAP_UUID)[0]
|
||||
rescue DBus::Error => e
|
||||
if e.to_s == "org.bluez.Error.Failed: Connection refused (111)" then
|
||||
if e.to_s.include? "Connection refused (111)" then
|
||||
$stderr.puts "Connection to device failed. Restarting the device might help"
|
||||
exit 1
|
||||
elsif e.to_s == "org.bluez.Error.Failed: Connection timed out" then
|
||||
elsif e.to_s.include? "Connection timed out" then
|
||||
$stderr.puts "Device does not respond to connection request"
|
||||
exit 1
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue