Accept pretty names for -R instead of codes
This commit is contained in:
parent
cbb94be759
commit
d7caf78f5e
3 changed files with 33 additions and 11 deletions
12
main.c
12
main.c
|
@ -42,7 +42,7 @@ void usage(FILE *fp)
|
||||||
" -T <timeout> Time (seconds) to wait after successfull TFTP upload\n"
|
" -T <timeout> Time (seconds) to wait after successfull TFTP upload\n"
|
||||||
" -p <port> Port to use for TFTP upload\n"
|
" -p <port> Port to use for TFTP upload\n"
|
||||||
#ifdef NMRPFLASH_SET_REGION
|
#ifdef NMRPFLASH_SET_REGION
|
||||||
" -R <region> Set device region\n"
|
" -R <region> Set device region (NA, WW, GR, PR, RU, BZ, IN, KO, JP)\n"
|
||||||
#endif
|
#endif
|
||||||
#ifdef NMRPFLASH_TFTP_TEST
|
#ifdef NMRPFLASH_TFTP_TEST
|
||||||
" -U Test TFTP upload\n"
|
" -U Test TFTP upload\n"
|
||||||
|
@ -83,7 +83,7 @@ int main(int argc, char **argv)
|
||||||
.mac = "ff:ff:ff:ff:ff:ff",
|
.mac = "ff:ff:ff:ff:ff:ff",
|
||||||
.op = NMRP_UPLOAD_FW,
|
.op = NMRP_UPLOAD_FW,
|
||||||
.port = 69,
|
.port = 69,
|
||||||
.force_root = 1
|
.region = NULL,
|
||||||
};
|
};
|
||||||
#ifdef NMRPFLASH_WINDOWS
|
#ifdef NMRPFLASH_WINDOWS
|
||||||
WSADATA wsa;
|
WSADATA wsa;
|
||||||
|
@ -121,16 +121,16 @@ int main(int argc, char **argv)
|
||||||
case 'M':
|
case 'M':
|
||||||
args.ipmask = optarg;
|
args.ipmask = optarg;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
|
||||||
#ifdef NMRPFLASH_SET_REGION
|
#ifdef NMRPFLASH_SET_REGION
|
||||||
case 'R':
|
case 'R':
|
||||||
|
args.region = optarg;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case 'p':
|
||||||
case 'T':
|
case 'T':
|
||||||
case 't':
|
case 't':
|
||||||
if (c == 'p') {
|
if (c == 'p') {
|
||||||
max = 0xffff;
|
max = 0xffff;
|
||||||
} else if (c == 'R') {
|
|
||||||
max = 0x0009;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val = atoi(optarg);
|
val = atoi(optarg);
|
||||||
|
@ -145,8 +145,6 @@ int main(int argc, char **argv)
|
||||||
args.rx_timeout = val;
|
args.rx_timeout = val;
|
||||||
} else if (c == 'T') {
|
} else if (c == 'T') {
|
||||||
args.ul_timeout = val * 1000;
|
args.ul_timeout = val * 1000;
|
||||||
} else if (c == 'R') {
|
|
||||||
args.region = val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
29
nmrp.c
29
nmrp.c
|
@ -118,6 +118,22 @@ static const char *msg_code_str(uint16_t code)
|
||||||
#undef CASE_CODE
|
#undef CASE_CODE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint16_t to_region_code(const char *region)
|
||||||
|
{
|
||||||
|
#define REGION_CODE(r, c) if (!strcasecmp(region, r)) return c
|
||||||
|
REGION_CODE("NA", 0x0001);
|
||||||
|
REGION_CODE("WW", 0x0002);
|
||||||
|
REGION_CODE("GR", 0x0003);
|
||||||
|
REGION_CODE("PR", 0x0004);
|
||||||
|
REGION_CODE("RU", 0x0005);
|
||||||
|
REGION_CODE("BZ", 0x0006);
|
||||||
|
REGION_CODE("IN", 0x0007);
|
||||||
|
REGION_CODE("KO", 0x0008);
|
||||||
|
REGION_CODE("JP", 0x0009);
|
||||||
|
#undef REGION_CODE
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void msg_dump(struct nmrp_msg *msg, int dump_opts)
|
static void msg_dump(struct nmrp_msg *msg, int dump_opts)
|
||||||
{
|
{
|
||||||
struct nmrp_opt *opt;
|
struct nmrp_opt *opt;
|
||||||
|
@ -420,6 +436,16 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->region) {
|
||||||
|
region = htons(to_region_code(args->region));
|
||||||
|
if (!region) {
|
||||||
|
fprintf(stderr, "Invalid region code '%s'.\n", args->region);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
region = 0;
|
||||||
|
}
|
||||||
|
|
||||||
status = 1;
|
status = 1;
|
||||||
|
|
||||||
sock = ethsock_create(args->intf, ETH_P_NMRP);
|
sock = ethsock_create(args->intf, ETH_P_NMRP);
|
||||||
|
@ -513,8 +539,7 @@ int nmrp_do(struct nmrpd_args *args)
|
||||||
msg_opt_add(&tx.msg, NMRP_O_FW_UP, NULL, 0);
|
msg_opt_add(&tx.msg, NMRP_O_FW_UP, NULL, 0);
|
||||||
|
|
||||||
#ifdef NMRPFLASH_SET_REGION
|
#ifdef NMRPFLASH_SET_REGION
|
||||||
if (args->region) {
|
if (region) {
|
||||||
region = htons(args->region);
|
|
||||||
msg_opt_add(&tx.msg, NMRP_O_DEV_REGION, ®ion, 2);
|
msg_opt_add(&tx.msg, NMRP_O_DEV_REGION, ®ion, 2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
3
nmrpd.h
3
nmrpd.h
|
@ -71,8 +71,7 @@ struct nmrpd_args {
|
||||||
const char *mac;
|
const char *mac;
|
||||||
enum nmrp_op op;
|
enum nmrp_op op;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint16_t region;
|
const char *region;
|
||||||
int force_root;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *leafname(const char *path);
|
const char *leafname(const char *path);
|
||||||
|
|
Loading…
Add table
Reference in a new issue