📄 prism2dl.c
字号:
/* src/prism2/download/prism2dl.c** user utility for downloading prism2 images** Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.* --------------------------------------------------------------------** linux-wlan** This software is distributed on an "AS* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** This software is NOT distributed under an Open Source license.* If you received it without a direct license from AbsoluteValue * Systems, Inc. then you are not a licensed user and are violating* AbsoluteValue Systems rights under copyright law.* * --------------------------------------------------------------------** Inquiries regarding this software and AbsoluteValue Systems products* and service can be made directly to:** AbsoluteValue Systems Inc.* info@linux-wlan.com* http://www.linux-wlan.com** --------------------------------------------------------------------** Portions of the development of this software were funded by * Intersil Corporation as part of PRISM(R) chipset product development.** --------------------------------------------------------------------*//*================================================================*//* System Includes */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <ctype.h>#include <regex.h>#include <sys/socket.h>#include <sys/types.h>#include <sys/ioctl.h>#include <endian.h>#include <byteswap.h>/*================================================================*//* Project Includes */#include <wlan/wlan_compat.h>#include <wlan/version.h>#include <wlan/p80211hdr.h>#include <wlan/p80211types.h>#include <wlan/p80211meta.h>#include <wlan/p80211metamsg.h>#include <wlan/p80211msg.h>#include <wlan/p80211metadef.h>#include <wlan/p80211metastruct.h>#include <wlan/p80211ioctl.h>#include <prism2/hfa384x.h>/* Redefine macros for endianness to avoid using kernel headers */#if __BYTE_ORDER == __LITTLE_ENDIAN#define hfa384x2host_16(n) (n)#define hfa384x2host_32(n) (n)#define host2hfa384x_16(n) (n)#define host2hfa384x_32(n) (n)#else#define hfa384x2host_16(n) bswap_16(n)#define hfa384x2host_32(n) bswap_32(n)#define host2hfa384x_16(n) bswap_16(n)#define host2hfa384x_32(n) bswap_32(n)#endif/*================================================================*//* Local Constants */#define APPNAME "prism2dl"#define APPNAME_MAX 30#define ADDPDRFILES_MAX 10#define RAMFILES_MAX 10#define FLASHFILES_MAX 10#define S3DATA_MAX 5000#define S3PLUG_MAX 200#define S3CRC_MAX 200#define S3INFO_MAX 50#define SREC_LINE_MAX 264#define S3LEN_TXTOFFSET 2#define S3LEN_TXTLEN 2#define S3ADDR_TXTOFFSET 4#define S3ADDR_TXTLEN 8#define S3DATA_TXTOFFSET 12/*S3DATA_TXTLEN variable, depends on len field *//*S3CKSUM_TXTOFFSET variable, depends on len field */#define S3CKSUM_TXTLEN 2#define SERNUM_LEN_MAX 12#define S3PLUG_ITEMCODE_TXTOFFSET (S3DATA_TXTOFFSET)#define S3PLUG_ITEMCODE_TXTLEN 8#define S3PLUG_ADDR_TXTOFFSET (S3DATA_TXTOFFSET+8)#define S3PLUG_ADDR_TXTLEN 8#define S3PLUG_LEN_TXTOFFSET (S3DATA_TXTOFFSET+16)#define S3PLUG_LEN_TXTLEN 8#define S3CRC_ADDR_TXTOFFSET (S3DATA_TXTOFFSET)#define S3CRC_ADDR_TXTLEN 8#define S3CRC_LEN_TXTOFFSET (S3DATA_TXTOFFSET+8)#define S3CRC_LEN_TXTLEN 8#define S3CRC_DOWRITE_TXTOFFSET (S3DATA_TXTOFFSET+16)#define S3CRC_DOWRITE_TXTLEN 8#define S3INFO_LEN_TXTOFFSET (S3DATA_TXTOFFSET)#define S3INFO_LEN_TXTLEN 4#define S3INFO_TYPE_TXTOFFSET (S3DATA_TXTOFFSET+4)#define S3INFO_TYPE_TXTLEN 4#define S3INFO_DATA_TXTOFFSET (S3DATA_TXTOFFSET+8)/* S3INFO_DATA_TXTLEN variable, depends on INFO_LEN field */#define S3ADDR_PLUG (0xff000000UL)#define S3ADDR_CRC (0xff100000UL)#define S3ADDR_INFO (0xff200000UL)#define PDAFILE_LINE_MAX 1024#define CHUNKS_MAX 100#define WRITESIZE_MAX 4096/*================================================================*//* Local Macros *//*================================================================*//* Local Types */typedef struct s3datarec{ UINT32 len; UINT32 addr; UINT8 checksum; UINT8 *data;} s3datarec_t;typedef struct s3plugrec{ UINT32 itemcode; UINT32 addr; UINT32 len;} s3plugrec_t;typedef struct s3crcrec{ UINT32 addr; UINT32 len; UINT dowrite;} s3crcrec_t;typedef struct s3inforec{ UINT16 len; UINT16 type; union { hfa384x_compident_t version; hfa384x_caplevel_t compat; UINT16 buildseq; hfa384x_compident_t platform; } info;} s3inforec_t;typedef struct pda{ UINT8 buf[HFA384x_PDA_LEN_MAX]; hfa384x_pdrec_t *rec[HFA384x_PDA_RECS_MAX]; UINT nrec;} pda_t;typedef struct imgchunk{ UINT32 addr; /* start address */ UINT32 len; /* in bytes */ UINT16 crc; /* CRC value (if it falls at a chunk boundary) */ UINT8 *data;} imgchunk_t;/*================================================================*//* Local Static Definitions *//*----------------------------------------------------------------*//* App support */char appname[APPNAME_MAX + 1];char *fullname;char devname[16];/*----------------------------------------------------------------*//* option flags *//* GENERAL options */int opt_status = 0; /* -s => show status and exit */int opt_verbose = 0; /* -v => boolean, verbose operation */int opt_nowrite = 0; /* -n => boolean, process all data-but don't download */int opt_debug = 0; /* -d => boolean, process all data-but don't download */int opt_generate = 0; /* -g => boolean, if -s or -d output is in pdr and srec file format */int opt_dumpchunks = 0; /* -D => boolean, dump the imgchunks after plugging and crc *//* IMAGEFILE options */int opt_ramloadcnt = 0; /* -r => boolean & count of ram filenames */char rfname[RAMFILES_MAX][FILENAME_MAX+1]; /* -r filenames */int opt_flashloadcnt = 0; /* -f => boolean & count of flash filenames */char ffname[FLASHFILES_MAX][FILENAME_MAX+1]; /* -f filenames *//* PDA options */int opt_addpdrcnt = 0; /* -a => boolean & count of addfiles */char addpdrfname[ADDPDRFILES_MAX][FILENAME_MAX+1]; /* -a filenames */int opt_newpda = 0; /* -p => boolean for whole new PDA */char newpdafname[FILENAME_MAX+1]; /* -p filename */int opt_macaddr = 0; /* -m => boolean for cmdline MAC address */UINT8 macaddr[WLAN_ADDR_LEN]; /* -m mac address */int opt_sernum = 0; /* -S => boolean for cmdline serial # */char sernum[SERNUM_LEN_MAX+1]; /* -S serial # string */int opt_pdaloc = 0; /* -l => pda location */ /* -l address */char opts[] = "svVndDgr:f:a:p:m:S:l:";/*----------------------------------------------------------------*//* s-record image processing *//* Data records */UINT ns3data = 0;s3datarec_t s3data[S3DATA_MAX];/* Plug records */UINT ns3plug = 0;s3plugrec_t s3plug[S3PLUG_MAX];/* CRC records */UINT ns3crc = 0;s3crcrec_t s3crc[200];/* Info records */UINT ns3info = 0;s3inforec_t s3info[50];/* S7 record (there _better_ be only one) */UINT32 startaddr;/* Load image chunks */UINT nfchunks;imgchunk_t fchunk[CHUNKS_MAX];/* Note that for the following pdrec_t arrays, the len and code *//* fields are stored in HOST byte order. The mkpdrlist() function *//* does the conversion. *//*----------------------------------------------------------------*//* PDA, built from [card|newfile]+[addfile1+addfile2...] */pda_t pda;hfa384x_compident_t nicid;hfa384x_caplevel_t rfid;hfa384x_caplevel_t macid;hfa384x_caplevel_t priid;const UINT16 crc16tab[256] ={ 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040};/*================================================================*//* Local Function Declarations */void usage(void);int read_srecfile(char *fname);int mkimage(imgchunk_t *clist, UINT *ccnt);int read_pdrfile( char *fname, int isnew);int read_cardpda(pda_t *pda, char *dev);int read_filepda(pda_t *pda, char *pdrfname);void merge_pda(pda_t *pda, UINT16 *pdwords, int nword);int mkpdrlist( pda_t *pda);int do_ioctl( p80211msg_t *msg );void print_all_pdrs(pda_t *pda);int str2macaddr( UINT8 *a, char *s );int s3datarec_compare(const void *p1, const void *p2);int mkpda_crc( pda_t *pda);int pda_write(pda_t *pda);int plugimage( imgchunk_t *fchunk, UINT nfchunks, s3plugrec_t* s3plug, UINT ns3plug, pda_t *pda, char *fname);int crcimage( imgchunk_t *fchunk, UINT nfchunks, s3crcrec_t *s3crc, UINT ns3crc);int writeimage(imgchunk_t *fchunk, UINT nfchunks, int isflash);void free_chunks(imgchunk_t *fchunk, UINT* nfchunks);void free_srecs(void);void dumpchunks( imgchunk_t *fchunk, UINT nfchunks);int validate_identity(void);/*================================================================*//* Function Definitions *//*----------------------------------------------------------------* main** prism2dl entry point.** Arguments:* argc number of command line arguments* argv array of argument strings** Returns: * 0 - success * ~0 - failure----------------------------------------------------------------*/int main ( int argc, char **argv ){ INT result = 0; int optch; int i; int pda_changed = 0; /* has cardpda been altered? */ strcpy( appname, APPNAME ); fullname = argv[0]; /* Initialize the data structures */ memset(rfname, 0, sizeof(rfname)); memset(ffname, 0, sizeof(ffname)); memset(addpdrfname, 0, sizeof(addpdrfname)); memset(newpdafname, 0, sizeof(newpdafname)); memset(macaddr, 0, sizeof(macaddr)); memset(sernum, 0, sizeof(sernum)); memset(devname, 0, sizeof(devname)); ns3data = 0; memset(s3data, 0, sizeof(s3data)); ns3plug = 0; memset(s3plug, 0, sizeof(s3plug)); ns3crc = 0; memset(s3crc, 0, sizeof(s3crc)); ns3info = 0; memset(s3info, 0, sizeof(s3info)); startaddr = 0; nfchunks = 0; memset( fchunk, 0, sizeof(fchunk)); memset( &nicid, 0, sizeof(nicid)); memset( &rfid, 0, sizeof(rfid)); memset( &macid, 0, sizeof(macid)); memset( &priid, 0, sizeof(priid)); /* clear the pda and add an initial END record */ memset(&pda, 0, sizeof(pda)); pda.rec[0] = (hfa384x_pdrec_t*)pda.buf; pda.rec[0]->len = host2hfa384x_16(2); /* len in words */ /* len in words */ pda.rec[0]->code = host2hfa384x_16(HFA384x_PDR_END_OF_PDA); pda.nrec = 1; /* if no args, print the usage msg */ if ( argc < 2 ) { usage(); return -1; } /* collect the args */ while ( ((optch = getopt(argc, argv, opts)) != EOF) && (result == 0) ) { switch (optch) { case 'v': /* Verbose operation */ opt_verbose = 1; break; case 'V': /* Display version and exit */ printf("%s utility version %s\n", appname, WLAN_RELEASE); return 0; break; case 'n': /* Process files and card PDA, no download */ opt_nowrite = 1; break; case 'd': /* Process files, no card PDA, no download */ opt_debug = 1; opt_verbose = 1; break; case 'D': /* dump chunks */ opt_dumpchunks = 1; break; case 's': /* Show status */ opt_status = 1; break; case 'g': /* File generate */ opt_generate = 1; break; case 'r': /* Ram image filename, add to list */ if ( opt_ramloadcnt >= RAMFILES_MAX ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -