From 9e7a94a8525f0d3aaec1a4b9e9cab37e70b6c8ea Mon Sep 17 00:00:00 2001 From: Miguel Ruiz de Sotto Date: Tue, 16 Jan 2024 17:22:11 +0100 Subject: [PATCH 1/2] shutdown socket before closing Signed-off-by: Miguel Ruiz de Sotto --- ledgerblue/commTCP.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ledgerblue/commTCP.py b/ledgerblue/commTCP.py index 639010d..922235c 100644 --- a/ledgerblue/commTCP.py +++ b/ledgerblue/commTCP.py @@ -79,6 +79,7 @@ def apduMaxDataSize(self): def close(self): try: + self.socket.shutdown(socket.SHUT_RD) self.socket.close() self.socket = None except: From f958b35daf94e4fe980de66d0f13fcb8def2c83a Mon Sep 17 00:00:00 2001 From: Miguel Ruiz de Sotto Date: Tue, 16 Jan 2024 17:35:39 +0100 Subject: [PATCH 2/2] raise CommException with response data Signed-off-by: Miguel Ruiz de Sotto --- ledgerblue/commTCP.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ledgerblue/commTCP.py b/ledgerblue/commTCP.py index 922235c..7586a6d 100644 --- a/ledgerblue/commTCP.py +++ b/ledgerblue/commTCP.py @@ -60,7 +60,7 @@ def get_data(): # When more data is available, the chip sends 0x61XX # So 0x61xx as a SW must not be interpreted as an error if (sw & 0xFF00) != 0x6100: - raise CommException("Invalid status %04x" % sw, sw) + raise CommException("Invalid status %04x" % sw, sw, data=response) else: while (sw & 0xFF00) == 0x6100: send_apdu(bytes.fromhex("00c0000000")) # GET RESPONSE @@ -72,7 +72,7 @@ def get_data(): return bytearray(response) # In any other case return an exception - raise CommException("Invalid status %04x" % sw, sw) + raise CommException("Invalid status %04x" % sw, sw, data=response) def apduMaxDataSize(self): return 240