UDP Port (4729) Conflict Between SIMTrace2 and pySim

Hello community/admin,

I am experiencing an issue while using SIMTrace2 and pySim to sniff and analyze SIM card communication. Below are the details:


1. When SIMTrace2 Sniff is Turned Off

I run the following command:

bash
pySim-trace.py gsmtap-udp

Output:

plaintext
INFO root: Opening source gsmtap-udp... Detected UICC Add-on "SIM" Detected UICC Add-on "GSM-R" Detected UICC Add-on "RUIM" Can't read AIDs from SIM -- 'list' object has no attribute 'lower' warning: EF.DIR seems to be empty! ADF.ECASD: a0000005591010ffffffff8900000200 ADF.ISD-R: a0000005591010ffffffff8900000100 ISIM: a0000000871004 USIM: a0000000871002 INFO root: Entering main loop...

When I check the UDP port (4729) usage:

bash
sudo lsof -i :4729

Output:

plaintext
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME python3 198340 jun 4u IPv4 301846 0t0 UDP localhost:4729

2. When SIMTrace2 Sniff is Turned On

I run the following command:

bash
simtrace2-sniff

Output:

plaintext
simtrace2-sniff - Phone-SIM card communication sniffer (C) 2010-2017 by Harald Welte <laforge@gnumonks.org> (C) 2018 by Kevin Redon <kredon@sysmocom.de> Using USB device 1d50:60e3 Addr=46, Path=1-5, Cfg=1, Intf=0, Alt=0: 255/1/0 (SIMtrace Sniffer) Entering main loop ATR: 3b 9f 96 80 1f c7 80 31 e0 73 fe 21 11 57 86 81 27 86 98 60 58 ec PPS: ff 00 ff TPDU: a0 a4 00 00 02 7f 20 9f 17 TPDU: a0 c0 00 00 17 00 00 00 00 7f 20 02 00 00 00 00 00 0a 93 00 1c 04 00 83 8a 83 8a 00 90 00

When I check the UDP port (4729) usage:

bash
sudo lsof -i :4729

Output:

plaintext
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME simtrace2 198351 jun 7u IPv4 308389 0t0 UDP localhost:36190->localhost:4729 simtrace2 198351 jun 8u IPv4 308390 0t0 UDP localhost:4729

UDP Port (4729) Conflict Between SIMTrace2 and pySim

Hello community/admin,

I am experiencing an issue while using SIMTrace2 and pySim to sniff and analyze SIM card communication. Below are the details:


1. When SIMTrace2 Sniff is Turned Off

I run the following command:

bash
/usr/src/pysim/pySim-trace.py gsmtap-udp

Output:

plaintext
INFO root: Opening source gsmtap-udp... Detected UICC Add-on "SIM" Detected UICC Add-on "GSM-R" Detected UICC Add-on "RUIM" Can't read AIDs from SIM -- 'list' object has no attribute 'lower' warning: EF.DIR seems to be empty! ADF.ECASD: a0000005591010ffffffff8900000200 ADF.ISD-R: a0000005591010ffffffff8900000100 ISIM: a0000000871004 USIM: a0000000871002 INFO root: Entering main loop...

When I check the UDP port (4729) usage:

bash
sudo lsof -i :4729

Output:

plaintext
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME python3 198340 jun 4u IPv4 301846 0t0 UDP localhost:4729

2. When SIMTrace2 Sniff is Turned On

I run the following command:

bash
simtrace2-sniff

Output:

plaintext
simtrace2-sniff - Phone-SIM card communication sniffer (C) 2010-2017 by Harald Welte <laforge@gnumonks.org> (C) 2018 by Kevin Redon <kredon@sysmocom.de> Using USB device 1d50:60e3 Addr=46, Path=1-5, Cfg=1, Intf=0, Alt=0: 255/1/0 (SIMtrace Sniffer) Entering main loop ATR: 3b 9f 96 80 1f c7 80 31 e0 73 fe 21 11 57 86 81 27 86 98 60 58 ec PPS: ff 00 ff TPDU: a0 a4 00 00 02 7f 20 9f 17 TPDU: a0 c0 00 00 17 00 00 00 00 7f 20 02 00 00 00 00 00 0a 93 00 1c 04 00 83 8a 83 8a 00 90 00

When I check the UDP port (4729) usage:

bash
sudo lsof -i :4729

Output:

plaintext
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME simtrace2 198351 jun 7u IPv4 308389 0t0 UDP localhost:36190->localhost:4729 simtrace2 198351 jun 8u IPv4 308390 0t0 UDP localhost:4729

3. When Running SIMTrace2 Sniff and pySim-trace.py Together

If I try to run both SIMTrace2 sniff and pySim-trace.py gsmtap-udp simultaneously, I get the following error from pySim:

plaintext
jun@jun-RDR:pySim-trace.py gsmtap-udp INFO root: Opening source gsmtap-udp... Traceback (most recent call last): File "pySim-trace.py", line 199, in <module> s = GsmtapApduSource(opts.bind_ip, opts.bind_port) File "pysim/pySim/apdu_source/gsmtap.py", line 44, in __init__ self.gsmtap = GsmtapReceiver(bind_ip, bind_port) File "/home/jun/.local/lib/python3.10/site-packages/osmocom/gsmtap.py", line 207, in __init__ self.sock.bind((self.bind_ip, self.bind_port)) OSError: [Errno 98] Address already in use

Main Issue

  1. When SIMTrace2 sniff is running, it occupies UDP port 4729, preventing pySim from using the same port.
  2. When SIMTrace2 sniff is stopped, pySim can access UDP port 4729 but fails to decode data, showing the following errors:
    plaintext
    Can't read AIDs from SIM -- 'list' object has no attribute 'lower' warning: EF.DIR seems to be empty!
  3. If I try to run both tools at the same time, pySim crashes with the error [Errno 98] Address already in use.

Request for Help

Any insights or advice would be greatly appreciated. Thank you!