Add code to support setting the device region
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Fri, 12 Feb 2016 13:48:42 +0000 (14:48 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Fri, 12 Feb 2016 13:48:42 +0000 (14:48 +0100)
main.c
nmrp.c
nmrpd.h

diff --git a/main.c b/main.c
index 55a046e3626786a5550c1539f00cffb45c94ca69..9760c61fad06bd59862276981cb18730d26151de 100644 (file)
--- a/main.c
+++ b/main.c
@@ -41,6 +41,9 @@ void usage(FILE *fp)
                        " -t <timeout>    Timeout (in milliseconds) for regular messages\n"
                        " -T <timeout>    Time (seconds) to wait after successfull TFTP upload\n"
                        " -p <port>       Port to use for TFTP upload\n"
+#ifdef NMRPFLASH_SET_REGION
+                       " -R <region>     Set device region\n"
+#endif
 #ifdef NMRPFLASH_TFTP_TEST
                        " -U              Test TFTP upload\n"
 #endif
@@ -94,7 +97,7 @@ int main(int argc, char **argv)
 
        opterr = 0;
 
-       while ((c = getopt(argc, argv, "a:c:f:F:i:m:M:p:t:T:hLVvU")) != -1) {
+       while ((c = getopt(argc, argv, "a:c:f:F:i:m:M:p:R:t:T:hLVvU")) != -1) {
                max = 0x7fffffff;
                switch (c) {
                        case 'a':
@@ -119,9 +122,17 @@ int main(int argc, char **argv)
                                args.ipmask = optarg;
                                break;
                        case 'p':
-                               max = 0xffff;
+#ifdef NMRPFLASH_SET_REGION
+                       case 'R':
+#endif
                        case 'T':
                        case 't':
+                               if (c == 'p') {
+                                       max = 0xffff;
+                               } else if (c == 'R') {
+                                       max = 0x0009;
+                               }
+
                                val = atoi(optarg);
                                if (val <= 0 || val > max) {
                                        fprintf(stderr, "Invalid numeric value for -%c.\n", c);
@@ -132,8 +143,10 @@ int main(int argc, char **argv)
                                        args.port = val;
                                } else if (c == 't') {
                                        args.rx_timeout = val;
-                               } else {
+                               } else if (c == 'T') {
                                        args.ul_timeout = val * 1000;
+                               } else if (c == 'R') {
+                                       args.region = val;
                                }
 
                                break;
diff --git a/nmrp.c b/nmrp.c
index 0bd9b19382e264246221a3c7e937ad54f84bb246..1cedaba42634289c1f2283a4a14c56c801dfccd7 100644 (file)
--- a/nmrp.c
+++ b/nmrp.c
@@ -67,6 +67,7 @@ struct nmrp_opt {
        uint16_t len;
        union {
                uint8_t magic[4];
+               uint16_t region;
                struct {
                        uint8_t addr[4];
                        uint8_t mask[4];
@@ -426,6 +427,14 @@ int nmrp_do(struct nmrpd_args *args)
                                tx.msg.opts[1].type = NMRP_O_FW_UP;
                                tx.msg.opts[1].len = NMRP_OPT_LEN;
 
+#ifdef NMRPFLASH_SET_REGION
+                               tx.msg.num_opts = 3;
+
+                               tx.msg.opts[2].type = NMRP_O_DEV_REGION;
+                               tx.msg.opts[2].len = NMRP_OPT_LEN + 2;
+                               tx.msg.opts[2].val.region = args->region;
+#endif
+
                                expect = NMRP_C_TFTP_UL_REQ;
 
                                printf("Received configuration request from %s.\n",
diff --git a/nmrpd.h b/nmrpd.h
index 049b6479d15a720b61cc47bf0151d7a2ebb42cee..125dc557c43b681916f49e36253561ca5bc86277 100644 (file)
--- a/nmrpd.h
+++ b/nmrpd.h
@@ -67,6 +67,7 @@ struct nmrpd_args {
        const char *mac;
        enum nmrp_op op;
        uint16_t port;
+       uint16_t region;
        int force_root;
 };