10
0
Fork 0

disconnect & UPDATE BINARY implemented

This commit is contained in:
Kevin Redon 2011-05-05 12:34:19 +02:00
parent df44d1f5f0
commit 7eb855a56a
2 changed files with 29 additions and 1 deletions

View File

@ -108,6 +108,7 @@ class Server < SAP
when "DISCONNECT_REQ"
raise "msg #{message[:name]} in wrong state #{@state}" unless @state!=:not_connected and @state!=:connection_under_nogiciation
log("server","client disconneting",3)
disconnect()
response = create_message("DISCONNECT_RESP")
send(response)
set_state :not_connected

View File

@ -42,7 +42,7 @@ class SIMServer < Server
doc = XML::Parser.string(xml)
@card = doc.parse
rescue
puts "can't read #{@xml_path}"
log("connect","can't read #{@xml_path}",3)
status = create_message("STATUS_IND",[[0x08,[0x02]]])
send(status)
sleep 1
@ -55,6 +55,11 @@ class SIMServer < Server
# card ready
return true
end
def disconnect
@card.save(@xml_path)
log("disconnect","save SIM in #{@xml_path}",3)
end
# get ATR
def atr
@ -159,6 +164,28 @@ class SIMServer < Server
sw = [0x90,0x00]
end
end
when 0xd6 # UPDATE BINARY
# is an transparent ef selected ?
type = file_info
if type[:type]!="EF" then
# no EF selected
sw = [0x94,0x00]
elsif type[:structure]!="transparent" then
# file is inconsitent with the command
sw = [0x94,0x08]
else
body = @selected.find_first("./body").content.hex2arr
offset = (request[2]<<8)+request[3]
length = request[4]
if offset>=body.length or offset+length>body.length then
# out of range (invalid address)
sw = [0x94,0x02]
else
# write the data
body[offset,length] = request[5,length]
sw = [0x90,0x00]
end
end
when 0x88 # RUN GSM ALGORITHM
# verify the apdu
if request[2,2]!=[0x00,0x00] then