aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristina Quast <chrysh.ng+git@gmail.com>2015-05-14 17:14:34 +0200
committerChristina Quast <chrysh.ng+git@gmail.com>2015-05-14 17:19:28 +0200
commit152e878bfe77ec77005f904bbd5f370cd5b31a10 (patch)
tree9904885ccb7864ebd169a5261f639d5b3912a168
parent59dae9239853b4ffc5b04d17237b3a7fc5cf82a2 (diff)
gsmtap.py: Ported from scapy to socket
With the python module scapy the headers of each layer have to be created by hand. Furthermore, in order to use it, the program would have to be started as root. Using sockets would be the better. The reason for using scapy was, that it was the first best thing that I found when searching for python socket communication. The next step would be to open and close the socket only once instead of every time an APDU is send to wireshark. Furthermore, the ATR probably has to be treated differently from APDU packets.
-rwxr-xr-x[-rw-r--r--]usb_application/gsmtap.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/usb_application/gsmtap.py b/usb_application/gsmtap.py
index 32977a4..96038ea 100644..100755
--- a/usb_application/gsmtap.py
+++ b/usb_application/gsmtap.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
-from scapy.all import IP, UDP, sr1
+import socket
+import array
ip="127.0.0.1"
port=4729
@@ -10,19 +11,14 @@ gsmtap_hdr="\x02\x04\x04"+"\x00"*13
# FIXME: Is ATR something special?
def gsmtap_send_apdu(data):
-# Do we have performance penalty because the socket stays open?
- p=IP(dst=ip, src=ip)/UDP(sport=sp, dport=port)/(gsmtap_hdr+data)
-# FIXME: remove show and ans
- if p:
- p.show()
-
- ans = sr1(p, timeout=2)
- if ans:
- print(ans)
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ s.connect((ip, port))
+ s.send(gsmtap_hdr+data.tostring())
+ s.close()
if __name__ == '__main__':
cmds = ("\xa0\xa4\x00\x00\x02\x6f\x7e\x9f\x0f",
"\xa0\xd6\x00\x00\x0b\xff\xff\xff\xff\x09\xf1\x07\xff\xfe\x00\x03\x90\x00",
- );
+ )
for cmd in cmds:
- gsmtap_send_apdu(cmd)
+ gsmtap_send_apdu(array.array('B', cmd))