Add more hints

In response to #156 and #164.
This commit is contained in:
Joseph C. Lehner 2025-03-07 08:29:12 +01:00
parent a8cf411561
commit 924ff34d1b
3 changed files with 34 additions and 12 deletions

28
main.c
View file

@ -311,13 +311,27 @@ int main(int argc, char **argv)
val = ethsock_list_all();
} else {
val = nmrp_do(&args);
if (val != 0 && args.maybe_invalid_firmware_file) {
fprintf(stderr,
"\n"
"Firmware file rejected by remote device. Possible causes:\n"
"- Wrong firmware file (model number correct?)\n"
"- Wrong file format (e.g. .chk vs .trx file)\n"
"- Downgrading to a lower version number\n");
if (val != 0) {
if (args.hints & NMRP_MAYBE_FIRMWARE_INVALID) {
fprintf(stderr,
"\n"
"Firmware file rejected by router. Possible causes:\n"
"- Wrong firmware file (model number correct?)\n"
"- Wrong file format (e.g. .chk vs .trx file)\n"
"- Downgrading to a lower version number\n");
} else if (args.hints & NMRP_NO_ETHERNET_CONNECTION) {
fprintf(stderr,
"No Ethernet connection detected. Possible causes:\n"
"- Wrong Ethernet port - try others there's more than one\n"
"- Bad Ethernet cable\n"
"- Hardware issue\n");
} else if (args.hints & NMRP_NO_NMRP_RESPONSE) {
fprintf(stderr,
"No response from router. Possible causes/fixes:\n"
"- Unsupported router\n"
"- Wrong Ethernet port - try others if there's more than one\n"
"- Try holding reset button for a few seconds while powering on router\n");
}
}
}

12
nmrp.c
View file

@ -412,7 +412,7 @@ int nmrp_do(struct nmrpd_args *args)
struct in_addr ipaddr;
struct in_addr ipmask;
args->maybe_invalid_firmware_file = false;
args->hints = 0;
if (args->op != NMRP_UPLOAD_FW) {
fprintf(stderr, "Operation not implemented.\n");
@ -512,6 +512,7 @@ int nmrp_do(struct nmrpd_args *args)
if (unplugged) {
if (!g_interrupted) {
args->hints |= NMRP_NO_ETHERNET_CONNECTION;
fprintf(stderr, "Error: Ethernet cable is unplugged.\n");
goto out;
} else {
@ -597,8 +598,11 @@ int nmrp_do(struct nmrpd_args *args)
status = 1;
if ((time_monotonic() - beg) >= timeout) {
printf("\nNo response after %d seconds. ", timeout);
args->hints |= NMRP_NO_NMRP_RESPONSE;
if (!args->blind || !was_plugged_in) {
if (!was_plugged_in) {
args->hints |= NMRP_NO_ETHERNET_CONNECTION;
printf("Ethernet cable unplugged. ");
}
@ -641,7 +645,7 @@ int nmrp_do(struct nmrpd_args *args)
msg_code_str(rx.msg.code), msg_code_str(expect));
if (ulreqs && expect == NMRP_C_TFTP_UL_REQ && rx.msg.code == NMRP_C_CONF_REQ) {
args->maybe_invalid_firmware_file = true;
args->hints |= NMRP_MAYBE_FIRMWARE_INVALID;
}
if (++unexpected > 5) {
@ -677,7 +681,7 @@ int nmrp_do(struct nmrpd_args *args)
break;
case NMRP_C_TFTP_UL_REQ:
if (++ulreqs > 1) {
args->maybe_invalid_firmware_file = true;
args->hints |= NMRP_MAYBE_FIRMWARE_INVALID;
}
if (ulreqs > NMRP_MAX_UL_REQS) {
@ -755,7 +759,7 @@ int nmrp_do(struct nmrpd_args *args)
// file has been rejected. this feature is only implemented
// by some bootloaders.
expect = NMRP_C_TFTP_UL_REQ;
args->maybe_invalid_firmware_file = true;
args->hints |= NMRP_MAYBE_FIRMWARE_INVALID;
} else {
goto out;
}

View file

@ -87,6 +87,10 @@
#define NMRP_ETH_TIMEOUT_S 60
#define NMRP_MAX_UL_REQS 3
#define NMRP_MAYBE_FIRMWARE_INVALID (1 << 0)
#define NMRP_NO_ETHERNET_CONNECTION (1 << 1)
#define NMRP_NO_NMRP_RESPONSE (1 << 2)
struct eth_hdr {
uint8_t ether_dhost[6];
uint8_t ether_shost[6];
@ -117,7 +121,7 @@ struct nmrpd_args {
uint16_t port;
const char *region;
off_t offset;
bool maybe_invalid_firmware_file;
int hints;
struct ethsock *sock;
};