Add code to support setting the device region
This commit is contained in:
		
							parent
							
								
									4247a2870f
								
							
						
					
					
						commit
						a6c40ee917
					
				
					 3 changed files with 26 additions and 3 deletions
				
			
		
							
								
								
									
										19
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								nmrp.c
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								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",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								nmrpd.h
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								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;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue