Primo rilascio: Gateway SIP-DMR completo

This commit is contained in:
2026-08-08 16:01:06 +02:00
commit febef4f5f2
8 changed files with 730 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import hmac
import hashlib
import struct
import time
def calcola_hmac(passphrase: str, dati: bytes) -> bytes:
"""Calcola la firma HMAC-SHA1 richiesta dalle reti FreeDMR/HBLink."""
return hmac.new(passphrase.encode('utf-8'), dati, hashlib.sha1).digest()
def crea_pacchetto_ping(peer_id: int, passphrase: str) -> bytes:
"""
Crea un pacchetto PING OpenBridge formattato con autenticazione HMAC.
"""
# Header OpenBridge tipico: Magic 'OPB' (3 byte) + Tipo 0x01 (Ping) + PeerID (4 byte) + Timestamp (4 byte)
timestamp = int(time.time())
payload_base = struct.pack("!3sBI I", b"OPB", 0x01, peer_id, timestamp)
# Calcoliamo la firma HMAC-SHA1 della password sul payload base
firma_hmac = calcola_hmac(passphrase, payload_base)
# Restituiamo il pacchetto completo (Payload + HMAC)
return payload_base + firma_hmac
def crea_superheader_chiamata(peer_id: int, passphrase: str, src_id: int, dst_tg: int, slot: int, stream_id: bytes) -> bytes:
"""
Crea l'intestazione di inizio trasmissione (Call Start / SuperHeader) per HBLink.
"""
# Header: Magic 'OPB' + Tipo 0x80 (Start Call) + PeerID + StreamID + Slot + SrcID + DstTG
# (Formato compatibile con le specifiche OpenBridge/HomeBrew)
flags = (slot & 0x01) << 7
payload_base = struct.pack("!3sB I 4s B I I",
b"OPB", 0x80, peer_id, stream_id[:4], flags, src_id, dst_tg)
firma_hmac = calcola_hmac(passphrase, payload_base)
return payload_base + firma_hmac