Remove unneeded code & includes.
On Windows, when performing config dumps, found that packets were being lost
but we were not detecting this.  Added code to check the sequence numbers of
the incoming packets.  Additionally, added a check after the loop to ensure
that the read did not time out.

Signed-off-by: Scott Talbert <s...@techie.net>
---
 concordance/concordance.c | 26 --------------------------
 libconcord/remote.cpp     |  2 --
 libconcord/remote_mh.cpp  | 12 +++++++++++-
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/concordance/concordance.c b/concordance/concordance.c
index e3cd32b..3486f44 100644
--- a/concordance/concordance.c
+++ b/concordance/concordance.c
@@ -32,8 +32,6 @@
 #include <conio.h>
 #include <winsock.h>
 
-HANDLE con;
-
 /*
  * (see below) Windows does not need this, since _getch already
  * does what we need - just make set_canon do nothing 
@@ -152,11 +150,6 @@ void cb_print_percent_status(uint32_t stage_id, uint32_t 
count, uint32_t curr,
     uint32_t total, uint32_t counter_type, void *arg,
     const uint32_t *stages)
 {
-
-#ifdef _WIN32
-    CONSOLE_SCREEN_BUFFER_INFO sbi;
-#endif
-
     if (stage_id == LC_CB_STAGE_NUM_STAGES) {
 #if _DEBUG
         printf("Num stages: %d\n", count);
@@ -165,16 +158,7 @@ void cb_print_percent_status(uint32_t stage_id, uint32_t 
count, uint32_t curr,
     }
 
     if (count != 0) {
-#ifdef _WIN32
-        GetConsoleScreenBufferInfo(con, &sbi);
-        sbi.dwCursorPosition.X -= 14;
-        if (sbi.dwCursorPosition.X < 0) {
-            sbi.dwCursorPosition.X = 0;
-        }
-        SetConsoleCursorPosition(con, sbi.dwCursorPosition);
-#else
         printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
-#endif
     } else {
         print_stage_name(stage_id);
     }
@@ -937,20 +921,10 @@ int main(int argc, char *argv[])
     char *file_name;
     int mode, file_mode, err;
 
-#ifdef _WIN32
-    con=GetStdHandle(STD_OUTPUT_HANDLE);
-    SetConsoleTextAttribute(con,FOREGROUND_BLUE|FOREGROUND_INTENSITY);
-#endif
-
     printf("Concordance %s\n", VERSION);
     printf("Copyright 2007 Kevin Timmerman and Phil Dibowitz\n");
     printf("This software is distributed under the GPLv3.\n\n");
 
-#ifdef _WIN32
-    SetConsoleTextAttribute(con,
-                            FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
-#endif
-
     file_name = NULL;
     mode = MODE_UNSET;
 
diff --git a/libconcord/remote.cpp b/libconcord/remote.cpp
index cd972c6..3a50cbe 100644
--- a/libconcord/remote.cpp
+++ b/libconcord/remote.cpp
@@ -24,8 +24,6 @@
 #include <string.h>
 #include <errno.h>
 
-#include <iostream>
-
 #include "libconcord.h"
 #include "lc_internal.h"
 #include "hid.h"
diff --git a/libconcord/remote_mh.cpp b/libconcord/remote_mh.cpp
index 2670419..9268195 100644
--- a/libconcord/remote_mh.cpp
+++ b/libconcord/remote_mh.cpp
@@ -23,7 +23,6 @@
 #include "remote.h"
 
 #include <string.h>
-#include <iostream>
 #include <stdlib.h>
 
 #include "libconcord.h"
@@ -254,11 +253,19 @@ int CRemoteMH::ReadFile(const char *filename, uint8_t 
*rd, const uint32_t rdlen,
     debug("msg_ack");
     debug_print_packet(rsp);
 
+    uint8_t exp_seq = rsp[2] & 0x3F;
     int pkt_count = 0;
     *data_read = 0;
     uint8_t *rd_ptr = rd;
     while(!(err = HID_ReadReport(rsp, MH_TIMEOUT))) {
         debug_print_packet(rsp);
+        get_seq(exp_seq);
+        uint8_t rcv_seq = rsp[0] & 0x3F;
+        if (exp_seq != rcv_seq) {
+            debug("ERROR: unexpected sequence # - packet lost! %02x %02x",
+                  exp_seq, rcv_seq);
+            return LC_ERROR_READ;
+        }
         // Ignore 1st two bits on 2nd byte for length.
         int len = rsp[1] & 0x3F;
         // Skip 1st two bytes, read up to packet length.  "len"
@@ -298,12 +305,15 @@ int CRemoteMH::ReadFile(const char *filename, uint8_t 
*rd, const uint32_t rdlen,
                 debug("Failed to read from remote");
                 return LC_ERROR_READ;
             }
+            exp_seq = rsp[2] & 0x3F;
             debug("ack");
             debug_print_packet(rsp);
             pkt_count = 0;
         }
     }
     debug("data_read=%d", *data_read);
+    if (err)
+        return err;
 
     if ((err = reset_sequence(get_seq(seq), param)))
         return err;
-- 
1.8.5.3


------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel

Reply via email to