⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set_mac.c

📁 Blob autotest. Used on xscale ( set_mac function)
💻 C
字号:
#include "socket_base.h"#define MAC_ADDR "00:11:22:33:44:66"char *next_cmd = "reboot";int main(int argc, char *argv[]){	//open network lclient	COMMANDPAR par1;	HTRANSINTERFACE cmdFile = NULL;	int result;	int ret = 0;	char cmdline[256];		par1.opMode=SOCKET_OP;	par1.socketAddr = malloc(30);	par1.socketAddr = "192.168.1.100:10086";	par1.endPoint = CLIENT;		if (par1.opMode == FILE_OP){		}else if (par1.opMode == SOCKET_OP){                cmdFile = OpenTransInterface(&par1);                if(cmdFile == NULL){                        fprintf(stderr, "Can not connect the server socket!\n");                        return -1;                }	}	printf("send commad:%s\n",next_cmd);		result  = SendPackage(next_cmd, 6, cmdFile);	if(result != 6){		printf("send problem\n");		ret = -1;		goto out1;	}	result = ReadPackage(cmdline, 4, cmdFile);//get the cmd	if(result != 4){		printf("read problem\n");		ret = -1;		goto out1;	}	printf("readpackage: %s\n", cmdline);	if (strncmp(cmdline, "Done",4) == 0)	{		printf("reboot success\n");	}			//finish reboot platform			COMMANDPAR par;	HTRANSINTERFACE handle;	int last_result;	int i;	char rbuf[4096], rbuf_save[256];	char *p_buf;	char *mac_buf;	char *wbuf = malloc(256);	char *macaddr = malloc(20);	memset(macaddr, 0,20);	mac_buf = macaddr;	memset(rbuf, 0, 4096);	memset(rbuf_save, 0, 256);	par.opMode = COMM_OP;	par.commAddr = malloc(30);	par.commAddr = "/dev/ttyS0";	par.baudrate = malloc(15);	par.baudrate = "B38400";	par.endPoint = SERVER;	handle = OpenTransInterface(&par);	if(handle == NULL){		printf("Open Transfer interface failed\n");		return -1;	} 	sleep(5);	printf("----Test platform can enter blob control interface----\n");	/* wait to enter blob command control interface*/	for (i=0; i<6; i++)	{		wbuf = " ";		result = SendPackage(wbuf, 1, handle);		if(result != 1){			printf("Send problem\n");			ret = -1;			goto out;		}		sleep(1);	}		printf("echo anykey successed\n");		result = ReadPackage(rbuf, 1024, handle, 1, 1);		printf("read %d bytes\n", result);		printf("read: %s\n", rbuf);		p_buf = rbuf;		for (i=0; i<result; i++)		{			if (strncmp(p_buf, "blob>",5) == 0)			{					printf("enter blob command control\n");				break;			}			p_buf++;			if(i >= result-1)			{				printf("can not enter blob command control\n");				ret = -1;				goto out;			}		}	printf("----set mac----\n");		/* test  download zImage to nandflash*//*		p_buf = wbuf;		p_buf = "setmac ";		p_buf += 7;		p_buf = MAC_ADDR;		p_buf += 17;		p_buf = "\n";*/		wbuf = "setmac 00-11-22-33-44-66\n";		result = SendPackage(wbuf, 25, handle);		if(result != 25){			printf("Send problem\n");			ret = -1;			goto out;		}		sleep(5);		wbuf = "setmac\n";		result = SendPackage(wbuf, 7, handle);		if(result != 7){			printf("Send problem\n");			ret = -1;			goto out;		}		sleep(2);		result = ReadPackage(rbuf, 4096, handle, 1, 10);		printf("read %d bytes\n", result);		printf("read: %s\n", rbuf);		p_buf = rbuf;		for (i=0; i<result; i++)		{			if (strncmp(p_buf, "current MAC:",12) == 0)			{					int j;				printf("get set MAC\n");				p_buf += 12;				for (j=0; j < 17; j++)				{					*mac_buf = *p_buf;					if(*mac_buf == '-')						*mac_buf = ':';					mac_buf++;					p_buf++;				}									if(strncmp(macaddr,MAC_ADDR,17) == 0)				{					printf("set mac addr via blob\n");				}				else				{					printf("Fail to set mac addr via blob\n");					goto out;				}				break;			}			p_buf++;			if(i == result-1)			{				printf("failed to set mac\n");				ret = -1;				goto out;			}		}		printf("----boot up system------\n");		wbuf = "nkernel\n";		result = SendPackage(wbuf, 8, handle);		if(result != 8){			printf("Send problem\n");			ret = -1;			goto out;		}		sleep(5);				result = ReadPackage(rbuf, 100, handle, 1, 5);		printf("read %d bytes\n", result);		printf("read: %s\n", rbuf);		p_buf = rbuf;		for (i=0; i<result; i++)		{			if (strncmp(p_buf, "blob>",5) == 0)			{					printf("load kernel from nandflash successfully\n");				break;			}			p_buf++;			if (i >= result - 1)			{				printf("failed to load kernel from nandflash\n");				ret = -1;				goto out;			}		}		wbuf = "boot\n";		result = SendPackage(wbuf, 5, handle);		if(result != 5){			printf("Send problem\n");			ret = -1;			goto out;		}				sleep(10);		printf("boot up system\n");				result = ReadPackage(rbuf, 4096, handle, 1, 10);			printf("read %d bytes\n", result);			printf("read: %s\n", rbuf);			p_buf = rbuf;		sleep(10);			result = ReadPackage(rbuf, 4096, handle, 1, 10);			printf("read %d bytes\n", result);			printf("read: %s\n", rbuf);			p_buf = rbuf;		sleep(10);			result = ReadPackage(rbuf, 4096, handle, 1, 10);			printf("read %d bytes\n", result);			printf("read: %s\n", rbuf);			p_buf = rbuf;		sleep(10);			result = ReadPackage(rbuf, 4096, handle, 1, 10);			printf("read %d bytes\n", result);			printf("read: %s\n", rbuf);			p_buf = rbuf;		sleep(20);			result = ReadPackage(rbuf, 4096, handle, 1, 10);			printf("read %d bytes\n", result);			printf("read: %s\n", rbuf);			p_buf = rbuf;		wbuf = "\n";		result = SendPackage(wbuf, 1, handle);		if(result != 1){			printf("Send problem\n");			ret = -1;			goto out;		}			printf("Send enter key to consel\n");		result = ReadPackage(rbuf, 1024, handle, 1, 10);		printf("read %d bytes\n", result);		printf("read: %s\n", rbuf);		p_buf = rbuf;		for (i=0; i<result; i++)		{			if (strncmp(p_buf, "root@Linux",10) == 0)			{					printf("system bootup from nandflash successfully\n");				break;			}			p_buf++;			if(i>result-1)			{				printf("failed to bootup system from nandflash\n");				ret = -1;				goto out;			}		}			wbuf = "ifconfig eth0\n";		result = SendPackage(wbuf, 14, handle);		if(result != 14){			printf("Send problem\n");			ret = -1;			goto out;		}		printf("use ifconfig to get hw address of eth0\n");		sleep(4);		result = ReadPackage(rbuf, 1024, handle, 1, 10);		printf("read %d bytes\n", result);		printf("read: %s\n", rbuf);		p_buf = rbuf;		for (i=0; i<result; i++)		{			if (strncmp(p_buf, "HWaddr",6) == 0)			{					printf("check eth0 mac\n");				p_buf += 7;				if(strncmp(p_buf,MAC_ADDR,17) == 0)					printf("set mac via blob successfully\n");				else				printf("set mac via blob failed. get hw addr is not equal to the mac set.\n");				break;			}			p_buf++;			if(i>result-1)			{				printf("failed to bootup system from nandflash\n");				ret = -1;				goto out;			}		}	printf("------------------------------------------------------------------\n");	printf("------------------------------------------------------------------\n");	printf("------------------------------------------------------------------\n");	printf("------------------------------------------------------------------\n");	out:	if(handle != NULL){		CloseTransInterface(handle);		}		out1:    if(cmdFile != NULL)                CloseTransInterface(cmdFile);	return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -