From 24e75bfeaba337cf32325cc2a60ceedb31c06567 Mon Sep 17 00:00:00 2001 From: Hui Peng Date: Fri, 10 Nov 2023 22:11:33 -0800 Subject: [PATCH] Do not exit after pairing is finished Android performs additional service discovery during pairing, otherwise pairing fails. --- apps/pair.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/pair.py b/apps/pair.py index 93459124..996b01c6 100644 --- a/apps/pair.py +++ b/apps/pair.py @@ -291,6 +291,7 @@ async def pair( mitm, bond, ctkd, + linger, io, oob, prompt, @@ -395,6 +396,7 @@ async def pair( address_or_name, transport=BT_LE_TRANSPORT if mode == 'le' else BT_BR_EDR_TRANSPORT, ) + pairing_failure = False if not request: try: @@ -402,10 +404,12 @@ async def pair( await connection.pair() else: await connection.authenticate() - return except ProtocolError as error: + pairing_failure = True print(color(f'Pairing failed: {error}', 'red')) - return + + if not linger or pairing_failure: + return else: if mode == 'le': # Advertise so that peers can find us and connect @@ -455,6 +459,7 @@ def emit(self, record): help='Enable CTKD', show_default=True, ) +@click.option('--linger', default=True, is_flag=True, help='Linger after pairing') @click.option( '--io', type=click.Choice( @@ -490,6 +495,7 @@ def main( mitm, bond, ctkd, + linger, io, oob, prompt, @@ -514,6 +520,7 @@ def main( mitm, bond, ctkd, + linger, io, oob, prompt,