diff --git a/main.go b/main.go index 313fda0..d9afd47 100644 --- a/main.go +++ b/main.go @@ -94,8 +94,10 @@ func main() { var lastReceivedSeq uint8 var receivedSeq bool var lastPingAt time.Time + var lastLongPingAt time.Time var errCount int var randID [4]byte + var authID [6]byte for { r, err := read() if err != nil { @@ -107,10 +109,23 @@ func main() { } errCount = 0 + // Example success auth packet: 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + // 0xe6, 0xb2, 0x7b, 0x7b, 0xbb, 0x41, 0x3f, 0x2b, + // 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x5d, 0x37, 0x12, 0x82, 0x3b, 0xde, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x46, 0x54, 0x54, 0x48, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 if len(r) == 96 && bytes.Equal(r[:8], []byte{0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}) { if bytes.Equal(r[48:52], []byte{0xff, 0xff, 0xff, 0xfe}) { log.Fatal("invalid user/password") } else { + copy(authID[:], r[26:32]) log.Print("auth ok") } } @@ -130,10 +145,10 @@ func main() { } if len(r) == 16 && bytes.Equal(r[:6], []byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}) { // Replying to the radio. - // Example receive: 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0xe4, 0x35, 0xdd, 0x72, 0xbe, 0xd9, 0xf2, 0x63 - // Example answer: 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0xbe, 0xd9, 0xf2, 0x63, 0xe4, 0x35, 0xdd, 0x72 + // Example request from radio: 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0xe4, 0x35, 0xdd, 0x72, 0xbe, 0xd9, 0xf2, 0x63 + // Example answer from PC: 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0xbe, 0xd9, 0xf2, 0x63, 0xe4, 0x35, 0xdd, 0x72 gotSeq := r[6] - send([]byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, gotSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID)}) + send([]byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, gotSeq, r[7], byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID)}) } if time.Since(lastPingAt) >= 100*time.Millisecond { @@ -145,8 +160,37 @@ func main() { } send([]byte{0x15, 0x00, 0x00, 0x00, 0x07, 0x00, sendSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID), 0x01, randID[0], randID[1], randID[2], randID[3]}) + send([]byte{0x10, 0x00, 0x00, 0x00, 0x03, 0x00, sendSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID)}) sendSeq++ lastPingAt = time.Now() + + if time.Since(lastLongPingAt) >= 60*time.Second { + // Example request from PC: 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, + // 0xbb, 0x41, 0x3f, 0x2b, 0xe6, 0xb2, 0x7b, 0x7b, + // 0x00, 0x00, 0x00, 0x30, 0x01, 0x05, 0x00, 0x02, + // 0x00, 0x00, 0x5d, 0x37, 0x12, 0x82, 0x3b, 0xde, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + // Example reply from radio: 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + // 0xe6, 0xb2, 0x7b, 0x7b, 0xbb, 0x41, 0x3f, 0x2b, + // 0x00, 0x00, 0x00, 0x30, 0x02, 0x05, 0x00, 0x02, + // 0x00, 0x00, 0x5d, 0x37, 0x12, 0x82, 0x3b, 0xde, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + send([]byte{0x40, 0x00, 0x00, 0x00, 0x00, 0x00, sendSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID), + 0x00, 0x00, 0x00, 0x30, 0x01, 0x05, 0x00, 0x3f, + 0x00, 0x00, authID[0], authID[1], authID[2], authID[3], authID[4], authID[5], + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) + sendSeq++ + lastLongPingAt = time.Now() + } } } }