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

📄 prism2dl.c

📁 uClinux2.6上兼容PRISM2.0芯片组的USB设备驱动程序.
💻 C
📖 第 1 页 / 共 5 页
字号:
*                s - Size in words (little endian)*                t - Info type (little endian), see #defines and *                    s3inforec_t for details about types.*                d - (s - 1) little endian words giving the contents of*                    the given info type.** Arguments:*	fname	name of the s-record file to load** Returns: *	0	- success *	~0	- failure (probably an errno)----------------------------------------------------------------*/int read_srecfile(char *fname){	FILE*		f;	int		result = 0;	char		buf[SREC_LINE_MAX];	char		tmpbuf[30];	s3datarec_t	tmprec;	int		i;	int		line = 0;	UINT16		*tmpinfo;		printf("Reading S-record file %s...\n", fname);	if ( strcmp("stdin", fname) == 0 ) {		f = stdin;	} else {		f = fopen(fname, "r");		if ( f == NULL ) {			result=errno;			perror(APPNAME);			return result;		}	}	while ( fgets(buf, sizeof(buf), f) != NULL ) {		line++;		if ( buf[0] != 'S' ) {			fprintf(stderr,APPNAME":%s:%d warning: No initial \'S\'\n", fname, line);			fclose(f);			return 1;		}		if ( buf[1] == '7' ) {	/* S7 record, start address */			buf[12] = '\0';			startaddr = strtoul(buf+4, NULL, 16);			if (opt_verbose) {				printf( "  S7 start addr, line=%d "					" addr=0x%08lx\n", 					line, 					startaddr);			}//			break;			continue;		} else if ( buf[1] != '3') {			fprintf(stderr,APPNAME":%s:%d warning: Unknown S-record detected.\n", fname, line);			fclose(f);			return 1;		}		/* Ok, it's an S3, parse and put it in the right array */		/* Record Length field (we only want datalen) */		memcpy(tmpbuf, buf+S3LEN_TXTOFFSET, S3LEN_TXTLEN);		tmpbuf[S3LEN_TXTLEN] = '\0';		tmprec.len = strtoul( tmpbuf, NULL, 16) - 4 - 1; /* 4=addr, 1=cksum */		/* Address field */		memcpy(tmpbuf, buf+S3ADDR_TXTOFFSET, S3ADDR_TXTLEN);		tmpbuf[S3ADDR_TXTLEN] = '\0';		tmprec.addr = strtoul( tmpbuf, NULL, 16);		/* Checksum field */		tmprec.checksum = strtoul( buf+strlen(buf)-2, NULL, 16);		switch(  tmprec.addr )		{		case S3ADDR_PLUG:			memcpy(tmpbuf, buf+S3PLUG_ITEMCODE_TXTOFFSET, S3PLUG_ITEMCODE_TXTLEN);			tmpbuf[S3PLUG_ITEMCODE_TXTLEN] = '\0';			s3plug[ns3plug].itemcode = strtoul(tmpbuf,NULL,16);			s3plug[ns3plug].itemcode = bswap_32(s3plug[ns3plug].itemcode);			memcpy(tmpbuf, buf+S3PLUG_ADDR_TXTOFFSET, S3PLUG_ADDR_TXTLEN);			tmpbuf[S3PLUG_ADDR_TXTLEN] = '\0';			s3plug[ns3plug].addr = strtoul(tmpbuf,NULL,16);			s3plug[ns3plug].addr = bswap_32(s3plug[ns3plug].addr);			memcpy(tmpbuf, buf+S3PLUG_LEN_TXTOFFSET, S3PLUG_LEN_TXTLEN);			tmpbuf[S3PLUG_LEN_TXTLEN] = '\0';			s3plug[ns3plug].len = strtoul(tmpbuf,NULL,16);			s3plug[ns3plug].len = bswap_32(s3plug[ns3plug].len);			if (opt_verbose) {				printf( "  S3 plugrec, line=%d "					"itemcode=0x%04lx addr=0x%08lx len=%ld\n", 					line, 					s3plug[ns3plug].itemcode,					s3plug[ns3plug].addr,					s3plug[ns3plug].len);			}			ns3plug++;			break;		case S3ADDR_CRC:			memcpy(tmpbuf, buf+S3CRC_ADDR_TXTOFFSET, S3CRC_ADDR_TXTLEN);			tmpbuf[S3CRC_ADDR_TXTLEN] = '\0';			s3crc[ns3crc].addr = strtoul(tmpbuf,NULL,16);			s3crc[ns3crc].addr = bswap_32(s3crc[ns3crc].addr);			memcpy(tmpbuf, buf+S3CRC_LEN_TXTOFFSET, S3CRC_LEN_TXTLEN);			tmpbuf[S3CRC_LEN_TXTLEN] = '\0';			s3crc[ns3crc].len = strtoul(tmpbuf,NULL,16);			s3crc[ns3crc].len = bswap_32(s3crc[ns3crc].len);			memcpy(tmpbuf, buf+S3CRC_DOWRITE_TXTOFFSET, S3CRC_DOWRITE_TXTLEN);			tmpbuf[S3CRC_DOWRITE_TXTLEN] = '\0';			s3crc[ns3crc].dowrite = strtoul(tmpbuf,NULL,16);			s3crc[ns3crc].dowrite = bswap_32(s3crc[ns3crc].dowrite);			if (opt_verbose) {				printf( "  S3 crcrec, line=%d "					"addr=0x%08lx len=%ld write=0x%08x\n", 					line, 					s3crc[ns3crc].addr,					s3crc[ns3crc].len,					s3crc[ns3crc].dowrite);			}			ns3crc++;			break;		case S3ADDR_INFO:			memcpy(tmpbuf, buf+S3INFO_LEN_TXTOFFSET, S3INFO_LEN_TXTLEN);			tmpbuf[S3INFO_LEN_TXTLEN] = '\0';			s3info[ns3info].len = strtoul(tmpbuf,NULL,16);			s3info[ns3info].len = bswap_16(s3info[ns3info].len);			memcpy(tmpbuf, buf+S3INFO_TYPE_TXTOFFSET, S3INFO_TYPE_TXTLEN);			tmpbuf[S3INFO_TYPE_TXTLEN] = '\0';			s3info[ns3info].type = strtoul(tmpbuf,NULL,16);			s3info[ns3info].type = bswap_16(s3info[ns3info].type);			tmpinfo = (UINT16*)&(s3info[ns3info].info.version);			for (i = 0; i < s3info[ns3info].len - 1; i++) {				memcpy( tmpbuf, buf+S3INFO_DATA_TXTOFFSET+(i*4), 4);				tmpbuf[4] = '\0';				tmpinfo[i] = strtoul(tmpbuf,NULL,16);				tmpinfo[i] = bswap_16(tmpinfo[i]);			}			if (opt_verbose) {				printf( "  S3 inforec, line=%d "					"len=0x%04x type=0x%04x\n", 					line, 					s3info[ns3info].len,					s3info[ns3info].type);				printf( "            info=");				for (i = 0; i < s3info[ns3info].len - 1; i++) {					printf("%04x ", tmpinfo[i]);				}				printf("\n");			}			ns3info++;			break;		default:	/* Data record */			if (opt_verbose) {				printf("  S3 datarec, line=%04d addr=0x%08lx len=%03ld\n", 					line, tmprec.addr, tmprec.len);			}			s3data[ns3data].addr = tmprec.addr;			s3data[ns3data].len = tmprec.len;			s3data[ns3data].checksum = tmprec.checksum;			s3data[ns3data].data = malloc(tmprec.len);			for ( i = 0; i < tmprec.len; i++) {				memcpy(tmpbuf, buf+S3DATA_TXTOFFSET+(i*2), 2);				tmpbuf[2] = '\0';				s3data[ns3data].data[i] = strtoul(tmpbuf, NULL, 16);			}			ns3data++;			break;		}	}	return result;}/*----------------------------------------------------------------* str2macaddr* This function converts a character string that represents an* a 6 byte hex string to a 6 byte array.* The string format is: "xx:xx:xx:xx:xx:xx"** Arguments:*	a	- a six byte array*	s	- character string representing a mac address* Returns: *	0	success*	~0	detected a format error----------------------------------------------------------------*/int str2macaddr( UINT8 *a, char *s ){	char	*p;	int	i;	UINT	val;	for ( i = 0; i < 5; i++) {  /* loop over the number of :'s */		p = strchr( s, ':');		if ( p == NULL ) {			return 1;		} else {			*p = '\0';			sscanf( s, "%x", &val);			a[i] = (UINT8)val;			s = p+1;		}	}	sscanf( s, "%x", &val);	a[i] = (UINT8)val;	return 0;}/*----------------------------------------------------------------* s3datarec_compare** Comparison function for qsort().** Arguments:*	p1	ptr to the first item*	p2	ptr to the second item* Returns: *	0	items are equal*	<0	p1 < p2*	>0	p1 > p2----------------------------------------------------------------*/int s3datarec_compare(const void *p1, const void *p2) {	const s3datarec_t	*s1 = p1;	const s3datarec_t	*s2 = p2;	if ( s1->addr == s2->addr ) return 0;	if ( s1->addr < s2->addr ) return -1;	return 1;}/*----------------------------------------------------------------* usage** This function displays the proper command line syntax of this * utility.** Arguments:*	none** Returns:*	nothing----------------------------------------------------------------*/void usage(void){	printf("\n%s : 802.11 frame dump utility\n", appname);	printf("    usage: %s [option ...] devname\n\n", appname);	printf("       where valid options are:\n\n""  options:  (pnemonics in parentheses)\n""       GENERAL OPTIONS:\n""       -v          (verbose)  Show more status info during operation.\n""       -V          (Version)  Show version and exit\n""       -n          (nowrite)  Do all processing, including card PDA read, \n""                              but do not write to card.\n""       -d          (debug)    Do all processing, excluding card PDA read, \n""                              but do not write to card.  A valid interface \n""                              name is _not_ required for this mode.\n""       -s          (status)   Show CIS, PDA from card and exit\n""       -g          (generate) Show the PDA in a format readable by this \n""                              program.  Useful for saving the existing PDA\n""                              from a card.\n""\n""       IMAGEFILE OPTIONS:\n""       -r <file>   (ram)      Load SREC file to card RAM.  This option may\n""                              be specified multiple times.  If the value \n""                              is \"stdin\", the file will be read from \n""                              stdin and the option may only be specified once.\n""       -f <file>   (flash)    Load SREC file to card FLASH. This option may\n""                              be specified multiple times.  If the value \n""                              is \"stdin\", the file will be read from \n""                              stdin and the option may only be specified once.\n""\n""       PDA OPTIONS:\n""       -a <file>   (addpdr)   Add the PDRs from file to the PDA from card. This\n""                              option may be specified multiple times.\n""       -p <file>   (pda)      Replace the card PDA with the contents of file.\n""       -m <haddr>  (macaddr)  Overwrite the MAC address PDR with the given \n""                              value.  <addr> ::= xx:xx:xx:xx:xx:xx, where \n""                              xx is a two digit hex number.\n""       -S <str>    (Sernum)   Overwrite the serial number PDR with the given\n""                              string.  String must be <= 12 characters, any\n""                              extra will be truncated.\n""       -l <addr>   (pdaloc)   PDA location in card memory.  Commonly values:\n""                                 HFA3841 ==> 0x003f0000\n""                                 HFA3842 ==> 0x007f0000\n""\n""  argument:\n""  	devname    Linux device name (e.g. eth0, wlan0)\n""\n""EXAMPLES:\n""   Review card status:\n""     prism2dl -s wlan0\n""\n""   Load a new PDA:\n""     prism2dl -p pdafile.txt wlan0\n""       or\n""     prism2dl -p pdafile.txt -a pda1.txt -a pda2.txt wlan0\n""\n""     Note that the f/w images will most likely contain bogus plug info after\n""     rewriting the PDA by itself.  It is generally recommended to reload the \n""     primage and secondary images at the same time as modifying the PDA.\n""\n""   Load a FLASH image _and_ PDA:\n""     prism2dl -p pdafile.txt -f CIS.hex -f primary.hex -f secondary.hex wlan0\n""\n""   Load a RAM image:\n""     prism2dl -a pda1.txt -r tertiary.hex\n""\n""Note: PDA records are additive starting with the records from the card\n""      OR the records from the -p specified file.  -a specified file(s)\n""      overwrite, append, or remove records one at a time.  If multiple\n""      files are specified using the -a option, the files are processed\n""      from left to right.  This implies that a record removed from the\n""      current working PDA may then be added again by a record that\n""      appears after the \"remove\" record in the file set.\n\n");}/*----------------------------------------------------------------* writeimage** Takes the chunks, builds p80211 messages and sends them down* to the driver for writing to the card.** Arguments:*	fchunk		Array of image chunks*	nfchunks	Number of image chunks*	isflash		boolean indicating whether this is a*                       flash write or a ram write.** Returns: *	0	success*	~0	failure----------------------------------------------------------------*/int writeimage(imgchunk_t *fchunk, UINT nfchunks, int isflash){	int					result = 0;	p80211msg_p2req_flashdl_state_t		fstatemsg;	p80211msg_p2req_flashdl_write_t		fwritemsg;	p80211msg_p2req_ramdl_state_t		rstatemsg;	p80211msg_p2req_ramdl_write_t		rwritemsg;	p80211msg_t				*msgp;	UINT32					resultcode;	int					i;	int					j;	UINT					nwrites;	UINT32					curroff;	UINT32					currlen;	UINT32					currdaddr;	/* Initialize the messages */	memset(&fstatemsg, 0, sizeof(fstatemsg));	strcpy(fstatemsg.devname, devname);	fstatemsg.msgcode =		DIDmsg_p2req_flashdl_state;	fstatemsg.msglen =		sizeof(fstatemsg);	fstatemsg.enable.did =		DIDmsg_p2req_flashdl_state_enable;	fstatemsg.resultcode.did =	DIDmsg_p2req_flashdl_state_resultcode;	fstatemsg.enable.status =	P80211ENUM_msgitem_status_data_ok;	fstatemsg.resultcode.status =	P80211ENUM_msgitem_status_no_value;	fstatemsg.enable.len =		sizeof(UINT32);	fstatemsg.resultcode.len =	sizeof(UINT32);	memset(&fwritemsg, 0, sizeof(fwritemsg));	strcpy(fwritemsg.devname, devname);	fwritemsg.msgcode =		DIDmsg_p2req_flashdl_write;	fwritemsg.msglen =		sizeof(fwritemsg);	fwritemsg.addr.did =		DIDmsg_p2req_flashdl_write_addr;	fwritemsg.len.did =		DIDmsg_p2req_flashdl_write_len;	fwritemsg.data.did =		DIDmsg_p2req_flashdl_write_data;	fwritemsg.resultcode.did =	DIDmsg_p2req_flashdl_write_resultcode;	fwritemsg.addr.status =		P80211ENUM_msgitem_status_data_ok;	fwritemsg.len.status =		P80211ENUM_msgitem_status_data_ok;	fwritemsg.data.status =		P80211ENUM_msgitem_status_data_ok;	fwritemsg.resultcode.status =	P80211ENUM_msgitem_status_no_value;	fwritemsg.addr.len =		sizeof(UINT32);	fwritemsg.len.len =		sizeof(UINT32);	fwritemsg.data.len =		WRITESIZE_MAX;	fwritemsg.resultcode.len =	sizeof(UINT32);	memset(&rstatemsg, 0, sizeof(rstatemsg));	strcpy(rstatemsg.devname, devname);	rstatemsg.msgcode =		DIDmsg_p2req_ramdl_state;	rstatemsg.msglen =		sizeof(rstatemsg);	rstatemsg.enable.did =		DIDmsg_p2req_ramdl_state_enable;	rstatemsg.exeaddr.did =		DIDmsg_p2req_ramdl_state_exeaddr;	rstatemsg.resultcode.did =	DIDmsg_p2req_ramdl_state_resultcode;	rstatemsg.enable.status =	P80211ENUM_msgitem_status_data_ok;	rstatemsg.exeaddr.status =	P80211ENUM_msgitem_status_data_ok;	rstatemsg.resultcode.status =	P80211ENUM_msgitem_status_no_value;	rstatemsg.enable.len =		sizeof(UINT32);	rstatemsg.exeaddr.len =		sizeof(UINT32);	rstatemsg.resultcode.len =	sizeof(UINT32);	memset(&rwritemsg, 0, sizeof(rwritemsg));	strcpy(rwritemsg.devname, devname);	rwritemsg.msgcode =		DIDmsg_p2req_ramdl_write;	rwritemsg.msglen =		sizeof(rwritemsg);	rwritemsg.addr.did =		DIDmsg_p2req_ramdl_write_addr;	rwritemsg.len.did =		DIDmsg_p2req_ramdl_write_len;	rwritemsg.data.did =		DIDmsg_p2req_ramdl_write_data;	rwritemsg.resultcode.did =	DIDmsg_p2req_ramdl_write_resultcode;	rwritemsg.addr.status =		P80211ENUM_msgitem_status_data_ok;	rwritemsg.len.status =		P80211ENUM_msgitem_status_data_ok;	rwritemsg.data.status =		P80211ENUM_msgitem_status_data_ok;	rwritemsg.resultcode.status =	P80211ENUM_msgitem_status_no_value;	rwritemsg.addr.len =		sizeof(UINT32);	rwritemsg.len.len =		sizeof(UINT32);	rwritemsg.data.len =		WRITESIZE_MAX;	rwritemsg.resultcode.len =	sizeof(UINT32);	/* Send xxx_state(enable) */	if (opt_verbose) printf("Sending dl_state(enable) message.\n");	if ( isflash ) {		fstatemsg.enable.data = P80211ENUM_truth_true;	} else {		rstatemsg.enable.data = P80211ENUM_truth_true;		rstatemsg.exeaddr.data = startaddr;	}	if ( !opt_debug ) {		msgp = isflash ? (p80211msg_t*)&fstatemsg : (p80211msg_t*)&rstatemsg;		result = do_ioctl(msgp);		if ( result ) {			fprintf(stderr,APPNAME				": writeimage()->do_ioctl() failed w/ result=%d, "				"aborting download\n", result);			return result;		}		resultcode = isflash ? 				fstatemsg.resultcode.data : rstatemsg.resultcode.data;		if ( resultcode != P80211ENUM_resultcode_success ) {			fprintf(stderr,APPNAME				": writeimage()->xxxdl_state msg indicates failure, "				"w/ resultcode=%ld, a

⌨️ 快捷键说明

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