save progress

kf7eel
KF7EEL 4 years ago committed by Simon
parent 5f691b3a72
commit 8d8ed3ae7d

@ -353,10 +353,8 @@ def rule_timer_loop():
# Remove expired UNITs from dictionary # Remove expired UNITs from dictionary
print(UNIT_MAP) print(UNIT_MAP)
## for unit in UNIT_MAP: # Remove UNIT IDs not seen in the last 24 hours
## svrd_send_all(b'UNIT' + unit) _then = _now - (3600 * 24)
# Remove UNITs if not seen after an hour
_then = _now - 3600
remove_list = [] remove_list = []
for unit in UNIT_MAP: for unit in UNIT_MAP:
if UNIT_MAP[unit][1] < (_then): if UNIT_MAP[unit][1] < (_then):
@ -1396,6 +1394,13 @@ class routerOBP(OPENBRIDGE):
#Ignore this system and TS pair if it's called again on this packet #Ignore this system and TS pair if it's called again on this packet
return(_sysIgnore) return(_sysIgnore)
# Process SVRD packets
def svrd_received(self, _mode, _data):
print(UNIT_MAP)
logger.info('SVRD Received. Mode: ' + str(_mode) + ' Data: ' + str(_data))
# Add UNIT ID to UNIT_MAP
if _mode == b'UNIT':
UNIT_MAP[_data] = (self._system, time())
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
pkt_time = time() pkt_time = time()
@ -1405,14 +1410,16 @@ class routerOBP(OPENBRIDGE):
# Match UNIT data, SMS/GPS, and send it to the dst_id if it is in out UNIT_MAP # Match UNIT data, SMS/GPS, and send it to the dst_id if it is in out UNIT_MAP
if (_dtype_vseq == 6 or _dtype_vseq == 7) or ahex(dmrpkt)[27:-27] == b'd5d7f77fd757' and _dtype_vseq == 3 and _call_type == 'unit': if (_dtype_vseq == 6 or _dtype_vseq == 7) or ahex(dmrpkt)[27:-27] == b'd5d7f77fd757' and _dtype_vseq == 3 and _call_type == 'unit':
logger.info('Received UNIT data packet') logger.info('Received UNIT data packet')
print(UNIT_MAP)
if _dst_id in UNIT_MAP: if _dst_id in UNIT_MAP:
print(UNIT_MAP[_dst_id])
print(UNIT_MAP[_dst_id][0])
systems[UNIT_MAP[_dst_id][0]].send_system(_data) systems[UNIT_MAP[_dst_id][0]].send_system(_data)
else: else:
print('not in map') logger.info('UNIT not in map, sending to ALL SYSTEMS that are not OpenBridge')
for s in CONFIG['SYSTEMS'].items():
if s[1]['MODE'] == 'OPENBRIDGE':
pass
elif s[1]['MODE'] != 'OPENBRIDGE':
systems[s[0]].send_system(_data)
if _call_type == 'group' or _call_type == 'vcsbk': if _call_type == 'group' or _call_type == 'vcsbk':
@ -1809,35 +1816,36 @@ class routerHBP(HBSYSTEM):
# Assume this is not a data call. We use this to prevent SMS/GPS data from triggering a reflector. # Assume this is not a data call. We use this to prevent SMS/GPS data from triggering a reflector.
_data_call = False _data_call = False
print(self._system) ## print(self._system)
print(UNIT_MAP) ## print(UNIT_MAP)
# Make/update an entry in the UNIT_MAP for this subscriber # Make/update an entry in the UNIT_MAP for this subscriber
UNIT_MAP[_rf_src] = (self._system, pkt_time) UNIT_MAP[_rf_src] = (self._system, pkt_time)
print() ## print()
print(_call_type) print(_call_type)
print(_dtype_vseq) print(_dtype_vseq)
print(_frame_type) ## print(_frame_type)
print(_stream_id) ## print(_stream_id)
print(_seq) ## print(_seq)
print(ahex(dmrpkt))
if _dtype_vseq == 3: if _dtype_vseq == 3:
print(ahex(dmrpkt)[27:-27]) print(ahex(dmrpkt)[27:-27])
print() ## print()
# Filter out SMS/GPS. Usually _dtype_vseq of 3, 6, and 7. # Filter out SMS/GPS. Usually _dtype_vseq of 3, 6, and 7.
if (_dtype_vseq == 6 or _dtype_vseq == 7) or ahex(dmrpkt)[27:-27] == b'd5d7f77fd757' and _dtype_vseq == 3 and _call_type == 'unit': if (_dtype_vseq == 6 or _dtype_vseq == 7) or ahex(dmrpkt)[27:-27] == b'd5d7f77fd757' and _dtype_vseq == 3 and _call_type == 'unit':
## if ahex(dmrpkt)[27:-27] == b'd5d7f77fd757': ## if ahex(dmrpkt)[27:-27] == b'd5d7f77fd757':
print('data call')
# This is a data call # This is a data call
_data_call = True _data_call = True
## if _dtype_vseq == [3, 6, 7] and _call_type == 'unit':
## print('data packet')
## print((_data))
## print(systems['OBP-TEST'])
# systems['OBP-HB'].send_system(b'SVRDDATA' + _data)
if _dst_id in UNIT_MAP: if _dst_id in UNIT_MAP:
systems[UNIT_MAP[_dst_id][0]].send_system(_data) systems[UNIT_MAP[_dst_id][0]].send_system(_data)
else: else:
print('not in map') logger.info('UNIT not in map, sending to ALL SYSTEMS that are not OpenBridge')
for s in CONFIG['SYSTEMS'].items():
## if s[1]['MODE'] == 'OPENBRIDGE':
## pass
## elif s[1]['MODE'] != 'OPENBRIDGE':
systems[s[0]].send_system(_data)
#Handle private calls (for reflectors) #Handle private calls (for reflectors)

