Index: types.h
===================================================================
--- types.h	(revision 1365)
+++ types.h	(working copy)
@@ -73,6 +73,7 @@
 	uint8_t tq_index;
 	uint8_t tq_avg;
 	uint8_t last_ttl;
+        uint16_t seqno;         /* Most recent seqno received from this neighbor */
 	unsigned long last_valid;            /* when last packet via this neighbour was received */
 	TYPE_OF_WORD real_bits[NUM_WORDS];
 	struct orig_node *orig_node;
Index: routing.c
===================================================================
--- routing.c	(revision 1365)
+++ routing.c	(working copy)
@@ -305,6 +305,9 @@
 	orig_node->flags = batman_packet->flags;
 	neigh_node->last_valid = jiffies;
 
+        if(batman_packet->seqno > neigh_node->seqno)
+            neigh_node->seqno = batman_packet->seqno;
+        
 	ring_buffer_set(neigh_node->tq_recv, &neigh_node->tq_index, batman_packet->tq);
 	neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
 
@@ -320,10 +323,16 @@
 		best_neigh_node = neigh_node;
 
 	}
-
-	tmp_hna_buff_len = (hna_buff_len > batman_packet->num_hna * ETH_ALEN ? batman_packet->num_hna * ETH_ALEN : hna_buff_len);
-
-	update_routes(orig_node, best_neigh_node, hna_buff, tmp_hna_buff_len);
+        
+        if(best_neigh_node == NULL || orig_node->router == NULL){
+                tmp_hna_buff_len = (hna_buff_len > batman_packet->num_hna * ETH_ALEN ? batman_packet->num_hna * ETH_ALEN : hna_buff_len);
+                update_routes(orig_node, best_neigh_node, hna_buff, tmp_hna_buff_len);         
+                
+                /* Resolving the tmpt looping: only when best_neigh_node has up-to-date seqno, switch to it */
+        }else if(best_neigh_node->seqno > orig_node->router->seqno){                
+                tmp_hna_buff_len = (hna_buff_len > batman_packet->num_hna * ETH_ALEN ? batman_packet->num_hna * ETH_ALEN : hna_buff_len);
+                update_routes(orig_node, best_neigh_node, hna_buff, tmp_hna_buff_len);
+        }
 }
 
 static char count_real_packets(struct ethhdr *ethhdr, struct batman_packet *batman_packet, struct batman_if *if_incoming)
@@ -367,7 +376,10 @@
 	char has_directlink_flag;
 	char is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0, is_broadcast = 0, is_bidirectional, is_single_hop_neigh, is_duplicate;
 	unsigned short if_incoming_seqno;
-
+        
+        struct neigh_node *tmp_neigh_node = NULL;
+        
+        
 	/* could be changed by schedule_own_packet() */
 	if_incoming_seqno = atomic_read(&if_incoming->seqno);
 
@@ -435,22 +447,35 @@
 		return;
 	}
 
+        orig_node = get_orig_node(batman_packet->orig);
+	if (orig_node == NULL)
+		return;
+
+        /* When the echo contains a tq from neighbor that is worse
+         * than the current average via that neighbor, update the avg
+         * tq to circumvent the stale tq reading */
 	if (is_my_oldorig) {
+                list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {                        
+                        if (compare_orig(tmp_neigh_node->addr, ethhdr->h_source) && (tmp_neigh_node->if_incoming == if_incoming)) {
+                                if(batman_packet->tq < tmp_neigh_node->tq_avg){
+                                        ring_buffer_set(tmp_neigh_node->tq_recv, &tmp_neigh_node->tq_index, batman_packet->tq);
+                                        tmp_neigh_node->tq_avg = ring_buffer_avg(tmp_neigh_node->tq_recv);
+                                }
+                        }
+                }
+                
 		debug_log(LOG_TYPE_BATMAN, "Drop packet: ignoring all rebroadcast echos (sender: %s) \n", neigh_str);
 		return;
 	}
-
+        
 	is_duplicate = count_real_packets(ethhdr, batman_packet, if_incoming);
-
-	orig_node = get_orig_node(batman_packet->orig);
-	if (orig_node == NULL)
-		return;
-
+        
+        
 	/* if sender is a direct neighbor the sender mac equals originator mac */
 	orig_neigh_node = (is_single_hop_neigh ? orig_node : get_orig_node(ethhdr->h_source));
 	if (orig_neigh_node == NULL)
 		return;
-
+        
 	/* drop packet if sender is not a direct neighbor and if we don't route towards it */
 	if (!is_single_hop_neigh && (orig_neigh_node->router == NULL)) {
 		debug_log(LOG_TYPE_BATMAN, "Drop packet: OGM via unknown neighbor! \n");
