From 615609c724480714fce32891f5e9e6a1997fedaf Mon Sep 17 00:00:00 2001 From: Max Weller Date: Fri, 17 Nov 2017 17:01:59 +0100 Subject: [PATCH] add proper decoding for cable test results using test result code -> description lookup from decompiled netgear software --- cli/src/com_cabletest.c | 2 +- lib/include/ngadmin.h | 18 +++++++++++++++--- lib/src/ports.c | 4 ++-- raw/include/nsdp/protocol.h | 4 ++-- raw/include/nsdp/str.h | 2 ++ raw/src/attr.c | 8 ++++---- raw/src/str.c | 12 ++++++++++++ 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cli/src/com_cabletest.c b/cli/src/com_cabletest.c index b5dfab3..412fc4b 100644 --- a/cli/src/com_cabletest.c +++ b/cli/src/com_cabletest.c @@ -38,7 +38,7 @@ int do_cabletest (int argc, const char **argv, struct ngadmin *nga) } for (i = 0; i < j; i++) - printf("port %i: %08X %08X\n", ct[i].port, ct[i].v1, ct[i].v2); + printf("port %i: %s, code=%d, distance=%d m\n", ct[i].port, getCableTestResultStr(ct[i].test_result), ct[i].test_result, ct[i].fault_distance); end: free(ct); diff --git a/lib/include/ngadmin.h b/lib/include/ngadmin.h index a7e17de..821cedc 100644 --- a/lib/include/ngadmin.h +++ b/lib/include/ngadmin.h @@ -225,11 +225,23 @@ struct igmp_conf { */ struct cabletest { char port; /**< port */ - int v1; /**< raw value 1 */ - int v2; /**< raw value 2 */ + int test_result; /**< test result code (see enum) */ + int fault_distance; /**< fault distance / cable length in meters */ }; - +/** + * Cabletest result codes + */ +enum { + CABLETEST_OK = 0, // System0056 = OK + CABLETEST_NO_CABLE = 1, // System0052 = No Cable + CABLETEST_OPEN_CABLE = 2, // System0053 = Open Cable + CABLETEST_SHORT_CIRCUIT = 3, // System0054 = Short Circuit + CABLETEST_FIBER_CABLE = 4, // System0055 = Fiber Cable + CABLETEST_SHORTED_CABLE = 5, // System0064 = Shorted cable + CABLETEST_UNKNOWN = 6, // System0065 = Unknown + CABLETEST_CROSSTALK = 7 // System0066 = Crosstalk +}; #ifdef __cplusplus extern "C" { diff --git a/lib/src/ports.c b/lib/src/ports.c index f5243e5..46e9689 100644 --- a/lib/src/ports.c +++ b/lib/src/ports.c @@ -165,8 +165,8 @@ int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb) goto end; } if (acr->port == ct[i].port) { - ct[i].v1 = acr->v1; - ct[i].v2 = acr->v2; + ct[i].test_result = acr->test_result; + ct[i].fault_distance = acr->fault_distance; break; } } diff --git a/raw/include/nsdp/protocol.h b/raw/include/nsdp/protocol.h index 70d111e..dd12008 100644 --- a/raw/include/nsdp/protocol.h +++ b/raw/include/nsdp/protocol.h @@ -145,8 +145,8 @@ struct attr_cabletest_do { struct attr_cabletest_result { unsigned char port; /* port number */ - unsigned int v1; /* raw value 1 (values unknown yet) */ - unsigned int v2; /* raw value 2 (values unknown yet) */ + unsigned int test_result; /* Cable test result code */ + unsigned int fault_distance; /* fault distance or cable length in meters */ } __attribute__((packed)); diff --git a/raw/include/nsdp/str.h b/raw/include/nsdp/str.h index d9a0a28..1a9a1a2 100644 --- a/raw/include/nsdp/str.h +++ b/raw/include/nsdp/str.h @@ -17,6 +17,7 @@ extern const char* const qos_prio_str_tab[]; extern const char* const bitrate_str_tab[]; extern const char* const code_str_tab[]; extern const char* const error_str_tab[]; +extern const char* const cable_test_result_str_tab[]; static inline const char* safeStr (const char *s) @@ -39,6 +40,7 @@ static inline const char* getValueStr (const char* const* tab, unsigned char min #define getBitrateStr(bitrate) getValueStr(bitrate_str_tab, BITRATE_NOLIMIT, BITRATE_512M, bitrate) #define getCodeStr(code) getValueStr(code_str_tab, CODE_READ_REQ, CODE_WRITE_REP, code) #define getErrorStr(error) getValueStr(error_str_tab, ERROR_NONE, ERROR_DENIED, error) +#define getCableTestResultStr(error) getValueStr(cable_test_result_str_tab, ERROR_NONE, ERROR_DENIED, error) int parseValueStr (const char* const* tab, unsigned char mini, unsigned char maxi, const char *str); diff --git a/raw/src/attr.c b/raw/src/attr.c index 3d0e4c9..f2d5009 100644 --- a/raw/src/attr.c +++ b/raw/src/attr.c @@ -208,11 +208,11 @@ static int cabletest_result_endecode (struct attr *at, bool encode) return -EMSGSIZE; if (encode) { - acr->v1 = htonl(acr->v1); - acr->v2 = htonl(acr->v2); + acr->test_result = htonl(acr->test_result); + acr->fault_distance = htonl(acr->fault_distance); } else { - acr->v1 = ntohl(acr->v1); - acr->v2 = ntohl(acr->v2); + acr->test_result = ntohl(acr->test_result); + acr->fault_distance = ntohl(acr->fault_distance); } return 0; diff --git a/raw/src/str.c b/raw/src/str.c index 5ae1fc8..27cdc42 100644 --- a/raw/src/str.c +++ b/raw/src/str.c @@ -88,6 +88,18 @@ const char* const error_str_tab[] = { }; +const char* const cable_test_result_str_tab[] = { + [CABLETEST_OK] = "OK", + [CABLETEST_NO_CABLE] = "No Cable", + [CABLETEST_OPEN_CABLE] = "Open Cable", + [CABLETEST_SHORT_CIRCUIT] = "Short Circuit", + [CABLETEST_FIBER_CABLE] = "Fiber Cable", + [CABLETEST_SHORTED_CABLE] = "Shorted cable", + [CABLETEST_UNKNOWN] = "Unknown", + [CABLETEST_CROSSTALK] = "Crosstalk", + NULL +}; + int parseValueStr (const char* const* tab, unsigned char mini, unsigned char maxi, const char *str) { unsigned char i;