@ -335,7 +335,7 @@ def build_config(_config_file):
'RELAX_CHECKS': config.getboolean(section, 'RELAX_CHECKS'), 'RELAX_CHECKS': config.getboolean(section, 'RELAX_CHECKS'),
'ENHANCED_OBP': config.getboolean(section, 'ENHANCED_OBP'), 'ENHANCED_OBP': config.getboolean(section, 'ENHANCED_OBP'),
'ENCRYPTION_KEY': bytes(config.get(section, 'ENCRYPTION_KEY'), 'utf-8'), 'ENCRYPTION_KEY': bytes(config.get(section, 'ENCRYPTION_KEY'), 'utf-8'),
'USE_ENCRYPTION': config.getboolean(section, 'USE_ENCRYPTION'), 'ENCRYPT_ALL_TRAFFIC': config.getboolean(section, 'ENCRYPT_ALL_TRAFFIC'),
}}) }})
try: try:

@ -160,11 +160,11 @@ class OPENBRIDGE(DatagramProtocol):
_packet = b''.join([_packet, (hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest())]) _packet = b''.join([_packet, (hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest())])
## print(ahex(hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest())) ## print(ahex(hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest()))
## print(len(hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest())) ## print(len(hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest()))
if self._config['USE_ENCRYPTION'] == True or _packet[:4] == EOBP: if self._config['ENCRYPT_ALL_TRAFFIC'] == True or _packet[:4] == EOBP:
_enc_pkt = encrypt_packet(self._config['ENCRYPTION_KEY'], _packet) _enc_pkt = encrypt_packet(self._config['ENCRYPTION_KEY'], _packet)
_packet = b'EOBP' + _enc_pkt _packet = b'EOBP' + _enc_pkt
print('Use EOBP') print('Use EOBP')
print(_packet) ## print(_packet)
self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT']))
# KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!! # KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!!
#logger.debug('(%s) TX Packet to OpenBridge %s:%s -- %s', self._system, self._config['TARGET_IP'], self._config['TARGET_PORT'], ahex(_packet)) #logger.debug('(%s) TX Packet to OpenBridge %s:%s -- %s', self._system, self._config['TARGET_IP'], self._config['TARGET_PORT'], ahex(_packet))
@ -172,7 +172,7 @@ class OPENBRIDGE(DatagramProtocol):
## elif _packet[:4] == EOBP and self._config['TARGET_IP']: ## elif _packet[:4] == EOBP and self._config['TARGET_IP']:
elif _packet[:4] == SVRD: elif _packet[:4] == SVRD:
print(_packet) ## print(_packet)
_enc_pkt = encrypt_packet(self._config['ENCRYPTION_KEY'], _packet) _enc_pkt = encrypt_packet(self._config['ENCRYPTION_KEY'], _packet)
_packet = b'SVRD' + _enc_pkt _packet = b'SVRD' + _enc_pkt
self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT']))
@ -203,6 +203,10 @@ class OPENBRIDGE(DatagramProtocol):
else: else:
logger.debug('(%s) *BridgeControl* Not sent BCSQ Source Quench TARGET_IP not known , TG: %s, Stream ID: %s',self._system,int_id(_tgid)) logger.debug('(%s) *BridgeControl* Not sent BCSQ Source Quench TARGET_IP not known , TG: %s, Stream ID: %s',self._system,int_id(_tgid))
# Process SVRD data
def svrd_received(self, _mode, _data):
pass
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
pass pass
@ -215,11 +219,11 @@ class OPENBRIDGE(DatagramProtocol):
# DMRData -- encapsulated DMR data frame # DMRData -- encapsulated DMR data frame
if _packet[:4] == DMRD or _packet[:4] == EOBP: if _packet[:4] == DMRD or _packet[:4] == EOBP:
if _packet[:4] == EOBP: if _packet[:4] == EOBP:
print(_packet) ## print(_packet)
print('Decrypt') print('Decrypt')
_d_pkt = decrypt_packet(self._config['ENCRYPTION_KEY'], _packet[4:]) _d_pkt = decrypt_packet(self._config['ENCRYPTION_KEY'], _packet[4:])
_packet = _d_pkt _packet = _d_pkt
print(_packet) ## print(_packet)
_data = _packet[:53] _data = _packet[:53]
_hash = _packet[53:] _hash = _packet[53:]
_ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() _ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest()
@ -288,6 +292,11 @@ class OPENBRIDGE(DatagramProtocol):
h,p = _sockaddr h,p = _sockaddr
logger.info('(%s) OpenBridge HMAC failed, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:]),h,p) logger.info('(%s) OpenBridge HMAC failed, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:]),h,p)
elif _packet[:4] == SVRD:
_d_pkt = decrypt_packet(self._config['ENCRYPTION_KEY'], _packet[4:])
self.svrd_received(_d_pkt[4:8], _d_pkt[8:])
if self._config['ENHANCED_OBP']: if self._config['ENHANCED_OBP']:
if _packet[:2] == BC: # Bridge Control packet (Extended OBP) if _packet[:2] == BC: # Bridge Control packet (Extended OBP)
#Keep Alive #Keep Alive

@ -196,7 +196,7 @@ if __name__ == '__main__':
#*** CONFIG HERE *** #*** CONFIG HERE ***
Master = "127.0.0.1" Master = "127.0.0.1"
ListenPort = 62031 ListenPort = 62032
# '' = all IPv4, '::' = all IPv4 and IPv6 (Dual Stack) # '' = all IPv4, '::' = all IPv4 and IPv6 (Dual Stack)
ListenIP = '' ListenIP = ''
DestportStart = 54000 DestportStart = 54000

Loading…
Cancel
Save

Powered by TurnKey Linux.