Lines Matching full:handover
269 def dpp_handover_client(handover, alt=False):
272 handover.i_m_selector = False
273 run_dpp_handover_client(handover, alt)
276 def run_client_alt(handover, alt):
277 if handover.start_client_alt and not alt:
278 handover.start_client_alt = False
279 summary("Try to send alternative handover request")
280 dpp_handover_client(handover, alt=True)
282 class HandoverClient(nfc.handover.HandoverClient):
283 def __init__(self, handover, llc):
285 self.handover = handover
293 summary("Handover client received message '{0}'".format(records[0].type))
295 summary("Handover client received invalid message: %s" + binascii.hexlify(msg))
329 def run_dpp_handover_client(handover, alt=False):
332 chan_override = handover.altchanlist
333 handover.alt_proposal_used = True
341 summary("Cannot start handover client - no bootstrap URI available",
344 handover.my_uri = uri
359 summary("NFC Handover Request message for DPP: " + str(message))
361 if handover.peer_crn is not None and not alt:
362 summary("NFC handover request from peer was already received - do not send own[1]")
364 if handover.client:
365 summary("Use already started handover client")
366 client = handover.client
368 summary("Start handover client")
369 client = HandoverClient(handover, handover.llc)
371 summary("Trying to initiate NFC connection handover")
373 summary("Connected for handover")
375 summary("Handover connection refused")
382 handover.client = client
384 if handover.peer_crn is not None and not alt:
385 summary("NFC handover request from peer was already received - do not send own[2] (except alt)")
386 run_client_alt(handover, alt)
389 summary("Sending handover request")
391 handover.my_crn_ready = True
394 handover.my_crn_ready = False
395 summary("Failed to send handover request", color=C_RED)
396 run_client_alt(handover, alt)
399 handover.my_crn, = struct.unpack('>H', crn)
401 summary("Receiving handover response")
408 # This is fine if we are the handover selector
409 if handover.hs_sent:
410 summary("Client receive failed as expected since I'm the handover server: %s" % str(e))
411 elif handover.alt_proposal_used and not alt:
417 if handover.hs_sent:
418 summary("No response received as expected since I'm the handover server")
419 elif handover.alt_proposal_used and not alt:
421 elif handover.try_own and not alt:
425 run_client_alt(handover, alt)
433 summary("Received handover select message")
435 if handover.i_m_selector:
436 summary("Ignore the received select since I'm the handover selector")
437 run_client_alt(handover, alt)
440 if handover.alt_proposal_used and not alt:
441 summary("Ignore received handover select for the initial proposal since alternative proposal was sent")
458 handover.peer_uri = uri
464 summary("DPP handover report rejected", color=C_RED)
467 success_report("DPP handover reported successfully (initiator)")
497 if not dpp_found and handover.no_alt_proposal:
500 summary("DPP carrier not seen in response - allow peer to initiate a new handover with different parameters")
501 handover.alt_proposal = True
502 handover.my_crn_ready = False
503 handover.my_crn = None
504 handover.peer_crn = None
505 handover.hs_sent = False
510 handover.close()
511 summary("Done with handover")
526 class HandoverServer(nfc.handover.HandoverServer):
527 def __init__(self, handover, llc):
533 self.handover = handover
537 summary("Serving handover client on remote sap {0}".format(peer_sap))
557 summary("No handover select to send out - wait for a possible alternative handover request")
558 handover.alt_proposal = True
564 summary("Failed to send handover select - connection closed")
566 summary("Sent out full handover select")
567 if handover.terminate_on_hs_send_completion:
568 handover.delayed_exit()
576 summary("Handover serve thread exiting")
579 handover = self.handover
592 handover.peer_crn = carrier.collision_resolution_number
593 summary("peer_crn: %d" % handover.peer_crn)
595 if handover.my_crn is None and handover.my_crn_ready:
596 summary("Still trying to send own handover request - wait a moment to see if that succeeds before checking crn values")
598 if handover.my_crn is not None:
601 if handover.my_crn is not None:
602 summary("my_crn: %d" % handover.my_crn)
604 if handover.my_crn is not None and handover.peer_crn is not None:
605 if handover.my_crn == handover.peer_crn:
607 # TODO: Should generate a new Handover Request message
609 if ((handover.my_crn & 1) == (handover.peer_crn & 1) and \
610 handover.my_crn > handover.peer_crn) or \
611 ((handover.my_crn & 1) != (handover.peer_crn & 1) and \
612 handover.my_crn < handover.peer_crn):
613 summary("I'm the Handover Selector Device")
614 handover.i_m_selector = True
616 summary("Peer is the Handover Selector device")
641 elif handover.alt_proposal and handover.altchanlist:
644 chan_override=handover.altchanlist,
658 summary("DPP handover request processing failed",
660 if handover.altchanlist:
662 chan_override=handover.altchanlist)
681 handover.my_uri = data
682 handover.peer_uri = uri
706 summary("Sending handover select: " + str(sel))
708 summary("Handover completed successfully")
709 handover.terminate_on_hs_send_completion = True
711 handover.hs_sent = True
712 handover.i_m_selector = True
713 elif handover.no_alt_proposal:
714 summary("Do not try alternative proposal anymore - handover failed",
716 handover.hs_sent = True
719 handover.try_own = True
720 handover.hs_sent = False
721 handover.no_alt_proposal = True
722 if handover.client_thread:
723 handover.start_client_alt = True
725 handover.client_thread = threading.Thread(target=llcp_worker,
727 handover.client_thread.start()
828 summary("Write NFC Handover Select record on a tag")
869 global handover
872 summary("Starting handover client (try_alt)")
873 dpp_handover_client(handover, alt=True)
878 summary("Starting handover client (init_on_touch)")
879 dpp_handover_client(handover)
880 summary("llcp_worker init_on_touch processing completed: try_own={} hs_sent={} no_alt_proposal={} start_client_alt={}".format(handover.try_own, handover.hs_sent, handover.no_alt_proposal, handover.start_client_alt))
881 if handover.start_client_alt and not handover.hs_sent:
882 summary("Try alternative handover request before exiting llcp_worker")
883 handover.start_client_alt = False
884 dpp_handover_client(handover, alt=True)
890 summary("Wait for handover to complete")
892 print("Wait for handover to complete - press 'i' to initiate")
893 while not handover.wait_connection and handover.srv.sent_carrier is None:
894 if handover.try_own:
895 handover.try_own = False
896 summary("Try to initiate another handover with own parameters")
897 handover.my_crn_ready = False
898 handover.my_crn = None
899 handover.peer_crn = None
900 handover.hs_sent = False
901 dpp_handover_client(handover, alt=True)
904 if handover.srv.ho_server_processing:
913 summary("Starting handover client")
914 dpp_handover_client(handover)
950 summary("Start handover server")
973 global handover
974 handover.start_handover_server(llc)
979 global handover
980 handover.connected = True
981 handover.srv.start()
983 handover.client_thread = threading.Thread(target=llcp_worker,
985 handover.client_thread.start()
990 global handover
991 handover.close()
1010 help='initiate handover on touch')
1016 help='do not use stdout input to initiate handover')
1018 help='tag read only (do not allow connection handover)')
1019 parser.add_argument('--handover-only', action='store_true',
1020 help='connection handover only (do not allow tag read)')
1042 help='test mode: handover select URI')
1051 global handover
1052 handover = ConnectionHandover()
1063 handover.altchanlist = args.altchan
1079 'nfc.handover']:
1149 handover.wait_connection = True
1171 if only_one and handover.connected:
1172 role = "selector" if handover.i_m_selector else "requestor"
1173 summary("Connection handover result: I'm the %s" % role,
1175 if handover.peer_uri:
1176 summary("Peer URI: " + handover.peer_uri, color=C_YELLOW)
1177 if handover.my_uri:
1178 summary("My URI: " + handover.my_uri, color=C_YELLOW)
1179 if not (handover.peer_uri and handover.my_uri):
1180 summary("Negotiated connection handover failed",