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

📄 prism2dl.c

📁 uClinux2.6上兼容PRISM2.0芯片组的USB设备驱动程序.
💻 C
📖 第 1 页 / 共 5 页
字号:
				fprintf(stderr,APPNAME": too many RAM files on cmd line. Exiting.\n");				exit(1);			}			strncpy(rfname[opt_ramloadcnt], optarg, FILENAME_MAX);			opt_ramloadcnt++;			break;		case 'f':			/* Flash image filename, add to list */			if ( opt_flashloadcnt >= FLASHFILES_MAX ) {				fprintf(stderr,APPNAME": too many FLASH files on cmd line. Exiting.\n");				exit(1);			}			strncpy(ffname[opt_flashloadcnt], optarg, FILENAME_MAX);			opt_flashloadcnt++;			break;		case 'a':			/* Flash image filename, add to list */			if ( opt_addpdrcnt >= ADDPDRFILES_MAX ) {				fprintf(stderr,APPNAME": too many ADDPDR files on cmd line. Exiting.\n");				exit(1);			}			strncpy(addpdrfname[opt_addpdrcnt], optarg, FILENAME_MAX);			opt_addpdrcnt++;			break;		case 'p':			/* New PDA filename */			if ( opt_newpda ) {				fprintf(stderr,APPNAME": -p specified more than once. Exiting.\n");				exit(1);			}			opt_newpda = 1;			strncpy(newpdafname, optarg, FILENAME_MAX);			break;		case 'l':			opt_pdaloc = strtoul(optarg, NULL, 0);			break;		case 'm':			/* cmdline MAC address */			if ( opt_macaddr ) {				fprintf(stderr,APPNAME": -m specified more than once. Exiting.\n");				exit(1);			}			if ( str2macaddr(macaddr, optarg) != 0 ) {				fprintf(stderr,APPNAME": mac address format error. Exiting.\n");				exit(1);			}			opt_macaddr = 1;			break;		case 'S':			/* cmdline Serial number */			if ( opt_sernum ) {				fprintf(stderr,APPNAME": -S specified more than once. Exiting.\n");				exit(1);			}			strncpy( sernum, optarg, SERNUM_LEN_MAX);			opt_sernum = 1;			break;		default:			fprintf(stderr,APPNAME": unrecognized option -%c.\n", optch);			usage();			return -1;			break;		}	}	/* check for options that are mutually exclusive */	if ( opt_debug && opt_nowrite ) {		fprintf(stderr,APPNAME": -n and -d are mutually exclusive. Exiting.\n");		exit(1);	}	/*-----------------------------------------------------*/	/* if we made it this far, the options must be pretty much OK */	/* save the interface name */	if ( optind >= argc && !opt_debug ) {		/* we're missing the interface argument */		fprintf(stderr, APPNAME": missing argument - devname\n");		usage();		return -1;	} else if (!opt_debug) {		/* save the interface name */		strncpy( devname, argv[optind], sizeof(devname) );	}	/*-----------------------------------------------------*/	/* Build the PDA we're going to use. */	pda_changed = 0;	if ( !opt_newpda && !opt_debug ) { /* read pda from card */		if (read_cardpda(&pda, devname)) {			fprintf(stderr,"load_cardpda failed, exiting.\n");			exit(1);		}		if ( opt_status && opt_addpdrcnt) { /* print note about pda */			printf( "Card PDA prior to file generated "				"modifications:\n");		}	} else if ( opt_newpda ){ /* read pda from file */		pda_changed = 1;		read_filepda(&pda, newpdafname);		if  (opt_status && opt_addpdrcnt) {			printf( "File PDA prior to file generated "				"modifications:\n");		}	}	/* read the card's PRI-SUP */	if (!opt_debug) {		p80211msg_dot11req_mibget_t getmsg;		p80211itemd_t *item;		UINT32        *data;		memset(&getmsg, 0, sizeof(getmsg));		getmsg.msgcode = DIDmsg_dot11req_mibget;		getmsg.msglen = sizeof(getmsg);		strcpy(getmsg.devname, devname);		getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;		getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;		getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;		getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;		item = (p80211itemd_t *) getmsg.mibattribute.data;		item->did = DIDmib_p2_p2NIC_p2PRISupRange;		item->status = P80211ENUM_msgitem_status_no_value;				data = (UINT32*) item->data;		do_ioctl((p80211msg_t*)&getmsg);		if (getmsg.resultcode.data != P80211ENUM_resultcode_success) {			printf("Couldn't fetch PRI-SUP info\n");		}		/* Already in host order */		priid.role = *data++;		priid.id = *data++;		priid.variant = *data++;		priid.bottom = *data++;		priid.top = *data++;	}	/* If the MAC address is specified it should overwrite the         * current value. 	 */	if ( opt_macaddr ) {		const unsigned nwords = WLAN_ADDR_LEN/sizeof(UINT16) + 2;		UINT16 pdwords[nwords];		int i; /* index into byte array of macaddr */		int j; /* index into pdr words */		/* create mac address PDR		word[0] : PDR length		word[1] : MAC address PDR code (0x101)		word[2-4] : MAC address (WLAN_ADDR_LEN bytes - usually 6) 		*/		pdwords[0] = host2hfa384x_16(0x0004);		pdwords[1] = host2hfa384x_16(0x0101);		for (i = 0, j = 2; i < WLAN_ADDR_LEN; i += 2, j++) {			pdwords[j] = host2hfa384x_16((UINT16) macaddr[i+1] << 8 | (UINT16) macaddr[i]);		}		/* merge the value into the PDA, so that it will eventually		 * be written. 		 */		merge_pda(&pda, pdwords, nwords);		pda_changed = 1;	}	/* If a serial number is specified add it to the PDA. */	if ( opt_sernum ) {		const unsigned nwords = SERNUM_LEN_MAX/sizeof(UINT16) + 2;		UINT16 pdwords[nwords];		int i; /* index into byte array of serial numbers bytes */		int j; /* index into pdr words */		/* create mac address PDR		word[0] : PDR length		word[1] : Serial number PDR code (0x0003)		word[2-7] : Serial number (12 bytes)		*/		pdwords[0] = host2hfa384x_16(0x0007);		pdwords[1] = host2hfa384x_16(0x0003);		for (i = 0, j = 2; i < SERNUM_LEN_MAX; i += 2, j++) {			pdwords[j] = host2hfa384x_16((UINT16) sernum[i+1] << 8 | (UINT16) sernum[i]);		}		/* merge the value into the PDA, so that it will eventually		 * be written. 		 */		merge_pda(&pda, pdwords, nwords);		pda_changed = 1;	}	  	if ( opt_status || opt_generate ) { /* print pda */		print_all_pdrs(&pda);	}	if ( opt_addpdrcnt ) { /* read the "add pdas" and merge them*/		pda_changed = 1;		for ( i = 0; i < opt_addpdrcnt; i++) {			read_filepda(&pda, addpdrfname[i]);		}	}	if ( pda_changed ) { /* calculate the CRC for the new PDA */		mkpda_crc(&pda);	}	if ( (opt_status || opt_generate ) && pda_changed ) {		printf("PDA after crc calc and/or \"-a\" file "			"generated modifications:\n");		print_all_pdrs(&pda);		/* Read and print the CIS? */		exit(0);	} else if  ( opt_status || opt_generate ) { /* We're done */		exit(0);  	}	if ( opt_ramloadcnt && !opt_flashloadcnt ) {		if (pda_changed) {		printf("Warning: RAM load only, PDA changes will NOT be written to flash.\n");		}		goto skip_pda_write;	}	if ( !opt_debug && !opt_nowrite && pda_changed) { /* write the PDA */		if ( opt_pdaloc == 0 ) {			fprintf(stderr, APPNAME ": error, you must specifify a pda location\n");			usage();			exit(1);		}		pda_write(&pda);	}skip_pda_write:	/*-----------------------------------------------------*/	/* Read the flash files */	if ( opt_flashloadcnt ) {		for ( i = 0; i < opt_flashloadcnt; i++) { /* For each file */			/* Read the S3 file */			result = read_srecfile(ffname[i]);			if ( result ) {				fprintf(stderr, APPNAME					": Failed to read %s, exiting.\n",					ffname[i]);				exit(1);			}			/* Sort the S3 data records */			qsort( s3data, 				ns3data,				sizeof(s3datarec_t),				s3datarec_compare);			result = validate_identity();			if (startaddr != 0x00000000) {				fprintf(stderr, APPNAME ": Can't flash a RAM download image!\n");				exit(1);			}			if ( result ) {				fprintf(stderr, APPNAME ": Incompatible firmware image.\n");				exit(1);			}			/* Make the image chunks */			result = mkimage(fchunk, &nfchunks);			/* Do any plugging */			result = plugimage(fchunk, nfchunks, s3plug, ns3plug, 						&pda, ffname[i]);			if ( result ) {				fprintf(stderr, APPNAME					": Failed to plug data for %s, exiting.\n",					ffname[i]);				exit(1);			}			/* Insert any CRCs */			if (crcimage(fchunk, nfchunks, s3crc, ns3crc) ) {				fprintf(stderr, APPNAME					": Failed to insert all CRCs for "					"%s, exiting.\n",					ffname[i]);				exit(1);			}			/* Write the image */			if ( opt_nowrite ) continue;			result = writeimage(fchunk, nfchunks, 1);			if ( result ) {				fprintf(stderr, APPNAME					": Failed to flashwrite image data for "					"%s, exiting.\n",					ffname[i]);				exit(1);			}			/* clear any allocated memory */			free_chunks(fchunk, &nfchunks);			free_srecs();		}	}	/* Read the ram files */	if ( opt_ramloadcnt ) {		for ( i = 0; i < opt_ramloadcnt; i++) { /* For each file */			/* Read the S3 file */			result = read_srecfile(rfname[i]);			if ( result ) {				fprintf(stderr, APPNAME					": Failed to read %s, exiting.\n",					rfname[i]);				exit(1);			}			/* Sort the S3 data records */			qsort( s3data, 				ns3data,				sizeof(s3datarec_t),				s3datarec_compare);			result = validate_identity();			if ( result && !opt_newpda ) {				fprintf(stderr, APPNAME ": Incompatible firmware image.\n");				exit(1);			}			if (startaddr == 0x00000000) {				fprintf(stderr, APPNAME ": Can't RAM download a Flash image!\n");				exit(1);			}			/* Make the image chunks */			result = mkimage(fchunk, &nfchunks);			/* Do any plugging */			result = plugimage(fchunk, nfchunks, s3plug, ns3plug, 						&pda, rfname[i]);			if ( result ) {				fprintf(stderr, APPNAME					": Failed to plug data for %s, exiting.\n",					rfname[i]);				exit(1);			}			/* Insert any CRCs */			if (crcimage(fchunk, nfchunks, s3crc, ns3crc) ) {				fprintf(stderr, APPNAME					": Failed to insert all CRCs for "					"%s, exiting.\n",					rfname[i]);				exit(1);			}			if ( opt_dumpchunks ) {				/* Dump the contents of the image chunks */				dumpchunks(fchunk, nfchunks);			}			/* Write the image */			if ( opt_nowrite ) continue;			result = writeimage(fchunk, nfchunks, 0);			if ( result ) {				fprintf(stderr, APPNAME					": Failed to ramwrite image data for "					"%s, exiting.\n",					rfname[i]);				exit(1);			}			/* clear any allocated memory */			free_chunks(fchunk, &nfchunks);			free_srecs();		}	}	printf(APPNAME": finished.\n");	return result;}/*----------------------------------------------------------------* crcimage** Adds a CRC16 in the two bytes prior to each block identified by* an S3 CRC record.  Currently, we don't actually do a CRC we just* insert the value 0xC0DE in hfa384x order.  ** Arguments:*	fchunk		Array of image chunks*	nfchunks	Number of image chunks*	s3crc		Array of crc records*	ns3crc		Number of crc records** Returns: *	0	success*	~0	failure----------------------------------------------------------------*/int crcimage(imgchunk_t *fchunk, UINT nfchunks, s3crcrec_t *s3crc, UINT ns3crc){	int	result = 0;	int	i;	int	c;	UINT32	crcstart;	UINT32	crcend;	UINT32	cstart = 0;	UINT32	cend;	UINT8	*dest;	UINT32	chunkoff;	for ( i = 0; i < ns3crc; i++ ) {		if ( !s3crc[i].dowrite ) continue;		crcstart = s3crc[i].addr;		crcend =   s3crc[i].addr + s3crc[i].len;		/* Find chunk */		for ( c = 0; c < nfchunks; c++) {			cstart = fchunk[c].addr;			cend =	 fchunk[c].addr + fchunk[c].len;			/*  the line below does an address & len match search */			/*  unfortunately, I've found that the len fields of */			/*  some crc records don't match with the length of */			/*  the actual data, so we're not checking right */			/*  now */			/* if ( crcstart-2 >= cstart && crcend <= cend ) break;*/			/* note the -2 below, it's to make sure the chunk has */			/*   space for the CRC value */			if ( crcstart-2 >= cstart && crcstart < cend ) break;		}		if ( c >= nfchunks ) {			fprintf(stderr, APPNAME				": Failed to find chunk for "				"crcrec[%d], addr=0x%06lx len=%ld , "				"aborting crc.\n", 				i, s3crc[i].addr, s3crc[i].len);			return 1;		}				/* Insert crc */		if (opt_verbose) {			printf("Adding crc @ 0x%06lx\n", s3crc[i].addr-2);		}		chunkoff = crcstart - cstart - 2;		dest = fchunk[c].data + chunkoff;		*dest =     0xde;

⌨️ 快捷键说明

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