コード例 #1
0
ファイル: libipt_SET.c プロジェクト: jameshilliard/20-4-4
static void SET_save(const void *ip, const struct xt_entry_target *target)
{
	struct ipt_set_info_target *info =
	    (struct ipt_set_info_target *) target->data;

	print_target("--add-set", &info->add_set);
	print_target("--del-set", &info->del_set);
}
コード例 #2
0
ファイル: libipt_SET.c プロジェクト: jameshilliard/20-4-4
static void SET_print(const void *ip, const struct xt_entry_target *target,
                      int numeric)
{
	struct ipt_set_info_target *info =
	    (struct ipt_set_info_target *) target->data;

	print_target("add-set", &info->add_set);
	print_target("del-set", &info->del_set);
}
コード例 #3
0
// parse the response to reading the other device's Basic Attributes
int basic_parse( zcl_command_t *zcl)
{
	uint8_t			response = ZCL_STATUS_SUCCESS;
	int				i;

/*
	find the device in our target_t list
	use a list of offsets into target_t, along with attr ID, type and length limits
	copy the attribute values from the response, ignore non-SUCCESS status

*/
	i = find_target( &zcl->envelope->ieee_address);
	if (i >= 0)
	{
		if (target_list[i].basic.app_ver > 0)
		{
			//puts( "ignoring duplicate basic response");
		}
		else
		{
			memset( &basic_value, 0, sizeof basic_value);

			response = zcl_process_read_attr_response( zcl, &basic_attr.app_ver);

			target_list[i].basic = basic_value;
			print_target( i);
		}
	}

	return zcl_default_response( zcl, response);
}
コード例 #4
0
ファイル: target_manager.c プロジェクト: 7sam7/openjpeg
void print_alltarget( targetlist_param_t *targetlist)
{
  target_param_t *ptr;

  ptr = targetlist->first;
  while( ptr != NULL){
    print_target( ptr);
    ptr=ptr->next;
  }
}
コード例 #5
0
void print_allsession( sessionlist_param_t *sessionlist)
{
  session_param_t *ptr;
  cachemodel_param_t *cachemodel;
  int i=0;

  fprintf( logstream, "SESSIONS info:\n");

  ptr = sessionlist->first;
  while( ptr != NULL){
    fprintf( logstream, "session No.%d\n", i++);
    print_allchannel( ptr->channellist);
    cachemodel = ptr->cachemodellist->first;
    while( cachemodel){
      print_target( cachemodel->target);
      cachemodel = cachemodel->next;
    }
    ptr=ptr->next;
  }
}
コード例 #6
0
ファイル: dump_record.c プロジェクト: h4ck3rm1k3/FIS-GT.M
sm_uc_ptr_t  dump_record(sm_uc_ptr_t rp, block_id blk, sm_uc_ptr_t bp, sm_uc_ptr_t b_top)
{
	sm_uc_ptr_t	r_top, key_top, cptr0, cptr1;
	char		key_buf[MAX_KEY_SZ + 1], *temp_ptr, *temp_key, util_buff[MAX_UTIL_LEN];
	unsigned char	cc;
	short int	size;
	int4		util_len, head;
	int		buf_len;
	block_id	blk_id;

	if (rp >= b_top)
		return NULL;
	head = cli_present("HEADER");
	GET_SHORT(size, &((rec_hdr_ptr_t)rp)->rsiz);
	cc = ((rec_hdr_ptr_t)rp)->cmpc;
	if ((CLI_NEGATED != head) && !patch_is_fdmp)
	{
		memcpy(util_buff, "Rec:", sizeof("Rec:") - 1);
		util_len = sizeof("Rec:") - 1;
		util_len += i2hex_nofill(patch_rec_counter, (uchar_ptr_t)&util_buff[util_len], 4);
		memcpy(&util_buff[util_len], "  Blk ", sizeof("  Blk ") - 1);
		util_len += sizeof("  Blk ") - 1;
		util_len += i2hex_nofill(blk, (uchar_ptr_t)&util_buff[util_len], 8);
		memcpy(&util_buff[util_len], "  Off ", sizeof("  Off ") - 1);
		util_len += sizeof("  Off ") - 1;
		util_len += i2hex_nofill(rp - bp, (uchar_ptr_t)&util_buff[util_len], 4);
		memcpy(&util_buff[util_len], "  Size ", sizeof("  Size ") - 1);
		util_len += sizeof("  Size ") - 1;
		util_len += i2hex_nofill(size, (uchar_ptr_t)&util_buff[util_len], 4);
		memcpy(&util_buff[util_len], "  Cmpc ", sizeof("  Cmpc ") - 1);
		util_len += sizeof("  Cmpc ") - 1;
		util_len += i2hex_nofill(cc, (uchar_ptr_t)&util_buff[util_len], 2);
		memcpy(&util_buff[util_len], "  ", sizeof("  ") - 1);
		util_len += sizeof("  ") - 1;
		util_buff[util_len] = 0;
		util_out_print(util_buff, FALSE);
	}
	r_top = rp + size;
	if (r_top > b_top)
		r_top = b_top;
	else  if (r_top < rp + sizeof(rec_hdr))
		r_top = rp + sizeof(rec_hdr);
	if (cc > patch_comp_count)
		cc = patch_comp_count;
	if (((blk_hdr_ptr_t)bp)->levl)
		key_top = r_top - sizeof(block_id);
	else
	{
		for (key_top = rp + sizeof(rec_hdr);  key_top < r_top;)
			if (!*key_top++ && !*key_top++)
				break;
	}
	size = key_top - rp - sizeof(rec_hdr);
	if (size < 0)
		size = 0;
	else  if (size > sizeof(patch_comp_key) - 2)
		size = sizeof(patch_comp_key) - 2;
	memcpy(&patch_comp_key[cc], rp + sizeof(rec_hdr), size);
	patch_comp_count = cc + size;
	patch_comp_key[patch_comp_count] = patch_comp_key[patch_comp_count + 1] = 0;
	if (patch_is_fdmp)
	{
		if (dse_fdmp(key_top, r_top - key_top))
			patch_fdmp_recs++;
	} else
	{
		if (r_top - sizeof(block_id) >= key_top)
		{
			GET_LONG(blk_id, key_top);
			if ((((blk_hdr_ptr_t)bp)->levl) || (blk_id <= cs_addrs->ti->total_blks))
			{
				memcpy(util_buff, "Ptr ", sizeof("Ptr ") - 1);
				util_len = sizeof("Ptr ") - 1;
				util_len += i2hex_nofill(blk_id, (uchar_ptr_t)&util_buff[util_len], sizeof(blk_id) * 2);
				memcpy(&util_buff[util_len], "  ", sizeof("  ") - 1);
				util_len += sizeof("  ") - 1;
				util_buff[util_len] = 0;
				util_out_print(util_buff, FALSE);
			}
		}
		util_out_print("Key ", FALSE);
		if (r_top == b_top
			&& ((blk_hdr_ptr_t)bp)->levl && !((rec_hdr_ptr_t)rp)->cmpc
			&& r_top - rp == sizeof(rec_hdr) + sizeof(block_id))
				util_out_print("*", FALSE);
		else  if (patch_comp_key[0])
		{
			util_out_print("^", FALSE);
			RETRIEVE_ROOT_VAL(patch_comp_key, key_buf, temp_ptr, temp_key, buf_len);
			INIT_ROOT_GVT(key_buf, buf_len, curr_gbl_root);
		}
		print_target((uchar_ptr_t)patch_comp_key);
		util_out_print(0, TRUE);
		if (CLI_PRESENT != head)
		{
			for (cptr0 = rp;  cptr0 < r_top;  cptr0 += 20)
			{
				if (util_interrupt)
				{
					/* return, rather than signal ERR_CTRLC so
					 * that the calling routine can deal with
					 * that signal and do the appropriate
					 * cleanup.
					 */
					return NULL;
				}

				util_len = 8;
				i2hex_blkfill(cptr0 - bp, (uchar_ptr_t)util_buff, 8);
				memcpy(&util_buff[util_len], " : |", sizeof(" : |") - 1 );
				util_len += sizeof(" : |") - 1;
				util_buff[util_len] = 0;
				util_out_print(util_buff, FALSE);
				for (cptr1 = cptr0;  cptr1 < (cptr0 + 20);  cptr1++)
				{
					if (wide_out)
					{
						if (cptr1 < r_top)
						{
							i2hex_blkfill(*(sm_uc_ptr_t)cptr1, (uchar_ptr_t)util_buff, 4);
							util_buff[4] = 0;
							util_out_print(util_buff, FALSE);
						} else
							util_out_print("    ", FALSE);
					} else
					{
						if (cptr1 < r_top)
						{
							i2hex_blkfill(*(sm_uc_ptr_t)cptr1, (uchar_ptr_t)util_buff, 3);
							util_buff[3] = 0;
							util_out_print(util_buff, FALSE);
						} else
							util_out_print("   ", FALSE);
					}
				}
				if (wide_out)
				{
					util_out_print("|    |", FALSE);
					for (cptr1 = cptr0;  cptr1 < (cptr0 + 20);  cptr1++)
					{
						if (cptr1 < r_top)
						{
							if (PRINTABLE(*(sm_uc_ptr_t)cptr1))
								util_out_print("!AD", FALSE, 1, cptr1);
							else
								util_out_print(".", FALSE);
						} else
							util_out_print(" ", FALSE);
					}
				} else
				{	util_out_print("|", TRUE);
					util_out_print("           |", FALSE);
					for (cptr1 = cptr0;  cptr1 < (cptr0 + 20);  cptr1++)
					{
						if (cptr1 < r_top)
						{
							if (PRINTABLE(*(sm_uc_ptr_t)cptr1))
								util_out_print("  !AD", FALSE, 1, cptr1);
							else
								util_out_print("  .", FALSE);
						}
						else
							util_out_print("   ", FALSE);
					}
				}
				util_out_print("|", TRUE);
			}
		}
		if (CLI_NEGATED != head)
			util_out_print(0, TRUE);
	}
	return (r_top == b_top) ? NULL : r_top;
}
コード例 #7
0
ファイル: mu_int_err.c プロジェクト: ChristyV/fis-gtm
void	mu_int_err(
		int err,
		boolean_t do_path,
		boolean_t do_range,
		unsigned char *bot,
		int has_bot,
		unsigned char *top,
		int has_top,
	      	unsigned int level)
{
	int		i, util_len;
	unsigned char	util_buff[MAX_UTIL_LEN];
	unsigned char 	span_key[MAX_KEY_SZ + 1];

	if (!mu_int_errknt)
		util_out_print("!/Block:Offset Level", TRUE);
	mu_int_errknt++;
	mu_int_plen--;
	util_len=0;
	MEMCPY_LIT(&util_buff[util_len], NEWLINE);
	util_len += SIZEOF(NEWLINE) - 1;
	i2hex_blkfill(mu_int_path[mu_int_plen], &util_buff[util_len], BLOCK_WINDOW);
	util_len += BLOCK_WINDOW;
	MEMCPY_LIT(&util_buff[util_len], TEXT1);	/* OFFSET_WINDOW + 1 spaces */
	util_len += SIZEOF(TEXT3) - 1;				/* Using TEXT1 to clear space? */
	i2hex_nofill(mu_int_offset[mu_int_plen], (uchar_ptr_t)&util_buff[util_len], OFFSET_WINDOW);
	util_len += OFFSET_WINDOW + 1;
	i2hex_blkfill(level, (uchar_ptr_t)&util_buff[util_len], LEVEL_WINDOW);
	util_len += LEVEL_WINDOW;
	MEMCPY_LIT(&util_buff[util_len], TEXT2);
	util_len += SIZEOF(TEXT2) - 1;
	util_buff[util_len] = 0;
	if(sndata->sn_type)
		gtm_putmsg(VARLSTCNT(5) err, 3, LEN_AND_STR((char*)util_buff),
				(SPAN_NODE == sndata->sn_type) ? (sndata->span_prev_blk + 2) : (sndata->span_blk_cnt));
	else
		gtm_putmsg(VARLSTCNT(4) err, 2, LEN_AND_STR((char*)util_buff));
	if (do_path)
	{
		if (!master_dir)
		{
			util_out_print("                   Directory Path:  ", FALSE);
			for (i = 0;  trees->path[i + 1];  i++)
			{
				util_len = i2hex_nofill(trees->path[i], (uchar_ptr_t)util_buff, BLOCK_WINDOW);
				MEMCPY_LIT(&util_buff[util_len], TEXT3);
				util_len += SIZEOF(TEXT3) - 1;
				util_len += i2hex_nofill(trees->offset[i], (uchar_ptr_t)&util_buff[util_len], OFFSET_WINDOW);
				MEMCPY_LIT(&util_buff[util_len], TEXT4);
				util_len += SIZEOF(TEXT4) - 1;
				util_buff[util_len] = 0;
				util_out_print((caddr_t)util_buff, FALSE);
			}
			util_len = i2hex_nofill(trees->path[i], (uchar_ptr_t)util_buff, BLOCK_WINDOW);
			MEMCPY_LIT(&util_buff[util_len], TEXT3);
			util_len += SIZEOF(TEXT3) - 1;
			util_len += i2hex_nofill(trees->offset[i], (uchar_ptr_t)&util_buff[util_len], OFFSET_WINDOW);
			util_buff[util_len] = 0;
			util_out_print((caddr_t)util_buff, TRUE);
			util_out_print("                   Path:  ", FALSE);
		} else
			util_out_print("                   Directory Path:  ", FALSE);
		for (i = 0;  i < mu_int_plen;  i++)
		{
			util_len = i2hex_nofill(mu_int_path[i], (uchar_ptr_t)util_buff, BLOCK_WINDOW);
			MEMCPY_LIT(&util_buff[util_len], TEXT3);
			util_len += SIZEOF(TEXT3) - 1;
			util_len += i2hex_nofill(mu_int_offset[i], (uchar_ptr_t)&util_buff[util_len], OFFSET_WINDOW);
			MEMCPY_LIT(&util_buff[util_len], TEXT4);
			util_len += SIZEOF(TEXT4) - 1;
			util_buff[util_len] = 0;
			util_out_print((caddr_t)util_buff, FALSE);
		}
		util_len = i2hex_nofill(mu_int_path[i], (uchar_ptr_t)util_buff, BLOCK_WINDOW);
		MEMCPY_LIT(&util_buff[util_len], TEXT3);
		util_len += SIZEOF(TEXT3) - 1;
		util_len += i2hex_nofill(mu_int_offset[i], (uchar_ptr_t)&util_buff[util_len], OFFSET_WINDOW);
		util_buff[util_len] = 0;
		util_out_print((caddr_t)util_buff, TRUE);
	}
	if (do_range && mu_int_err_ranges)
	{
		util_out_print("Keys from ", FALSE);
		if (has_bot)
		{
			util_out_print("^", FALSE);
			/* in the case bot is the leftmost key of the gvtree, it needs a second null to be a properly terminated
			 * real key for print_target. since it is a simple set, we unconditionally do it for every key */
			bot[has_bot] = 0;
			print_target(bot);
		} else
		{
			assert(master_dir);	/* for a global variable tree, we better have a non-zero begin key */
			util_out_print("^%", FALSE);
		}
		util_out_print(" to ", FALSE);
		if (has_top)
		{
			util_out_print("^", FALSE);
			print_target(top);
		} else
			util_out_print("the end", FALSE);
		util_out_print(" are suspect.", TRUE);
	}
	if (!level && sndata->sn_type)
	{
		if (1 == sndata->sn_type)
			util_out_print("Spanning Node ^", FALSE);
		else
			util_out_print("Spanning Node Chunk ^", FALSE);
		/* in the case bot is the leftmost key of the gvtree, it needs a second null to be a properly terminated
		 * real key for print_target. since it is a simple set, we unconditionally do it for every key
		 */
		sndata->span_node_buf[sndata->key_len] = 0;
		sndata->span_node_buf[sndata->key_len+1] = 0;
		print_target(sndata->span_node_buf);
		util_out_print(" is suspect.", TRUE);
	}
	return;
}
コード例 #8
0
int main( int argc, char *argv[])
{
   char cmdstr[80];
	int status, i;
	xbee_serial_t XBEE_SERPORT;
	target_t *target = NULL;

	memset( target_list, 0, sizeof target_list);

	parse_serial_arguments( argc, argv, &XBEE_SERPORT);

	// initialize the serial and device layer for this XBee device
	if (xbee_dev_init( &my_xbee, &XBEE_SERPORT, NULL, NULL))
	{
		printf( "Failed to initialize device.\n");
		return 0;
	}

	// replace ZDO cluster table with one that intercepts Device Annce messages
	sample_endpoints.zdo.cluster_table = zdo_clusters;

	// Initialize the WPAN layer of the XBee device driver.  This layer enables
	// endpoints and clusters, and is required for all ZigBee layers.
	xbee_wpan_init( &my_xbee, &sample_endpoints.zdo);

	// Initialize the AT Command layer for this XBee device and have the
	// driver query it for basic information (hardware version, firmware version,
	// serial number, IEEE address, etc.)
	xbee_cmd_init_device( &my_xbee);
	printf( "Waiting for driver to query the XBee device...\n");
	do {
		xbee_dev_tick( &my_xbee);
		status = xbee_cmd_query_status( &my_xbee);
	} while (status == -EBUSY);
	if (status)
	{
		printf( "Error %d waiting for query to complete.\n", status);
	}

	// report on the settings
	xbee_dev_dump_settings( &my_xbee, XBEE_DEV_DUMP_FLAG_DEFAULT);

	// set Profile ID for our Basic Client Cluster endpoint
	sample_endpoints.zcl.profile_id = profile_id;

   print_help();

   puts( "searching for Commissioning Servers");
	find_devices();

	while (1)
   {
      while (xbee_readline( cmdstr, sizeof cmdstr) == -EAGAIN)
      {
      	wpan_tick( &my_xbee.wpan_dev);
      }

		if (! strcmpi( cmdstr, "quit"))
      {
			return 0;
		}
		else if (! strcmpi( cmdstr, "help") || ! strcmp( cmdstr, "?"))
		{
			print_help();
		}
		else if (! strncmpi( cmdstr, "profile ", 8))
		{
			profile_id = strtoul( &cmdstr[8], NULL, 16);
			printf( "Profile ID set to 0x%04x\n", profile_id);
			sample_endpoints.zcl.profile_id = profile_id;
		}
		else if (! strcmpi( cmdstr, "find"))
		{
			find_devices();
		}
		else if (! strcmpi( cmdstr, "target"))
		{
			puts( " #: --IEEE Address--- Ver. --------Application Name--------"
				" ---Date Code----");
			for (i = 0; i < target_index; ++i)
			{
				print_target( i);
			}
			puts( "End of List");
		}
		else if (! strncmpi( cmdstr, "target ", 7))
		{
			i = (int) strtoul( &cmdstr[7], NULL, 10);
			if (target_index == 0)
			{
				printf( "error, no targets in list, starting search now...\n");
				find_devices();
			}
			else if (i < 0 || i >= target_index)
			{
				printf( "error, index %d is invalid (must be 0 to %u)\n", i,
					target_index - 1);
			}
			else
			{
				target = &target_list[i];
				puts( "set target to:");
				print_target( i);
			}
		}
		else if (! strcmpi( cmdstr, "save"))
		{
			restart_target( target, TRUE);
		}
		else if (! strcmpi( cmdstr, "cancel"))
		{
			restart_target( target, FALSE);
		}
		else if (! strcmpi( cmdstr, "default"))
		{
			default_target( target);
		}
		else if (! strcmpi( cmdstr, "deploy"))
		{
			set_pan( target, &network_deploy);
		}
		else if (! strncmpi( cmdstr, "deploy ", 7))
		{
			if (cmdstr[7] == 'r')
			{
				puts( "deploy as router");
				network_deploy.startup_control = ZCL_COMM_STARTUP_JOINED;
			}
			else if (cmdstr[7] == 'c')
			{
				puts( "deploy as coordinator");
				network_deploy.startup_control = ZCL_COMM_STARTUP_COORDINATOR;
			}
			set_pan( target, &network_deploy);
		}
		else if (! strcmpi( cmdstr, "comm"))
		{
			set_pan( target, &network_comm);
		}
		else if (! strncmpi( cmdstr, "AT", 2))
		{
			process_command( &my_xbee, &cmdstr[2]);
		}
	   else
	   {
	   	printf( "unknown command: '%s'\n", cmdstr);
	   }
   }
}
コード例 #9
0
ファイル: dump_record.c プロジェクト: CeperaCPP/fis-gtm
sm_uc_ptr_t  dump_record(sm_uc_ptr_t rp, block_id blk, sm_uc_ptr_t bp, sm_uc_ptr_t b_top)
{
	sm_uc_ptr_t	r_top, key_top, cptr0, cptr1, cptr_top, cptr_base = NULL, cptr_next = NULL;
	char		key_buf[MAX_KEY_SZ + 1], *temp_ptr, *temp_key, util_buff[MAX_UTIL_LEN];
	char		*prefix_str, *space_str, *dot_str, *format_str;
	unsigned char	cc;
	short int	size;
	int4		util_len, head;
	uint4 		ch;
	int		buf_len, field_width,fastate, chwidth = 0;
        ssize_t   	chlen;
	block_id	blk_id;
	boolean_t	rechdr_displayed = FALSE;
	sgmnt_addrs	*csa;

	if (rp >= b_top)
		return NULL;
	head = cli_present("HEADER");
	GET_SHORT(size, &((rec_hdr_ptr_t)rp)->rsiz);
	cc = ((rec_hdr_ptr_t)rp)->cmpc;
	if ((CLI_NEGATED != head) && !patch_is_fdmp)
	{
		MEMCPY_LIT(util_buff, "Rec:");
		util_len = SIZEOF("Rec:") - 1;
		util_len += i2hex_nofill(patch_rec_counter, (uchar_ptr_t)&util_buff[util_len], 4);
		MEMCPY_LIT(&util_buff[util_len], "  Blk ");
		util_len += SIZEOF("  Blk ") - 1;
		util_len += i2hex_nofill(blk, (uchar_ptr_t)&util_buff[util_len], 8);
		MEMCPY_LIT(&util_buff[util_len], "  Off ");
		util_len += SIZEOF("  Off ") - 1;
		util_len += i2hex_nofill((int)(rp - bp), (uchar_ptr_t)&util_buff[util_len], 4);
		MEMCPY_LIT(&util_buff[util_len], "  Size ");
		util_len += SIZEOF("  Size ") - 1;
		util_len += i2hex_nofill(size, (uchar_ptr_t)&util_buff[util_len], 4);
		MEMCPY_LIT(&util_buff[util_len], "  Cmpc ");
		util_len += SIZEOF("  Cmpc ") - 1;
		util_len += i2hex_nofill(cc, (uchar_ptr_t)&util_buff[util_len], 2);
		MEMCPY_LIT(&util_buff[util_len], "  ");
		util_len += SIZEOF("  ") - 1;
		util_buff[util_len] = 0;
		util_out_print(util_buff, FALSE);
	}
	r_top = rp + size;
	if (r_top > b_top)
		r_top = b_top;
	else  if (r_top < rp + SIZEOF(rec_hdr))
		r_top = rp + SIZEOF(rec_hdr);
	if (cc > patch_comp_count)
		cc = patch_comp_count;
	if (((blk_hdr_ptr_t)bp)->levl)
		key_top = r_top - SIZEOF(block_id);
	else
	{
		for (key_top = rp + SIZEOF(rec_hdr);  key_top < r_top;)
			if (!*key_top++ && !*key_top++)
				break;
	}
	size = key_top - rp - SIZEOF(rec_hdr);
	if (size > SIZEOF(patch_comp_key) - 2 - cc)
		size = SIZEOF(patch_comp_key) - 2 - cc;
	if (size < 0)
		size = 0;
	memcpy(&patch_comp_key[cc], rp + SIZEOF(rec_hdr), size);
	patch_comp_count = cc + size;
	patch_comp_key[patch_comp_count] = patch_comp_key[patch_comp_count + 1] = 0;
	if (patch_is_fdmp)
	{
		if (dse_fdmp(key_top, (int)(r_top - key_top)))
			patch_fdmp_recs++;
	} else
	{
		if (r_top - SIZEOF(block_id) >= key_top)
		{
			GET_LONG(blk_id, key_top);
			if ((((blk_hdr_ptr_t)bp)->levl) || (blk_id <= cs_addrs->ti->total_blks))
			{
				MEMCPY_LIT(util_buff, "Ptr ");
				util_len = SIZEOF("Ptr ") - 1;
				util_len += i2hex_nofill(blk_id, (uchar_ptr_t)&util_buff[util_len], SIZEOF(blk_id) * 2);
				MEMCPY_LIT(&util_buff[util_len], "  ");
				util_len += SIZEOF("  ") - 1;
				util_buff[util_len] = 0;
				util_out_print(util_buff, FALSE);
			}
		}
		util_out_print("Key ", FALSE);
		if (r_top == b_top
			&& ((blk_hdr_ptr_t)bp)->levl && !((rec_hdr_ptr_t)rp)->cmpc
			&& r_top - rp == SIZEOF(rec_hdr) + SIZEOF(block_id))
				util_out_print("*", FALSE);
		else  if (patch_comp_key[0])
		{
			util_out_print("^", FALSE);
			csa = cs_addrs;
			RETRIEVE_ROOT_VAL(patch_comp_key, key_buf, temp_ptr, temp_key, buf_len);
			INIT_ROOT_GVT(key_buf, buf_len, curr_gbl_root);
		}
		print_target((uchar_ptr_t)patch_comp_key);
		util_out_print(0, TRUE);
		if (CLI_PRESENT != head)
		{
			prefix_str = "           |";
			if (wide_out)
			{
				format_str = "   !AD";
				dot_str = "   .";
				space_str = "    ";
				field_width = 4;
			} else
			{
				format_str = "  !AD";
				dot_str = "  .";
				space_str = "   ";
				field_width = 3;
			}
			fastate = 0;
			for (cptr0 = rp;  cptr0 < r_top;  cptr0 += NUM_BYTES_PER_LINE)
			{
				if (util_interrupt)
				{ /* return, rather than signal ERR_CTRLC so that the calling routine
				     can deal with that signal and do the appropriate cleanup */
					return NULL;
				}
				util_len = 8;
				i2hex_blkfill((int)(cptr0 - bp), (uchar_ptr_t)util_buff, 8);
				MEMCPY_LIT(&util_buff[util_len], " : |");
				util_len += SIZEOF(" : |") - 1;
				util_buff[util_len] = 0;
				util_out_print(util_buff, FALSE);
				/* Dump hexadecimal byte values */
				for (cptr1 = cptr0;  cptr1 < (cptr0 + NUM_BYTES_PER_LINE);  cptr1++)
				{
					if (cptr1 < r_top)
					{
						i2hex_blkfill(*(sm_uc_ptr_t)cptr1, (uchar_ptr_t)util_buff, field_width);
						util_buff[field_width] = 0;
						util_out_print(util_buff, FALSE);
					} else
						util_out_print(space_str, FALSE);
				}
				util_out_print("|", TRUE);
				util_out_print(prefix_str, FALSE);
				/* Display character/wide-character glyphs */
				for (cptr1 = cptr0, cptr_top = cptr0 + NUM_BYTES_PER_LINE;  cptr1 < cptr_top;  cptr1++)
				{
					if (!rechdr_displayed && (cptr1 == (rp + SIZEOF(rec_hdr))))
						rechdr_displayed = TRUE;
					assert(rechdr_displayed || (cptr1 < (rp + SIZEOF(rec_hdr))));
					assert(!rechdr_displayed || (cptr1 >= (rp + SIZEOF(rec_hdr))));
					switch (fastate)
					{
					case 0: /* prints single-byte characters or intepret
						   multi-byte characters */
						if (cptr1 >= r_top)
							util_out_print(space_str, FALSE);
						else if (!gtm_utf8_mode || IS_ASCII(*cptr1) || !rechdr_displayed)
						{ /* single-byte characters */
							if (PRINTABLE(*(sm_uc_ptr_t)cptr1))
								util_out_print(format_str, FALSE, 1, cptr1);
							else
								util_out_print(dot_str, FALSE);
						}
#ifdef UNICODE_SUPPORTED
						else { /* multi-byte characters */
							cptr_next = UTF8_MBTOWC(cptr1, r_top, ch);
							chlen = cptr_next - cptr1;
							if (WEOF == ch || !U_ISPRINT(ch))
							{ /* illegal or non-printable characters */
								cptr1--;
								fastate = 1;
							} else
							{ /* multi-byte printable characters */
								cptr_base = cptr1;
								chwidth = UTF8_WCWIDTH(ch);
								assert(chwidth >= 0 && chwidth <= 2);
								cptr1--;
								fastate = 2;
							}
						}
#endif
						break;

					case 1: /* illegal or non-printable characters */
						util_out_print(dot_str, FALSE);
						if (--chlen <= 0)
							fastate = 0;
						break;

					case 2: /* printable multi-byte characters */
						if (chlen-- > 1) /* fill leading bytes with spaces */
							util_out_print(space_str, FALSE);
						else
						{
							util_out_print("!AD", FALSE, field_width - chwidth, space_str);
							if (0 < chwidth)
								util_out_print("!AD", FALSE, cptr_next - cptr_base, cptr_base);
							fastate = 0;
						}
						break;
					}
				}
				util_out_print("|", TRUE);
			}
		}
		if (CLI_NEGATED != head)
			util_out_print(0, TRUE);
	}
	return (r_top == b_top) ? NULL : r_top;
}
コード例 #10
0
int main( int argc, char *argv[])
{
    const char *firmware = NULL;
    char xmodem_buffer[69];
    char cmdstr[80];
    int status, i;
    xbee_serial_t XBEE_SERPORT;
    FILE *fw_file = NULL;
#ifdef VERBOSE
    uint16_t last_state;
#endif
    uint16_t last_packet;
    target_t *target = NULL;

    // turn off buffering so status changes (lines ending in \r) display
    setvbuf( stdout, NULL, _IONBF, 0);

    memset( target_list, 0, sizeof target_list);

    // set serial port
    parse_serial_arguments( argc, argv, &XBEE_SERPORT);

    // parse args for this program
    parse_args( argc, argv);

    // initialize the serial and device layer for this XBee device
    if (xbee_dev_init( &my_xbee, &XBEE_SERPORT, NULL, NULL))
    {
        printf( "Failed to initialize device.\n");
        return 0;
    }

    // Initialize the WPAN layer of the XBee device driver.  This layer enables
    // endpoints and clusters, and is required for all ZigBee layers.
    xbee_wpan_init( &my_xbee, &sample_endpoints.zdo);

    // Initialize the AT Command layer for this XBee device and have the
    // driver query it for basic information (hardware version, firmware version,
    // serial number, IEEE address, etc.)
    xbee_cmd_init_device( &my_xbee);
    printf( "Waiting for driver to query the XBee device...\n");
    do {
        xbee_dev_tick( &my_xbee);
        status = xbee_cmd_query_status( &my_xbee);
    } while (status == -EBUSY);
    if (status)
    {
        printf( "Error %d waiting for query to complete.\n", status);
    }

    // report on the settings
    xbee_dev_dump_settings( &my_xbee, XBEE_DEV_DUMP_FLAG_DEFAULT);

    print_help();

    if (dynamic_profile.profile_id != 0)
    {
        printf( "Using profile ID 0x%04x with%s APS encryption.\n",
                dynamic_profile.profile_id,
                (dynamic_profile.flags & WPAN_CLUST_FLAG_ENCRYPT) ? "" : "out");
        xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL);
    }

    while (1)
    {
        while (xbee_readline( cmdstr, sizeof cmdstr) == -EAGAIN)
        {
            wpan_tick( &my_xbee.wpan_dev);

            if (fw_file != NULL)
            {
                if (xbee_xmodem_tx_tick( &xbee_ota.xbxm) != 0)
                {
                    uint16_t timer;

                    printf( "upload complete     \n");
                    fclose( fw_file);
                    fw_file = NULL;

                    // wait one second for device to reboot then rediscover it
                    timer = XBEE_SET_TIMEOUT_MS(1000);
                    while (! XBEE_CHECK_TIMEOUT_MS( timer));

                    xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL);
                }

#ifdef VERBOSE
                if (last_state != xbee_ota.xbxm.state)
                {
                    printf( "state change from %u to %u\n", last_state,
                            xbee_ota.xbxm.state);
                    last_state = xbee_ota.xbxm.state;
                }
#endif
                if (last_packet != xbee_ota.xbxm.packet_num)
                {
#ifdef VERBOSE
                    printf( "packet #%u\n", xbee_ota.xbxm.packet_num);
#else
                    printf( " %" PRIu32 " bytes\r",
                            UINT32_C(64) * xbee_ota.xbxm.packet_num);
#endif
                    last_packet = xbee_ota.xbxm.packet_num;
                }
            }
        }

        if (! strcmpi( cmdstr, "quit"))
        {
            return 0;
        }
        else if (! strcmpi( cmdstr, "help") || ! strcmp( cmdstr, "?"))
        {
            print_help();
        }
        else if (! strcmpi( cmdstr, "find"))
        {
            if (dynamic_profile.profile_id == 0)
            {
                puts( "Error: specify a profile via cmd line or 'profile' cmd");
            }
            else
            {
                xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL);
            }
        }
        else if (! strncmpi( cmdstr, "profile ", 8))
        {
            dynamic_profile.profile_id = strtoul( &cmdstr[8], NULL, 16);
            printf( "Profile ID set to 0x%04x\n", dynamic_profile.profile_id);
            profile_changed();
        }
        else if (! strcmpi( cmdstr, "target"))
        {
            puts( " #: --IEEE Address--- Ver. --------Application Name--------"
                  " ---Date Code----");
            for (i = 0; i < target_index; ++i)
            {
                print_target( i);
            }
            puts( "End of List");
        }
        else if (! strncmpi( cmdstr, "target ", 7))
        {
            i = (int) strtoul( &cmdstr[7], NULL, 10);
            if (target_index == 0)
            {
                printf( "error, no targets in list, starting search now...\n");
                xbee_ota_find_devices( &my_xbee.wpan_dev, xbee_found, NULL);
            }
            else if (i < 0 || i >= target_index)
            {
                printf( "error, index %d is invalid (must be 0 to %u)\n", i,
                        target_index - 1);
            }
            else
            {
                target = &target_list[i];
                puts( "set target to:");
                print_target( i);
            }
        }
        else if (! strcmpi( cmdstr, "F") && target != NULL)
        {
            // If the target is stuck in the bootloader, send an 'F' to start
            // a firmware update.
            wpan_envelope_t envelope;

            wpan_envelope_create( &envelope, &my_xbee.wpan_dev, &target->ieee,
                                  WPAN_NET_ADDR_UNDEFINED);
            envelope.options = current_profile->flags;
            xbee_transparent_serial_str( &envelope, "F");
        }
        else if (! strcmpi( cmdstr, "firmware"))
        {
            firmware = get_file();
        }
        else if (! strcmpi( cmdstr, "password"))
        {
            set_password( "");
            puts( "cleared password (will use default of a single null byte)");
        }
        else if (! strncmpi( cmdstr, "password ", 9))
        {
            set_password( &cmdstr[9]);
            printf( "set password to [%.*s]\n", xbee_ota.auth_length,
                    xbee_ota.auth_data);
        }
        else if (! strcmpi( cmdstr, "aps"))
        {
            xbee_ota.flags ^= XBEE_OTA_FLAG_APS_ENCRYPT;
            printf( "APS encryption %sabled\n",
                    (xbee_ota.flags & XBEE_OTA_FLAG_APS_ENCRYPT) ? "en" : "dis");
        }
        else if (! strcmpi( cmdstr, "go"))
        {
            if (target == NULL)
            {
                if (target_index > 0)
                {
                    target = &target_list[0];
                }
                else
                {
                    puts( "no targets available to send to");
                    continue;
                }
            }

            if (firmware == NULL)
            {
                firmware = get_file();
                if (firmware == NULL)
                {
                    printf( "Canceled.\n");
                    continue;
                }
            }

            printf( "Starting xmodem upload of\n  %s\n", firmware);

            fw_file = fopen( firmware, "rb");
            if (! fw_file)
            {
                printf( "Failed to open '%s'\n", firmware);
                exit( -1);
            }

            status = xbee_ota_init( &xbee_ota, &my_xbee.wpan_dev, &target->ieee);

            if (status)
            {
                printf( "%s returned %d\n", "xbee_ota_init", status);
                continue;
            }

            status = xbee_xmodem_set_source( &xbee_ota.xbxm, xmodem_buffer,
                                             fw_read, fw_file);
            if (status)
            {
                printf( "%s returned %d\n", "xbee_xmodem_set_source", status);
                continue;
            }

            // reset the xbee_xmodem_state_t state machine, keeping existing flags
            status = xbee_xmodem_tx_init( &xbee_ota.xbxm, xbee_ota.xbxm.flags);
            if (status)
            {
                printf( "%s returned %d\n", "xbee_xmodem_tx_init", status);
                continue;
            }

            // reset copies of basic cluster -- need to refresh after update
            memset( &target->basic, 0, sizeof(target->basic));

#ifdef VERBOSE
            last_state = last_packet = 0;
#endif

            // main loop will tick the xmodem transfre until fw_file == NULL
        }
#ifdef XBEE_XMODEM_TESTING
        else if (! strcmpi( cmdstr, "ACK"))
        {
            xbee_ota.xbxm.flags |= XBEE_XMODEM_FLAG_DROP_ACK;
        }
        else if (! strcmpi( cmdstr, "FRAME"))
        {
            xbee_ota.xbxm.flags |= XBEE_XMODEM_FLAG_DROP_FRAME;
        }
        else if (! strcmpi( cmdstr, "CRC"))
        {
            xbee_ota.xbxm.flags |= XBEE_XMODEM_FLAG_BAD_CRC;
        }
#endif
        else if (! strncmpi( cmdstr, "AT", 2))
        {
            process_command( &my_xbee, &cmdstr[2]);
        }
        else
        {
            printf( "unknown command: '%s'\n", cmdstr);
        }
    }
}