Rearranged the cmdline arguments to support flash loads.

This commit is contained in:
mark 2000-01-26 20:24:34 +00:00
parent 6c87551b66
commit 2dd3c7b89a
1 changed files with 210 additions and 116 deletions

View File

@ -48,6 +48,7 @@
#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>
@ -62,6 +63,10 @@
#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
@ -75,6 +80,7 @@
/*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
@ -147,29 +153,40 @@ typedef struct s3inforec
/*----------------------------------------------------------------*/
/* App support */
char *devname;
char appname[APPNAME_MAX + 1];
char *fullname;
char ifname[16];
int fd_ioctl = 0; /* Used to send request messages */
char devname[16];
/*----------------------------------------------------------------*/
/* option flags */
int opt_dumppda = 0; /* -s => 0-dont,1-from card,2-from file,3-combined */
int opt_addpdrs = 0; /* -a => boolean & filename PD records */
char pdrfilename[FILENAME_MAX+1];
int opt_newpda = 0; /* -p => boolean & filename for whole new PDA */
char pdafilename[FILENAME_MAX+1];
int opt_tfile = 0; /* -t => boolean & tertiary image filename */
char tfilename[FILENAME_MAX+1];
/* GENERAL options */
int opt_status = 0; /* -s => show status and exit */
int opt_verbose = 0; /* -v => boolean, verbose operation */
int opt_nodownload = 0; /* -n => boolean, process all data-but don't download */
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 */
char opts[] = "nvVs:t:a:p:";
/* 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 */
char opts[] = "svVndr:f:a:p:m:S:";
/*----------------------------------------------------------------*/
/* s-record image processing */
@ -227,6 +244,7 @@ int load_cardpda(void);
int makepdrlist( UINT8 *pda, hfa384x_pdrec_t *pdrec, UINT *nrec);
int do_ioctl( p80211msg_t *msg );
void print_all_pdrs(void);
int str2macaddr( UINT8 *a, char *s );
/*================================================================*/
/* Function Definitions */
@ -253,104 +271,15 @@ int main ( int argc, char **argv )
strcpy( appname, APPNAME );
fullname = argv[0];
/* if no args, print the usage msg */
if ( argc < 2 ) {
usage();
return -1;
}
/* 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));
/* collect the args */
while ( ((optch = getopt(argc, argv, opts)) != EOF) && (result == 0) ) {
switch (optch)
{
case 's':
/* PDA show level */
if (optarg) {
opt_dumppda = atoi(optarg);
if (opt_dumppda == 0) {
fprintf(stderr, APPNAME": bad -s argument\n");
return 1;
}
} else {
opt_dumppda = 1;
}
break;
case 't':
/* tertiary image filename */
opt_tfile = 1;
strncpy(tfilename, optarg, sizeof(tfilename));
tfilename[sizeof(tfilename)-1] = '\0';
break;
case 'a':
/* Add PD records filename */
fprintf(stderr,APPNAME": adding pd records not yet supported.\n");
exit(1);
/* TODO:
opt_addpdrs = 1;
strncpy(pdrfilename, optarg, sizeof(pdrfilename));
pdrfilename[sizeof(pdrfilename)-1] = '\0';
*/
break;
case 'p':
/* New PDA filename */
fprintf(stderr,APPNAME": writing a new pda not yet supported.\n");
exit(1);
/* TODO:
opt_newpda = 1;
strncpy(pdafilename, optarg, sizeof(pdafilename));
pdafilename[sizeof(pdafilename)-1] = '\0';
*/
break;
case 'n':
/* Process, no download */
opt_nodownload = 1;
break;
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;
default:
usage();
return -1;
break;
}
}
/* if we made it this far, the options must be pretty much OK */
if ( optind >= argc ) {
/* we're missing the interface argument */
fprintf(stderr, APPNAME": missing argument - interface\n");
usage();
return -1;
} else {
/* save the interface name */
strncpy( ifname, argv[optind], sizeof(ifname) );
ifname[sizeof(ifname)-1] = '\0';
}
/* Check mode and validate args */
if (opt_dumppda) {
switch (opt_dumppda)
{
case 2: /* from file */
case 3: /* combination */
if ( !opt_addpdrs && !opt_newpda ) {
fprintf(stderr, APPNAME":warning - no PDR or PDA files specified.\n");
}
}
} else {
if ( !opt_tfile ) {
fprintf(stderr, APPNAME":error - no image file specfied\n");
return 1;
}
}
/* Initialize data structures */
ns3data = 0;
memset(s3data, 0, sizeof(s3data));
ns3plug = 0;
@ -371,6 +300,132 @@ int main ( int argc, char **argv )
memset(addpdrec, 0, sizeof(newpdrec));
naddpdrec = 0;
/* 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;
break;
case 's':
/* Show status */
opt_status = 1;
break;
case 'r':
/* Ram image filename, add to list */
if ( opt_ramloadcnt >= RAMFILES_MAX ) {
fprintf(stderr,APPNAME": too many RAM files on cmd line. Exitting.\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. Exitting.\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. Exitting.\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. Exitting.\n");
exit(1);
}
opt_newpda = 1;
strncpy(newpdafname, optarg, FILENAME_MAX);
break;
case 'm':
/* cmdline MAC address */
if ( opt_macaddr ) {
fprintf(stderr,APPNAME": -m specified more than once. Exitting.\n");
exit(1);
}
if ( str2macaddr(macaddr, optarg) != 0 ) {
fprintf(stderr,APPNAME": mac address format error. Exitting.\n");
exit(1);
}
opt_macaddr = 1;
break;
case 'S':
/* cmdline Serial number */
if ( opt_sernum ) {
fprintf(stderr,APPNAME": -S specified more than once. Exitting.\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;
}
}
/* if we made it this far, the options must be pretty much OK */
if ( optind >= argc ) {
/* we're missing the interface argument */
fprintf(stderr, APPNAME": missing argument - interface\n");
usage();
return -1;
} else {
/* save the interface name */
strncpy( devname, argv[optind], sizeof(devname) );
}
/* Check mode and validate args */
#if 0
if (opt_dumppda) {
switch (opt_dumppda)
{
case 2: /* from file */
case 3: /* combination */
if ( !opt_addpdrs && !opt_newpda ) {
fprintf(stderr, APPNAME":warning - no PDR or PDA files specified.\n");
}
}
} else {
if ( !opt_tfile ) {
fprintf(stderr, APPNAME":error - no image file specfied\n");
return 1;
}
}
/* Initialize data structures */
/* Read files */
/*
if ( opt_newpda ) {
@ -387,7 +442,9 @@ int main ( int argc, char **argv )
return result;
}
}
#endif
#if 0
/* Read on card PDA */
if ( (opt_tfile || opt_dumppda) && !opt_newpda ) {
if (load_cardpda()) {
@ -395,11 +452,11 @@ int main ( int argc, char **argv )
exit(1);
}
}
/* Display the PDA */
if ( opt_dumppda ) {
print_all_pdrs();
}
#endif
return result;
@ -422,7 +479,7 @@ void print_all_pdrs(void)
{
int i;
int j;
printf("PDA from card %s:\n", ifname);
printf("PDA from card %s:\n", devname);
printf( "idx code len data\n"
"---------------------------------------------------\n");
/* 000 0x0000 000 0000 0000 0000 0000... */
@ -459,7 +516,7 @@ int load_cardpda(void)
/* set up the msg */
msg.msgcode = DIDmsg_p2req_readpda;
msg.msglen = sizeof(msg);
strcpy(msg.devname, ifname);
strcpy(msg.devname, devname);
msg.pda.did = DIDmsg_p2req_readpda_pda;
msg.pda.len = HFA384x_PDA_LEN_MAX;
msg.pda.status = P80211ENUM_msgitem_status_no_value;
@ -835,3 +892,40 @@ void usage(void)
printf(" so be careful when setting them.\n\n");
}
/*----------------------------------------------------------------
* 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;
}