From 7327ff32156f41f456f7cc08cc6739302402b7bf Mon Sep 17 00:00:00 2001 From: Nonoo Date: Fri, 23 Oct 2020 23:41:56 +0200 Subject: [PATCH] Use previous SIDs if we get an unexpected serial/audio req. success --- controlstream.go | 22 +++++++++------------- main.go | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/controlstream.go b/controlstream.go index 8093e7e..e51535e 100644 --- a/controlstream.go +++ b/controlstream.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "encoding/binary" "errors" "strings" "time" @@ -212,28 +213,23 @@ func (s *controlStream) handleRead(r []byte) error { // 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x03, 0x03, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + s.secondAuthTimer.Stop() + s.requestSerialAndAudioTimeout.Stop() + devName := s.parseNullTerminatedString(r[64:]) log.Print("got serial and audio request success, device name: ", devName) - if !s.serialAndAudioStreamOpenRequested { - return errors.New("not requested serial and audio streams yet") - } - - // The auth ID can change in the meantime because of a previous login... + // Stuff can change in the meantime because of a previous login... + s.common.remoteSID = binary.BigEndian.Uint32(r[8:12]) + s.common.localSID = binary.BigEndian.Uint32(r[12:16]) copy(s.authID[:], r[26:32]) - s.secondAuthTimer.Stop() - - if s.requestSerialAndAudioTimeout != nil { - s.requestSerialAndAudioTimeout.Stop() - s.requestSerialAndAudioTimeout = nil - } if err := s.serial.start(devName); err != nil { - return err + return errors.New("serial/" + err.Error()) } if err := s.audio.start(devName); err != nil { - return err + return errors.New("audio/" + err.Error()) } s.serialAndAudioStreamOpened = true diff --git a/main.go b/main.go index a4466b3..51eb5f3 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func runControlStream(osSignal chan os.Signal) (shouldExit bool, exitCode int) { c.deinit() // Need to wait before reinit because the IC-705 will disconnect our audio stream eventually if we relogin - // in a too short interval... + // in a too short interval without a deauth... t := time.NewTicker(time.Second) for sec := 65; sec > 0; sec-- { log.Print("waiting ", sec, " seconds...")