mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-27 10:48:35 +03:00
phone.py: too many usb function calls
This commit is contained in:
@@ -6,6 +6,7 @@ import sys
|
|||||||
|
|
||||||
# SuperSIM ATR
|
# SuperSIM ATR
|
||||||
atr= [0x3B, 0x9A, 0x94, 0x00, 0x92, 0x02, 0x75, 0x93, 0x11, 0x00, 0x01, 0x02, 0x02, 0x19]
|
atr= [0x3B, 0x9A, 0x94, 0x00, 0x92, 0x02, 0x75, 0x93, 0x11, 0x00, 0x01, 0x02, 0x02, 0x19]
|
||||||
|
RESP_OK = [0x60, 0x00]
|
||||||
|
|
||||||
def find_dev():
|
def find_dev():
|
||||||
dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
|
dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
|
||||||
@@ -45,28 +46,54 @@ def find_eps(dev):
|
|||||||
print(ep_out)
|
print(ep_out)
|
||||||
return (ep_in, ep_out)
|
return (ep_in, ep_out)
|
||||||
|
|
||||||
def emulate_sim():
|
def handle_phone_request():
|
||||||
dev = find_dev()
|
# ATR handling
|
||||||
# (epi, epo) = find_eps(dev)
|
try:
|
||||||
|
arr = dev.read(0x83, 64, 100) # Notification endpoint
|
||||||
|
print("arr: ", arr)
|
||||||
|
c=arr.pop()
|
||||||
|
print(c)
|
||||||
|
|
||||||
while True:
|
if c == ord('R'):
|
||||||
#ep_out.write("Hello")
|
try:
|
||||||
try:
|
|
||||||
# ATR handling
|
|
||||||
arr = dev.read(0x83, 64, 1000) # Notification endpoint
|
|
||||||
print("arr: ", arr)
|
|
||||||
c=arr.pop()
|
|
||||||
print(c)
|
|
||||||
if c == ord('R'):
|
|
||||||
written = dev.write(0x1, atr, 1000) # Probably we received a Reset, so we send ATR
|
written = dev.write(0x1, atr, 1000) # Probably we received a Reset, so we send ATR
|
||||||
print("Written data: " + written)
|
print("Written data: " + written)
|
||||||
|
except:
|
||||||
|
print("Timeout sending ATR!")
|
||||||
|
return
|
||||||
|
|
||||||
|
except:
|
||||||
|
#print("Timeout receiving atr!")
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Read phone request
|
||||||
|
try:
|
||||||
|
cmd = dev.read(0x82, 64, 10000000)
|
||||||
|
print("Received request!: ")
|
||||||
|
print("".join("%02x " % b for b in ans))
|
||||||
|
|
||||||
|
print("Write response");
|
||||||
|
try:
|
||||||
|
written = dev.write(0x01, RESP_OK, 10000000);
|
||||||
|
print("Bytes written:")
|
||||||
|
print(written)
|
||||||
|
except:
|
||||||
|
print("Timeout in send response")
|
||||||
|
|
||||||
|
except:
|
||||||
|
#print("Timeout in receive cmd")
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
ans = dev.read(0x82, 64, 1000)
|
def emulate_sim():
|
||||||
print("".join("%02x " % b for b in ans))
|
dev = find_dev()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
handle_phone_request()
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Bye")
|
print("Bye")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except:
|
except:
|
||||||
print("Timeout")
|
print("Timeout")
|
||||||
# print(ep_in.read(1, 5000));
|
|
||||||
|
|||||||
Reference in New Issue
Block a user