Ejemplo n.º 1
0
std::string Packet::text(
	const size_t start_bit,
	const size_t character_count
) const {
	std::string result;
	result.reserve(character_count);
	
	const size_t character_length = 6;
	const size_t end_bit = start_bit + character_count * character_length;
	for(size_t i=start_bit; i<end_bit; i+=character_length) {
		result += char_to_ascii(field_.read(i, character_length));
	} 

	return result;
}
Ejemplo n.º 2
0
static char *buffer_edit(char *buf, void (*func) (const char *p))
{
	int len, c;
	len = strlen(buf);
	if (func)
		prom_printf(buf);
	else {
		for (c = 0; c < len; c++)
			prom_printf("*");
	}

	for (;;) {
		c = prom_getchar();
		if (c == -1)
			break;
		if (char_is_newline(c))
			break;
		if (char_is_tab(c) && func)
			len = tabfunc(buf, len, func);
		else if (char_is_backspace(c)) {
			if (len > 0) {
				--len;
				buf[len] = 0;
				prom_printf("\b \b");
			}
		} else {
			c = char_to_ascii(c);
			if (c && len < CMD_LENG - 2) {
				buf[len] = c;
				buf[len + 1] = 0;
				if (func)
					prom_printf(buf + len);
				else
					prom_printf("*");
				len++;
			}
		}
	}

	buf[len] = 0;
	return buf;
}
Ejemplo n.º 3
0
static int
wl_scan(int unit)
{
	wl_scan_results_t *list = (wl_scan_results_t*)scan_result;
	wl_bss_info_t *bi;
	wl_bss_info_107_t *old_bi;
	uint i, ap_count = 0;
	char ssid_str[128], macstr[18];

	if (wl_get_scan_results(unit) == NULL)
		return 0;

	memset(ap_list, 0, sizeof(ap_list));
	if (list->count == 0)
		return 0;
	else if (list->version != WL_BSS_INFO_VERSION &&
			list->version != LEGACY_WL_BSS_INFO_VERSION &&
			list->version != LEGACY2_WL_BSS_INFO_VERSION) {
		/* fprintf(stderr, "Sorry, your driver has bss_info_version %d "
		    "but this program supports only version %d.\n",
		    list->version, WL_BSS_INFO_VERSION); */
		return 0;
	}

	bi = list->bss_info;
	for (i = 0; i < list->count; i++) {
		/* Convert version 107 to 109 */
		if (dtoh32(bi->version) == LEGACY_WL_BSS_INFO_VERSION) {
			old_bi = (wl_bss_info_107_t *)bi;
			bi->chanspec = CH20MHZ_CHSPEC(old_bi->channel);
			bi->ie_length = old_bi->ie_length;
			bi->ie_offset = sizeof(wl_bss_info_107_t);
		}

		if (bi->ie_length) {
			if (ap_count < WLC_MAX_AP_SCAN_LIST_LEN){
				ap_list[ap_count].used = TRUE;
				memcpy(ap_list[ap_count].BSSID, (uint8 *)&bi->BSSID, 6);
				strncpy((char *)ap_list[ap_count].ssid, (char *)bi->SSID, bi->SSID_len);
				ap_list[ap_count].ssid[bi->SSID_len] = '\0';
				ap_list[ap_count].ssidLen= bi->SSID_len;
				ap_list[ap_count].ie_buf = (uint8 *)(((uint8 *)bi) + bi->ie_offset);
				ap_list[ap_count].ie_buflen = bi->ie_length;
				ap_list[ap_count].channel = (uint8)(bi->chanspec & WL_CHANSPEC_CHAN_MASK);
				ap_list[ap_count].wep = bi->capability & DOT11_CAP_PRIVACY;
				ap_count++;
			}
		}
		bi = (wl_bss_info_t*)((int8*)bi + bi->length);
	}

	if (ap_count)
	{
		if (psta_debug)
		dbg("%-4s%-33s%-18s\n", "Ch", "SSID", "BSSID");

		for (i = 0; i < ap_count; i++)
		{
			memset(ssid_str, 0, sizeof(ssid_str));
			char_to_ascii(ssid_str, (const char *) trim_r(ap_list[i].ssid));

			ether_etoa((const unsigned char *) &ap_list[i].BSSID, macstr);
			if (psta_debug)
			dbg("%-4d%-33s%-18s\n",
				ap_list[i].channel,
				ap_list[i].ssid,
				macstr
			);
		}
	}

	return ap_count;
}
Ejemplo n.º 4
0
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

	if (strlen(nvram_wlan_get("wl", "ssid")) < 1)
		nvram_wlan_set("wl", "ssid", DEF_WLAN_5G_SSID);

	if (strlen(nvram_wlan_get("rt", "ssid")) < 1)
		nvram_wlan_set("rt", "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("wl", "ssid"));
	nvram_wlan_set("wl", "ssid2", buff);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("rt", "ssid"));
	nvram_wlan_set("rt", "ssid2", buff);

	if (strlen(nvram_safe_get("wl_wpa_mode")) < 1)
		nvram_set_int("wl_wpa_mode", 0);

	if (strlen(nvram_safe_get("wl_gmode")) < 1)
		nvram_set_int("wl_gmode", 2); // a/n Mixed

	if (strlen(nvram_safe_get("rt_gmode")) < 1)
		nvram_set_int("rt_gmode", 2); // b/g/n Mixed

	if (nvram_get_int("wl_HT_BW") > 1)
		nvram_set_int("wl_HT_BW", 1);

	if (nvram_get_int("rt_HT_BW") > 1)
		nvram_set_int("rt_HT_BW", 1);

	if (nvram_get_int("wl_stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_set_int("wl_stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_get_int("wl_stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_set_int("wl_stream_rx", BOARD_NUM_ANT_5G_RX);

	if (nvram_get_int("rt_stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_set_int("rt_stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_get_int("rt_stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_set_int("rt_stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("viptv_ifname", "");

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
Ejemplo n.º 5
0
// format : [Band, SSID, channel, security, encryption, RSSI, MAC, 802.11xx, hidden]
void show_ap_properties(const qcsapi_unsigned_int index, const qcsapi_ap_properties *params, char *buff)
{
	int channel 	= params->ap_channel;
	int wpa_mask	= params->ap_protocol;
	int psk_mask	= params->ap_authentication_mode;
	int tkip_mask	= params->ap_encryption_modes;
	int proto 	= params->ap_80211_proto;
	int hidden;
	char band[8], ssid[256], security[32], auth[16], crypto[32], wmode[8];
	char mac[24];

	// MAC
	sprintf(&mac[0], "%02X:%02X:%02X:%02X:%02X:%02X", 
		params->ap_mac_addr[0],
		params->ap_mac_addr[1],
		params->ap_mac_addr[2],
		params->ap_mac_addr[3],
		params->ap_mac_addr[4],
		params->ap_mac_addr[5]
	);

	// Band
	if(channel > 15)
		strcpy(band, "5G");
	else
		strcpy(band, "2G");

	// SSID
	if(!strcmp(params->ap_name_SSID, ""))
		strcpy(ssid, "");
	else{	
		memset(ssid, 0, sizeof(ssid));
		char_to_ascii(ssid, params->ap_name_SSID);
	}

	// security and authentication : check wpa_mask and psk_mask
	// 	wpa_mask : 0x01 = WPA, 0x02 = WPA2
	// 	psk_mask : 0x01 = psk, 0x02 = enterprise
	if((wpa_mask == 0x1) && (psk_mask == 0x01)){
		strcpy(security, "WPA-Personal");
		strcpy(auth, "PSK");
	}
	else if((wpa_mask == 0x2) && (psk_mask == 0x01)){
		strcpy(security, "WPA2-Personal");
		strcpy(auth, "PSK");
	}
	else if((wpa_mask == 0x3) && (psk_mask == 0x01)){
		strcpy(security, "WPA-Auto-Personal");
		strcpy(auth, "PSK");
	}
	else if((wpa_mask == 0x0) && (psk_mask == 0x0)){
		strcpy(security, "Open System");
		strcpy(auth, "NONE");
	}
	else{
		strcpy(security, "");
		strcpy(auth, "");
	}
		
	// encryption : check tkip_mask
	// 	tkip_mask : 0x01 = tkip, 0x02 = aes, 0x03 = tkip+aes
	if(tkip_mask == 0x01)
		strcpy(crypto, "TKIP");
	else if(tkip_mask == 0x02)
		strcpy(crypto, "AES");
	else if(tkip_mask == 0x03)
		strcpy(crypto, "TKIP+AES");
	else
		strcpy(crypto, "NONE");

	// Wmode : b/a/an/bg/bgn
	// 0x01 : b
	// 0x02 : g
	// 0x04 : a
	// 0x08 : n
	if(proto == 0x01)
		strcpy(wmode, "b");
	else if(proto == 0x04)
		strcpy(wmode, "a");
	else if(proto == 0x0C)
		strcpy(wmode, "an");
	else if(proto == 0x03)
		strcpy(wmode, "bg");
	else if(proto == 0x0B)
		strcpy(wmode, "bgn");
	else if(proto == 0x1C)
		strcpy(wmode, "ac");
	else{
		strcpy(wmode, "");
		fprintf(stderr, "[%s][%d]dp: [%d]\n", __FUNCTION__, __LINE__, proto);
	}

	// hidden SSID : if get MAC but not get SSID, it should be a hidden SSID
	if((&mac[0] != NULL) && !strcmp(params->ap_name_SSID, ""))
		hidden = 1;
	else if((&mac[0] != NULL) && !strcmp(params->ap_name_SSID, ""))
		hidden = 0;
	else
		hidden = 0;

#if 0
	dbg("band=%s,SSID=%s,channel=%d,security=%s,crypto=%s,RSSI=%d,MAC=%s,wmode=%s,hidden=%d\n", 
		band, ssid, params->ap_channel, security, crypto, params->ap_RSSI, &mac[0], wmode, hidden);
#endif

	sprintf(buff, "\"%s\",\"%s\",\"%d\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\",\"%d\"", 
		band, ssid, params->ap_channel, security, crypto, params->ap_RSSI, &mac[0], wmode, hidden);
}
Ejemplo n.º 6
0
Archivo: rc.c Proyecto: ff94315/rt-n56u
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;
#if defined (BOARD_GPIO_BTN_ROUTER)
	int i_router_switch = BTN_PRESSED;

	if (cpu_gpio_get_pin(BOARD_GPIO_BTN_ROUTER, &i_router_switch) >= 0) {
		if (i_router_switch != BTN_PRESSED)
			nvram_set_int("sw_mode", 3);
	}
#endif

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		sw_mode = 1;
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

#if defined (BOARD_GPIO_LED_ROUTER)
	if (sw_mode != 3)
		LED_CONTROL(BOARD_GPIO_LED_ROUTER, LED_ON);
#endif

#if BOARD_HAS_5G_RADIO
	if (strlen(nvram_wlan_get(1, "ssid")) < 1)
		nvram_wlan_set(1, "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(1, "ssid"));
	nvram_wlan_set(1, "ssid2", buff);

	if (strlen(nvram_wlan_get(1, "wpa_mode")) < 1)
		nvram_wlan_set_int(1, "wpa_mode", 0);

#if BOARD_HAS_5G_11AC
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 4); // a/n/ac Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 2)
		nvram_wlan_set_int(1, "HT_BW", 2);
#else
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 2); // a/n Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 1)
		nvram_wlan_set_int(1, "HT_BW", 1);
#endif

	if (nvram_wlan_get_int(1, "stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_wlan_set_int(1, "stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_wlan_get_int(1, "stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_wlan_set_int(1, "stream_rx", BOARD_NUM_ANT_5G_RX);
#endif

	if (strlen(nvram_wlan_get(0, "ssid")) < 1)
		nvram_wlan_set(0, "ssid", DEF_WLAN_2G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(0, "ssid"));
	nvram_wlan_set(0, "ssid2", buff);

	if (strlen(nvram_wlan_get(0, "gmode")) < 1)
		nvram_wlan_set_int(0, "gmode", 2); // b/g/n Mixed

	if (nvram_wlan_get_int(0, "HT_BW") > 1)
		nvram_wlan_set_int(0, "HT_BW", 1);

	if (nvram_wlan_get_int(0, "stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_wlan_set_int(0, "stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_wlan_get_int(0, "stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_wlan_set_int(0, "stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("vpnc_dom_t", "");
	nvram_set_temp("viptv_ifname", "");

	nvram_set_temp(RSTATS_NVKEY_24, (sw_mode != 3) ? IFDESC_WAN : IFDESC_LAN);
	nvram_set_temp(RSTATS_NVKEY_DM, IFDESC_WAN);

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
int wext_get_scanlist(const char *ifname, char *buf, int *len)
{
	//-----------------
	int retval = 0;		//返回值
	int i = 0;			
	int apCount = 0;	// 搜索到的AP数量
	char data[8192];	// *未知
	char ssid_str[256];	// ssid 名字?
	char header[128];	// *未知
	struct iwreq wrq;	// 创建ioctl
	SSA *ssap;			// SITE_SURVEY 数组
	char tmp[128];		// *未知 (好像没用)
	char prefix[] = "wlXXXXXXXXXX_"	// *未知
	memset(data, 0x00, 255);
	strcpy(data, "SiteSurvey=1");	// *应该是发出的指令
	wrq.u.data.length = strlen(data) + 1;
	wrq.u.data.pointer = data;
	wrq.u.data.flags = 0;
	
	if (wl_ioctl(ifname, RTPRIV_IOCTL_SET, &wrq) < 0)	// iwpriv ra0 set SiteSurvey=1
	{
		spinlock_unlock(0);			// 是专为防止多处理器并发而引入的一种锁。
		dbg("Site Survey fails\n");
		return 0;
	}
	
	spinlock_unlock(SPINLOCK_SiteSurvey);	// 是专为防止多处理器并发而引入的一种锁。
	sleep(5);
	
	memset(data, 0, 8192);
	strcpy(data, "");
	wrq.u.data.length = sizeof(data);
	wrq.u.data.pointer = data;
	wrq.u.data.flags = 0;
	if (wl_ioctl(ifname, RTPRIV_IOCTL_GSITESURVEY, &wrq) < 0) // iwpriv ra0 get_site_survey
	{
		dbg("errors in getting site survey result\n");
		return 0;
	}
	memset(header, 0, sizeof(header));
	if (wrq.u.data.length > 0)
	{
		// 这里应该是已经得到了扫描的结果
		ssap=(SSA *)(wrq.u.data.pointer+strlen(header)+1);
		int len = strlen(wrq.u.data.pointer+strlen(header))-1;
		char *sp, *op;
 		op = sp = wrq.u.data.pointer+strlen(header)+1;
		while (*sp && ((len - (sp-op)) >= 0))
		{
			// 这一部分应该是RT-41U 用于显示字符串的部分,应该是可以删除掉这部分代码的吧。
			ssap->SiteSurvey[i].channel[3] = '\0';
			ssap->SiteSurvey[i].ssid[32] = '\0';
			ssap->SiteSurvey[i].bssid[17] = '\0';
			ssap->SiteSurvey[i].encryption[8] = '\0';
			ssap->SiteSurvey[i].authmode[15] = '\0';
			ssap->SiteSurvey[i].signal[8] = '\0';
			ssap->SiteSurvey[i].wmode[7] = '\0';
			sp+=strlen(header);
			apCount=++i;
		}
		
		if (apCount)
		{
			retval += websWrite(wp, "[");
			for (i = 0; i < apCount; i++)
			{
				dbg("%-4s%-33s%-18s%-9s%-16s%-9s%-8s\n",
					ssap->SiteSurvey[i].channel,
					(char*)ssap->SiteSurvey[i].ssid,
					ssap->SiteSurvey[i].bssid,
					ssap->SiteSurvey[i].encryption,
					ssap->SiteSurvey[i].authmode,
					ssap->SiteSurvey[i].signal,
					ssap->SiteSurvey[i].wmode
				);
				
				memset(ssid_str, 0, sizeof(ssid_str));
				char_to_ascii(ssid_str, trim_r(ssap->SiteSurvey[i].ssid));
			}
		}
	}
	//------------------

	return -1;
}
Ejemplo n.º 8
0
int main(void)
    // The program's main entry point.  The program does a trivial 
    // mDNS query, looking for mDNS service & device in the local domain.
{
    	int     result;
    	mStatus     status;
    	DNSQuestion question;
    	domainname  type;
    	domainname  domain;
	char DeviceName[64];

    	// Initialise the mDNS core.
	status = mDNS_Init(&mDNSStorage, &PlatformStorage,
    	gRRCache, RR_CACHE_SIZE,
    	mDNS_Init_DontAdvertiseLocalAddresses,
    	mDNS_Init_NoInitCallback, mDNS_Init_NoInitCallbackContext);

    if (status == mStatus_NoError) {
#if 1 /* Query service type */
        // Construct and start the query.
        MakeDomainNameFromDNSNameString(&type, gServiceType);
        MakeDomainNameFromDNSNameString(&domain, gServiceDomain);

        status = mDNS_StartBrowse(&mDNSStorage, &question, &type, &domain, mDNSInterface_Any, mDNSfalse, BrowseCallback, NULL);
    
	//return;
        // Run the platform main event loop. 
        // The BrowseCallback routine is responsible for printing 
        // any results that we find.
        
        if (status == mStatus_NoError) {
            	fprintf(stderr, "* Query: %s\n", gServiceType);
        	EventLoop(&mDNSStorage);
            	mDNS_StopQuery(&mDNSStorage, &question);
                //Parse all service type and query detail
                //fprintf(stderr, "===== Parse all service type and query detail...\n");
                callback = 0;
                event = 0;
		StopNow = 0;
	}
	return 0;
#endif

#if 0 /* Query device name */
		Service_tmp = Service_list;
		while(Service_tmp!=NULL) {
			printf("\n======= Queried Service: %s.%s\n", Service_tmp->service, Service_tmp->type);
			sprintf(Query_type, "%s.%s", Service_tmp->service, Service_tmp->type);
			//Device_found = Service_tmp->sup_device;
			gServiceType = Query_type;
			MakeDomainNameFromDNSNameString(&type, gServiceType);
			status = mDNS_StartBrowse(&mDNSStorage, &question, &type, &domain, mDNSInterface_Any, mDNSfalse, QueryCallback, NULL);
			if (status == mStatus_NoError) {
		                EventLoop(&mDNSStorage);
        		        mDNS_StopQuery(&mDNSStorage, &question);
			}
                        callback = 0;
                        event = 0;
                        StopNow = 0;
                        Service_tmp = Service_tmp->next;
                }
		printf("===============\n\n");
#endif

#if 0 /* Query IP of device */
		DeviceIP_cur = Device_list;
		printf("%d,%d,%d  ", callback, event, StopNow);
		printf("QUERY DEVICE: %s/%s\n", Device_cur->name, Device_cur->IPv4Addr);
		char *cc = Device_cur->IPv4Addr;
		int x =0;
		for(; x<16; x++) {
			printf("%",*cc);
			cc++;
		}
		printf("\n");
		//if(DeviceIP_cur->IPv4Addr == NULL)
		if(!strcmp(DeviceIP_cur->IPv4Addr, ""))
			printf("    DeviceIP_cur->IPv4Addr == NULL\n");

		while(DeviceIP_cur && (!strcmp(DeviceIP_cur->IPv4Addr, ""))) {
			memset(DeviceName, 0, 64);
			strcpy(DeviceName, DeviceIP_cur->name);
			HostnameParse(DeviceName);
			gServiceType = DeviceName;
        		printf("Query IP of %s\n", gServiceType);
		        // Construct and start the query.
		       	MakeDomainNameFromDNSNameString(&type, gServiceType);
		        status = mDNS_GetAddrInfo(&mDNSStorage, &question, &type, &domain, mDNSInterface_Any, mDNSfalse, IPInfoCallback, NULL);
		        if (status == mStatus_NoError) {
		       	        EventLoop(&mDNSStorage);
                		mDNS_StopQuery(&mDNSStorage, &question);
		        }
			else {
				printf("Error= %ld\n", status);
			}
			DeviceIP_cur = DeviceIP_cur->next;
        	               callback = 0;
                        event = 0;
                       	StopNow = 0;
		}

		printf("===============\n");
#endif
int nvram_size, i = 0;
char *nvram_info;
char device_name_ascii[256], service_type_list[512];
struct mDNS_service_handler *handler;

nvram_size = device_count*64 + service_count*4;
nvram_info = malloc(nvram_size);
memset(nvram_info, 0, nvram_size);
printf("nvram_size= %d\n", nvram_size);

    	//Print all info
    	Service_tmp = Service_list;
    	while(Service_tmp!=NULL) {
		printf("\n=== %s.%s ===\n", Service_tmp->service, Service_tmp->type);
		Service_tmp = Service_tmp->next;
    	}

printf("\n===== Print device ========\n");
        Device_tmp = Device_list;
        while(Device_tmp!=NULL) {
                //printf("    %s:%s->", Device_tmp->name, Device_tmp->IPv4Addr);
		memset(device_name_ascii, 0, 256);
		char_to_ascii(device_name_ascii, Device_tmp->name);
		strcat(nvram_info, "<");
		sprintf(nvram_info, "%s%s>%s>", nvram_info, Device_tmp->IPv4Addr, device_name_ascii);
printf("    %s\n", nvram_info);
		Sup_service_tmp = Device_tmp->sup_service;
		memset(service_type_list, 0, 512);
		while(Sup_service_tmp!=NULL) {
			for(handler = &service_handler[0], i=0; handler->service; handler++, i++) {
				if(strstr(Sup_service_tmp->name, handler->service)) {
					sprintf(service_type_list, "%s#%d", service_type_list, i);
					break;
				}	
			}

			printf("%s ", Sup_service_tmp->name);
			Sup_service_tmp = Sup_service_tmp->next;
		}
		printf("\n");
		printf("Service_type= %s\n", service_type_list);
		sprintf(nvram_info, "%s%s", nvram_info, service_type_list);
printf("-> %s\n", nvram_info);
                Device_tmp = Device_tmp->next;
        }
	printf("\n==> %s\n", nvram_info);

	free(nvram_info);
	mDNS_Close(&mDNSStorage);
    }//Endof Initialise the mDNS core.
    
    if (status == mStatus_NoError) {
        result = 0;
    } else {
        result = 2;
    }
    if ( (result != 0) || (gMDNSPlatformPosixVerboseLevel > 0) ) {
        fprintf(stderr, "%s: Finished with status %d, result %d\n", gProgramName, (int)status, result);
    }

    return 0;
}