From 8d8ed3ae7d397af808437e76de58f3679785b377 Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Fri, 29 Oct 2021 05:15:18 -0700 Subject: [PATCH] save progress --- bridge_master.py | 54 ++++++++++++++++++++++++++------------------- config.py | 2 +- hblink.py | 19 +++++++++++----- hotspot_proxy_v2.py | 2 +- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index d63440f..17aecb1 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -353,10 +353,8 @@ def rule_timer_loop(): # Remove expired UNITs from dictionary print(UNIT_MAP) -## for unit in UNIT_MAP: -## svrd_send_all(b'UNIT' + unit) - # Remove UNITs if not seen after an hour - _then = _now - 3600 + # Remove UNIT IDs not seen in the last 24 hours + _then = _now - (3600 * 24) remove_list = [] for unit in UNIT_MAP: 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 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): 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 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') - print(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) 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': @@ -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. _data_call = False - print(self._system) - print(UNIT_MAP) +## print(self._system) +## print(UNIT_MAP) # Make/update an entry in the UNIT_MAP for this subscriber UNIT_MAP[_rf_src] = (self._system, pkt_time) - print() +## print() print(_call_type) print(_dtype_vseq) - print(_frame_type) - print(_stream_id) - print(_seq) +## print(_frame_type) +## print(_stream_id) +## print(_seq) + print(ahex(dmrpkt)) if _dtype_vseq == 3: print(ahex(dmrpkt)[27:-27]) - print() +## print() # 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 ahex(dmrpkt)[27:-27] == b'd5d7f77fd757': - print('data call') # This is a data call _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: systems[UNIT_MAP[_dst_id][0]].send_system(_data) 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) diff --git a/config.py b/config.py index 6c03909..bc290ec 100755 --- a/config.py +++ b/config.py @@ -335,7 +335,7 @@ def build_config(_config_file): 'RELAX_CHECKS': config.getboolean(section, 'RELAX_CHECKS'), 'ENHANCED_OBP': config.getboolean(section, 'ENHANCED_OBP'), '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: diff --git a/hblink.py b/hblink.py index 64c07bb..b3b318c 100755 --- a/hblink.py +++ b/hblink.py @@ -160,11 +160,11 @@ class OPENBRIDGE(DatagramProtocol): _packet = b''.join([_packet, (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())) - 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) _packet = b'EOBP' + _enc_pkt print('Use EOBP') - print(_packet) +## print(_packet) self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) # 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)) @@ -172,7 +172,7 @@ class OPENBRIDGE(DatagramProtocol): ## elif _packet[:4] == EOBP and self._config['TARGET_IP']: elif _packet[:4] == SVRD: - print(_packet) +## print(_packet) _enc_pkt = encrypt_packet(self._config['ENCRYPTION_KEY'], _packet) _packet = b'SVRD' + _enc_pkt self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) @@ -203,6 +203,10 @@ class OPENBRIDGE(DatagramProtocol): else: 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): pass @@ -215,11 +219,11 @@ class OPENBRIDGE(DatagramProtocol): # DMRData -- encapsulated DMR data frame if _packet[:4] == DMRD or _packet[:4] == EOBP: if _packet[:4] == EOBP: - print(_packet) +## print(_packet) print('Decrypt') _d_pkt = decrypt_packet(self._config['ENCRYPTION_KEY'], _packet[4:]) _packet = _d_pkt - print(_packet) +## print(_packet) _data = _packet[:53] _hash = _packet[53:] _ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() @@ -288,6 +292,11 @@ class OPENBRIDGE(DatagramProtocol): 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) + + 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 _packet[:2] == BC: # Bridge Control packet (Extended OBP) #Keep Alive diff --git a/hotspot_proxy_v2.py b/hotspot_proxy_v2.py index a19f932..386f4be 100644 --- a/hotspot_proxy_v2.py +++ b/hotspot_proxy_v2.py @@ -196,7 +196,7 @@ if __name__ == '__main__': #*** CONFIG HERE *** Master = "127.0.0.1" - ListenPort = 62031 + ListenPort = 62032 # '' = all IPv4, '::' = all IPv4 and IPv6 (Dual Stack) ListenIP = '' DestportStart = 54000