From e5a27f21204ffd0a46c315d691e99a1191034784 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 19 Jan 2022 16:30:22 +0000 Subject: [PATCH] Hops --- bridge_master.py | 28 ++++++++++++++-------------- hblink.py | 20 ++++++++++++++++---- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 2569b17..29e9745 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1236,7 +1236,7 @@ class routerOBP(OPENBRIDGE): OPENBRIDGE.__init__(self, _name, _config, _report) self.STATUS = {} - def to_target(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data, pkt_time, dmrpkt, _bits,_bridge,_system,_noOBP,sysIgnore): + def to_target(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data, pkt_time, dmrpkt, _bits,_bridge,_system,_noOBP,sysIgnore,_hops): _sysIgnore = sysIgnore for _target in BRIDGES[_bridge]: if (_target['SYSTEM'] != self._system) and (_target['ACTIVE']): @@ -1408,22 +1408,22 @@ class routerOBP(OPENBRIDGE): _tmp_data = b''.join([_tmp_data, dmrpkt, b'\x00\x00']) # Add two bytes of nothing since OBP doesn't include BER & RSSI bytes #_data[53:55] # Transmit the packet to the destination system - systems[_target['SYSTEM']].send_system(_tmp_data) + systems[_target['SYSTEM']].send_system(_tmp_data,_hops) #logger.debug('(%s) Packet routed by bridge: %s to system: %s TS: %s, TGID: %s', self._system, _bridge, _target['SYSTEM'], _target['TS'], int_id(_target['TGID'])) #Ignore this system and TS pair if it's called again on this packet return(_sysIgnore) - def sendDataToHBP(self,_d_system,_d_slot,_dst_id,_tmp_bits,_data,dmrpkt,_rf_src,_stream_id,_peer_id): + def sendDataToHBP(self,_d_system,_d_slot,_dst_id,_tmp_bits,_data,dmrpkt,_rf_src,_stream_id,_peer_id,_hops): _int_dst_id = int_id(_dst_id) #Assemble transmit HBP packet header _tmp_data = b''.join([_data[:15], _tmp_bits.to_bytes(1, 'big'), _data[16:20]]) _tmp_data = b''.join([_tmp_data, dmrpkt]) - systems[_d_system].send_system(_tmp_data) + systems[_d_system].send_system(_tmp_data,_hops) logger.info('(%s) UNIT Data Bridged to HBP on slot 1: %s DST_ID: %s',self._system,_d_system,_int_dst_id) if CONFIG['REPORTS']['REPORT']: systems[_d_system]._report.send_bridgeEvent('UNIT DATA,START,TX,{},{},{},{},{},{}'.format(_d_system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), 1, _int_dst_id).encode(encoding='utf-8', errors='ignore')) - def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot): + def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops): _int_dst_id = int_id(_dst_id) _target_status = systems[_target].STATUS @@ -1457,13 +1457,13 @@ class routerOBP(OPENBRIDGE): #Assemble transmit HBP packet header _tmp_data = b''.join([_data[:15], _tmp_bits.to_bytes(1, 'big'), _data[16:20]]) _tmp_data = b''.join([_tmp_data, dmrpkt]) - systems[_target].send_system(_tmp_data) + systems[_target].send_system(_tmp_data,_hops) logger.info('(%s) UNIT Data Bridged to OBP System: %s DST_ID: %s', self._system, _target,_int_dst_id) if CONFIG['REPORTS']['REPORT']: systems[_target]._report.send_bridgeEvent('UNIT DATA,START,TX,{},{},{},{},{},{}'.format(_target, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), 1, _int_dst_id).encode(encoding='utf-8', errors='ignore')) - def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data,_hash): + def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data,_hash,_hops): pkt_time = time() dmrpkt = _data[20:53] _bits = _data[15] @@ -1583,7 +1583,7 @@ class routerOBP(OPENBRIDGE): _tmp_bits = _bits ^ 1 << 7 else: _tmp_bits = _bits - self.sendDataToHBP(_d_system,_d_slot,_dst_id,_tmp_bits,_data,dmrpkt,_rf_src,_stream_id,_peer_id) + self.sendDataToHBP(_d_system,_d_slot,_dst_id,_tmp_bits,_data,dmrpkt,_rf_src,_stream_id,_peer_id,_hops) else: logger.info('(%s) UNIT Data not bridged to HBP on slot 1 - target busy: %s DST_ID: %s',self._system,_d_system,_int_dst_id) @@ -2020,7 +2020,7 @@ class routerHBP(HBSYSTEM): _tmp_data = b''.join([_tmp_data, dmrpkt, _data[53:55]]) # Transmit the packet to the destination system - systems[_target['SYSTEM']].send_system(_tmp_data) + systems[_target['SYSTEM']].send_system(_tmp_data,None) return _sysIgnore @@ -2029,12 +2029,12 @@ class routerHBP(HBSYSTEM): _int_dst_id = int_id(_dst_id) _tmp_data = b''.join([_data[:15], _tmp_bits.to_bytes(1, 'big'), _data[16:20]]) _tmp_data = b''.join([_tmp_data, dmrpkt]) - systems[_d_system].send_system(_tmp_data) + systems[_d_system].send_system(_tmp_data,None) logger.info('(%s) UNIT Data Bridged to HBP on slot 1: %s DST_ID: %s',self._system,_d_system,_int_dst_id) if CONFIG['REPORTS']['REPORT']: systems[_d_system]._report.send_bridgeEvent('UNIT DATA,START,TX,{},{},{},{},{},{}'.format(_d_system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), 1, _int_dst_id).encode(encoding='utf-8', errors='ignore')) - def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot): + def sendDataToOBP(self,_target,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,_hops): # _sysIgnore = sysIgnore _int_dst_id = int_id(_dst_id) _target_status = systems[_target].STATUS @@ -2069,7 +2069,7 @@ class routerHBP(HBSYSTEM): #Assemble transmit HBP packet header _tmp_data = b''.join([_data[:15], _tmp_bits.to_bytes(1, 'big'), _data[16:20]]) _tmp_data = b''.join([_tmp_data, dmrpkt]) - systems[_target].send_system(_tmp_data) + systems[_target].send_system(_tmp_data,None) logger.info('(%s) UNIT Data Bridged to OBP System: %s DST_ID: %s', self._system, _target,_int_dst_id) if CONFIG['REPORTS']['REPORT']: systems[system]._report.send_bridgeEvent('UNIT DATA,START,TX,{},{},{},{},{},{}'.format(_target, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), 1, _int_dst_id).encode(encoding='utf-8', errors='ignore')) @@ -2151,7 +2151,7 @@ class routerHBP(HBSYSTEM): continue #We only want to send data calls to individual IDs via OpenBridge if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE' and (_int_dst_id >= 1000000): - self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot) + self.sendDataToOBP(system,_data,dmrpkt,pkt_time,_stream_id,_dst_id,_peer_id,_rf_src,_bits,_slot,None) #If destination ID is in the Subscriber Map @@ -2166,7 +2166,7 @@ class routerHBP(HBSYSTEM): _tmp_bits = _bits ^ 1 << 7 else: _tmp_bits = _bits - self.sendDataToHBP(_d_system,_d_slot,_dst_id,_tmp_bits,_data,dmrpkt,_rf_src,_stream_id,_peer_id) + self.sendDataToHBP(_d_system,_d_slot,_dst_id,_tmp_bits,_data,dmrpkt,_rf_src,_stream_id,_peer_id,None) else: logger.info('(%s) UNIT Data not bridged to HBP on slot 1 - target busy: %s DST_ID: %s',self._system,_d_system,_int_dst_id) diff --git a/hblink.py b/hblink.py index c063249..d1efbc6 100755 --- a/hblink.py +++ b/hblink.py @@ -137,19 +137,22 @@ class OPENBRIDGE(DatagramProtocol): def dereg(self): logger.info('(%s) is mode OPENBRIDGE. No De-Registration required, continuing shutdown', self._system) - def send_system(self, _packet): + def send_system(self, _packet,_hops): #Don't do anything if we are STUNned if 'STUN' in self._CONFIG: logger.info('(%s) Bridge STUNned, discarding', self._system) return + if not _hops: + _hops = bytes(0) + if _packet[:3] == DMR and self._config['TARGET_IP']: if 'VER' in self._config and self._config['VER'] > 1: _packet = b''.join([DMRF,_packet[4:11], self._CONFIG['GLOBAL']['SERVER_ID'],_packet[15:], time_ns().to_bytes(8,'big')]) _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) _h.update(_packet) _hash = _h.digest() - _packet = b''.join([_packet, _hash]) + _packet = b''.join([_packet,_hops, _hash]) 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 %s', self._system, self._config['TARGET_IP'], self._config['TARGET_PORT'], _packet, _hash) @@ -173,7 +176,15 @@ class OPENBRIDGE(DatagramProtocol): logger.debug('(%s) *BridgeControl* sent KeepAlive',self._system) else: logger.debug('(%s) *BridgeControl* not sending KeepAlive, TARGET_IP currently not known',self._system) - + + def send_bcst(self): + if self._config['TARGET_IP']: + _packet = BCST + _packet = b''.join([_packet[:4], (hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest())]) + self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) + logger.debug('(%s) *BridgeControl* sent BCST STUN',self._system) + else: + logger.debug('(%s) *BridgeControl* not sending BCST STUN, TARGET_IP currently not known',self._system) def send_bcsq(self,_tgid,_stream_id): if self._config['TARGET_IP']: @@ -303,7 +314,8 @@ class OPENBRIDGE(DatagramProtocol): elif _packet[:4] == DMRF: _data = _packet[:53] _timestamp = _packet[53:60] - _hash = _packet[61:] + _hops = _packet[61] + _hash = _packet[62:] #_ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) _h.update(_packet[:61])