Added pdaread ioctl call and the decode and print of the pda.

This commit is contained in:
mark 2000-01-25 22:34:35 +00:00
parent 6e4562bffe
commit d6d9d2ec27
1 changed files with 135 additions and 27 deletions

View File

@ -52,6 +52,8 @@
#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>
@ -191,25 +193,28 @@ s3inforec_t s3info[50];
/* S7 record (there _better_ be only one) */
UINT32 startaddr;
/* Note that for the following pdrec_t arrays, the len and code */
/* fields are stored in HOST byte order. The makepdrlist() function */
/* does the conversion. */
/*----------------------------------------------------------------*/
/* Card PDA */
UINT8 cardpda[HFA384x_PDA_MAXLEN];
hfa384x_pdrec_t cardpdrec[HFA384x_PDA_MAXRECS];
UINT8 cardpda[HFA384x_PDA_LEN_MAX];
hfa384x_pdrec_t cardpdrec[HFA384x_PDA_RECS_MAX];
UINT ncardpdrec = 0;
/*----------------------------------------------------------------*/
/* Replacement PDA (from file) */
UINT8 newpda[HFA384x_PDA_MAXLEN];
hfa384x_pdrec_t newpdrec[HFA384x_PDA_MAXRECS];
UINT8 newpda[HFA384x_PDA_LEN_MAX];
hfa384x_pdrec_t newpdrec[HFA384x_PDA_RECS_MAX];
UINT nnewpdrec = 0;
/*----------------------------------------------------------------*/
/* Additive PDRs (adds to replacement or card PDA) */
UINT8 addpda[HFA384x_PDA_MAXLEN];
hfa384x_pdrec_t addpdrec[HFA384x_PDA_MAXRECS];
UINT8 addpda[HFA384x_PDA_LEN_MAX];
hfa384x_pdrec_t addpdrec[HFA384x_PDA_RECS_MAX];
UINT naddpdrec = 0;
/*================================================================*/
@ -219,6 +224,9 @@ void usage(void);
int load_srecfile(char *fname);
int load_pdrfile( char *fname, int isnew);
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);
/*================================================================*/
/* Function Definitions */
@ -381,14 +389,54 @@ int main ( int argc, char **argv )
}
/* Read on card PDA */
if ( opt_tfile || opt_dumppda ) {
load_cardpda();
if ( (opt_tfile || opt_dumppda) && !opt_newpda ) {
if (load_cardpda()) {
fprintf(stderr,"loac_cardpda failed, exiting.\n");
exit(1);
}
}
/* Display the PDA */
if ( opt_dumppda ) {
print_all_pdrs();
}
return result;
}
/*----------------------------------------------------------------
* print_all_pdrs
*
* Dumps the contents of all the pdr lists to stdout. Assumes that
* the pdrlists have 'been made'. See makepdrlist().
*
* Arguments: none
*
* Returns:
* 0 - success
* ~0 - failure (probably an errno)
----------------------------------------------------------------*/
void print_all_pdrs(void)
{
int i;
int j;
printf("PDA from card %s:\n", ifname);
printf( "idx code len data\n"
"---------------------------------------------------\n");
/* 000 0x0000 000 0000 0000 0000 0000... */
for ( i = 0; i < ncardpdrec; i++) {
printf("%03d 0x%04x %3d", i,
cardpdrec[i].code,
cardpdrec[i].len);
for ( j = 0; j < cardpdrec[i].len; j++) {
printf("%04x ", ((UINT16*)(cardpdrec[i].data))[j]);
}
printf("\n");
}
}
/*----------------------------------------------------------------
* load_cardpda
@ -404,8 +452,66 @@ int main ( int argc, char **argv )
* ~0 - failure (probably an errno)
----------------------------------------------------------------*/
int load_cardpda(void)
{
int result = 0;
p80211msg_p2req_readpda_t msg;
/* set up the msg */
msg.msgcode = DIDmsg_p2req_readpda;
msg.msglen = sizeof(msg);
strcpy(msg.devname, ifname);
msg.pda.did = DIDmsg_p2req_readpda_pda;
msg.pda.len = HFA384x_PDA_LEN_MAX;
msg.pda.status = P80211ENUM_msgitem_status_no_value;
msg.resultcode.did = DIDmsg_p2req_readpda_resultcode;
msg.resultcode.len = sizeof(UINT32);
msg.resultcode.status = P80211ENUM_msgitem_status_no_value;
if ( do_ioctl((p80211msg_t*)&msg) != 0 ) {
/* do_ioctl prints an erro if appropriate */
result = -1;
} else if ( msg.resultcode.data == P80211ENUM_resultcode_success ) {
memcpy(cardpda, msg.pda.data, HFA384x_PDA_LEN_MAX);
result = makepdrlist(cardpda, cardpdrec, &ncardpdrec);
}
return result;
}
/*----------------------------------------------------------------
* makepdrlist
*
* Reads a raw PDA and builds an array of pdrec_t structures.
* NOTE: the len and code fields of the pdrrec_t's in the array
* will contain their values in HOST byte order following the
* execution of this function. The data field is NOT converted.
* If you use one of the data field elements don't forget to
* convert it first.
*
* Arguments:
* pda buffer containing raw PDA bytes
* pdrec ptr to an array of pdrec_t's. Will be filled on exit.
* nrec ptr to a variable that will contain the count of PDRs
*
* Returns:
* 0 - success
* ~0 - failure (probably an errno)
----------------------------------------------------------------*/
int makepdrlist( UINT8 *pda, hfa384x_pdrec_t *pdrec, UINT *nrec)
{
int result = 0;
UINT16 *pda16 = (UINT16*)pda;
int curroff; /* in 'words' */
*nrec = 0;
curroff = 0;
while ( hfa384x2host_16(pda16[curroff + 1]) != HFA384x_PDR_END_OF_PDA){
pdrec[*nrec].len = hfa384x2host_16(pda16[curroff]);
pdrec[*nrec].code = hfa384x2host_16(pda16[curroff+1]);
pdrec[*nrec].data = (union pdr*)(pda + (curroff*2) + 2);
(*nrec)++;
curroff += hfa384x2host_16(pda16[curroff]);
}
return result;
}
@ -652,17 +758,17 @@ int load_srecfile(char *fname)
/*----------------------------------------------------------------
* do_ioctl
*
* TODO: describe
* Performs the ioctl call to send a message down to an 802.11
* device.
*
* Arguments:
* argc number of command line arguments
* argv array of argument strings
* msg the message to send
*
* Returns:
* 0 - success
* ~0 - failure
* 0 success
* ~0 failure
----------------------------------------------------------------*/
void do_ioctl( UINT8 *msg, UINT32 msgcode )
int do_ioctl( p80211msg_t *msg )
{
int result = 0;
int fd;
@ -674,21 +780,23 @@ void do_ioctl( UINT8 *msg, UINT32 msgcode )
/* get a socket */
fd = socket(AF_INET, SOCK_STREAM, 0);
if ( fd == -1 ) {
result = errno;
perror("wlanctl");
return;
} else {
req.len = msg->msglen;
req.data = msg;
strcpy( req.name, msg->devname);
req.result = 0;
result = ioctl( fd, P80211_IFREQ, &req);
if ( result == -1 ) {
result = errno;
perror(APPNAME);
}
close(fd);
}
req.len = MSG_BUFF_LEN; /* TODO: need to fix the length */
req.data = msg;
strcpy( req.name, devname);
req.result = 0;
result = ioctl( fd, P80211_IFREQ, &req);
if ( result == -1 ) {
perror("wlanctl");
}
return;
return result;
}
/*----------------------------------------------------------------