Exemple #1
0
/* end: 169.254.39.254, 0xfe27fea9 */
int gen_rpc_qcsapi_ip(void)
{
	int i;
	unsigned int j;
	unsigned char *hwaddr;
	char hwaddr_5g[18];
	struct ifreq ifr;
	struct in_addr start, addr;
	int hw_len;
	FILE *fp_qcsapi_conf;

	/* BRCM */
	ether_atoe(nvram_safe_get("lan_hwaddr"), (unsigned char *)&ifr.ifr_hwaddr.sa_data);
	for (j = 0, i = 0; i < 6; i++){
		j += ifr.ifr_hwaddr.sa_data[i] + (j << 6) + (j << 16) - j;
	}
	start.s_addr = htonl(ntohl(0x127fea9 /* start */) +
		((j + 0 /* c->addr_epoch */) % (1 + ntohl(0xfe27fea9 /* end */) - ntohl(0x127fea9 /* start */))));
	nvram_set("QTN_RPC_CLIENT", inet_ntoa(start));

	/* QTN */
	strcpy(hwaddr_5g, nvram_safe_get("lan_hwaddr"));
	inc_mac(hwaddr_5g, 4);
	ether_atoe(hwaddr_5g, (unsigned char *)&ifr.ifr_hwaddr.sa_data);
	for (j = 0, i = 0; i < 6; i++){
		j += ifr.ifr_hwaddr.sa_data[i] + (j << 6) + (j << 16) - j;
	}
	start.s_addr = htonl(ntohl(0x127fea9 /* start */) +
		((j + 0 /* c->addr_epoch */) % (1 + ntohl(0xfe27fea9 /* end */) - ntohl(0x127fea9 /* start */))));
	nvram_set("QTN_RPC_SERVER", inet_ntoa(start));
	if ((fp_qcsapi_conf = fopen("/etc/qcsapi_target_ip.conf", "w")) == NULL){
		logmessage("qcsapi", "write qcsapi conf error");
	}else{
		fprintf(fp_qcsapi_conf, "%s", nvram_safe_get("QTN_RPC_SERVER"));
		fclose(fp_qcsapi_conf);
		logmessage("qcsapi", "write qcsapi conf ok");
	}

#if 0
	do_ping_detect(); /* refer wanduck.c */
#endif
}
Exemple #2
0
int setMAC_5G_qtn(const char *mac)
{
	int ret;
	char cmd_l[64];
	char value[20] = {0};

	if( mac==NULL || !isValidMacAddr(mac) )
		return 0;

	if (!rpc_qtn_ready())
	{
		fprintf(stderr, "ATE command error\n");
		return -1;
	}
	ret = qcsapi_bootcfg_update_parameter("ethaddr", mac);
	if (ret < 0) {
		fprintf(stderr, "ATE command error\n");
		return -1;
	}
#if 0
	inc_mac(mac, 1);
#endif
	ret = qcsapi_bootcfg_update_parameter("wifiaddr", mac);
	if (ret < 0) {
		fprintf(stderr, "ATE command error\n");
		return -1;
	}
	ret = qcsapi_bootcfg_get_parameter("ethaddr", value, sizeof(value));
	if (ret < 0) {
		fprintf(stderr, "ATE command error\n");
		return -1;
	}

	memset(cmd_l, 0, 64);
	sprintf(cmd_l, "asuscfe1:macaddr=%s", mac);
	eval("nvram", "set", cmd_l );
	// puts(nvram_safe_get("1:macaddr"));

	puts(value);
	return 1;
}
/*
 * ATE get PLC password from MAC
 */
static int __getPLC_PWD(unsigned char *emac, char *pwd)
{
	FILE *fp;
	int len;
	char cmd[64], buf[32];

	inc_mac(2, emac);
	sprintf(cmd, "/usr/local/bin/mac2pw -q %02x%02x%02x%02x%02x%02x", emac[0], emac[1], emac[2], emac[3], emac[4], emac[5]);
	fp = popen(cmd, "r");
	if (fp) {
		len = fread(buf, 1, sizeof(buf), fp);
		pclose(fp);
		if (len > 1) {
			buf[len - 1] = '\0';
			strcpy(pwd, buf);
		}
		else
			return 0;
	}
	else
		return 0;

	return 1;
}