Modified to eliminate the '+1' in the various pstr structure typedefs. Also, created p80211item_maxitemlen to calculate the size of a did-len-data triple. Changed p80211item_getoffset to call p80211item_maxitemlen as opposed to the hardcoding so that the data size of an item is only calculated in one place.

This commit is contained in:
joellen 2000-01-11 04:13:02 +00:00
parent c60a78075f
commit b3738ea2f5
7 changed files with 250 additions and 205 deletions

View file

@ -1,5 +1,5 @@
LINUX_SRC=/usr/src/linux
PCMCIA_SRC=/usr/src/pcmcia-cs-3.0.13
MODULES_DIR=/lib/modules/2.2.9
PCMCIA_SRC=/usr/src/pcmcia-cs-3.0.12
MODULES_DIR=/lib/modules/2.2.5-15
INST_EXEDIR=/sbin
DESTDIR=

View file

@ -141,5 +141,9 @@ INT p80211_isvalid_itemdid( catlistitem_t *catlist, UINT32 did );
catlistitem_t *p80211_did2cat( catlistitem_t *catlist, UINT32 did );
grplistitem_t *p80211_did2grp( catlistitem_t *catlist, UINT32 did );
p80211meta_t *p80211_did2item( catlistitem_t *catlist, UINT32 did );
UINT32 p80211item_maxdatalen( struct catlistitem *metalist, UINT32 did );
UINT32 p80211_metaname2did(struct catlistitem *metalist, char *itemname);
UINT32 p80211item_maxitemlen( struct catlistitem *metalist, UINT32 did );
UINT32 p80211item_getoffset( struct catlistitem *metalist, UINT32 did );
#endif /* _P80211META_H */

View file

@ -86,7 +86,5 @@ __WLAN_PRAGMA_PACKDFLT__
/*================================================================*/
/* Function Declarations */
UINT32 p80211item_getoffset( struct catlistitem *metalist, UINT32 did );
#endif /* _P80211MSG_H */

View file

@ -363,7 +363,7 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211pstr255
{
UINT8 len __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR255+1] __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR255] __WLAN_ATTRIB_PACK__;
} p80211pstr255_t;
__WLAN_PRAGMA_PACKDFLT__
@ -372,7 +372,7 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211pstr6
{
UINT8 len __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR6+1] __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR6] __WLAN_ATTRIB_PACK__;
} p80211pstr6_t;
__WLAN_PRAGMA_PACKDFLT__
@ -381,7 +381,7 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211pstr14
{
UINT8 len __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR14+1] __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR14] __WLAN_ATTRIB_PACK__;
} p80211pstr14_t;
__WLAN_PRAGMA_PACKDFLT__
@ -390,7 +390,7 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211pstr32
{
UINT8 len __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR32+1] __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_PSTR32] __WLAN_ATTRIB_PACK__;
} p80211pstr32_t;
__WLAN_PRAGMA_PACKDFLT__
@ -399,8 +399,8 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211item
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
} p80211item_t;
__WLAN_PRAGMA_PACKDFLT__
@ -409,8 +409,8 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211itemd
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
UINT8 data[0] __WLAN_ATTRIB_PACK__;
} p80211itemd_t;
__WLAN_PRAGMA_PACKDFLT__
@ -420,8 +420,8 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211item_uint32
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
UINT32 data __WLAN_ATTRIB_PACK__;
} p80211item_uint32_t;
__WLAN_PRAGMA_PACKDFLT__
@ -431,8 +431,8 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211item_pstr6
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
p80211pstr6_t data __WLAN_ATTRIB_PACK__;
}p80211item_pstr6_t;
__WLAN_PRAGMA_PACKDFLT__
@ -442,8 +442,8 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211item_pstr14
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
p80211pstr14_t data __WLAN_ATTRIB_PACK__;
}p80211item_pstr14_t;
__WLAN_PRAGMA_PACKDFLT__
@ -453,8 +453,8 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211item_pstr32
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
p80211pstr32_t data __WLAN_ATTRIB_PACK__;
}p80211item_pstr32_t;
__WLAN_PRAGMA_PACKDFLT__
@ -464,8 +464,8 @@ __WLAN_PRAGMA_PACK1__
typedef struct p80211item_pstr255
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
p80211pstr255_t data __WLAN_ATTRIB_PACK__;
}p80211item_pstr255_t;
__WLAN_PRAGMA_PACKDFLT__
@ -473,10 +473,10 @@ __WLAN_PRAGMA_PACKDFLT__
/* message data item for UNK 264, namely mib items */
typedef struct p80211item_unk264
{
UINT32 did __WLAN_ATTRIB_PACK__;
short status __WLAN_ATTRIB_PACK__;
short len __WLAN_ATTRIB_PACK__;
UINT8 data[264] __WLAN_ATTRIB_PACK__;
UINT32 did __WLAN_ATTRIB_PACK__;
UINT16 status __WLAN_ATTRIB_PACK__;
UINT16 len __WLAN_ATTRIB_PACK__;
UINT8 data[MAXLEN_MIBATTRIBUTE] __WLAN_ATTRIB_PACK__;
} p80211item_unk264_t;
__WLAN_PRAGMA_PACK1__
struct catlistitem;
@ -530,9 +530,6 @@ void p80211_error2text(int err_code, char *err_str);
/* The following declare some utility functions for use with the */
/* p80211item_t and p80211meta_t types. */
UINT32 p80211item_maxdatalen( struct catlistitem *metalist, UINT32 did );
UINT32 p80211_metaname2did(struct catlistitem *metalist, char *itemname);
/*----------------------------------------------------------------*/
/* The following declare functions that perform validation and */
/* text to binary conversions based on the metadata for interface */

View file

@ -523,3 +523,202 @@ p80211meta_t *p80211_did2item( catlistitem_t *catlist, UINT32 did )
return item;
}
/*----------------------------------------------------------------
* p80211item_getoffset
*
* Returns the offset of the data item identified by a given DID.
* This function assumes a valid did is passed to the function.
*
* Arguments:
* did a valid, complete DID
*
* Returns:
* 0xffffffff if the type from the did doesn't match a
* known type
* offset on success
----------------------------------------------------------------*/
UINT32 p80211item_getoffset( catlistitem_t *metalist, UINT32 did )
{
UINT32 catgrp;
UINT32 offset;
UINT32 tmpdid;
UINT32 item;
INT i;
p80211meta_t *alist=NULL;
offset = 0UL;
if ( (p80211_isvalid_did(metalist, did )) != P80211DID_INVALID ) {
alist = metalist[P80211DID_SECTION(did)].
grplist[P80211DID_GROUP(did)].itemlist;
item = P80211DID_ITEM(did);
catgrp = P80211DID_MKSECTION(P80211DID_SECTION(did)) |
P80211DID_MKGROUP(P80211DID_GROUP(did));
for ( i = 1; i < item; i++ ) {
tmpdid = catgrp | P80211DID_MKITEM(i) | alist[i].did;
switch( P80211DID_TYPE(alist[i].did) ) {
case P80211_TYPE_OCTETSTR:
case P80211_TYPE_DISPLAYSTR:
case P80211_TYPE_INT:
case P80211_TYPE_BOUNDEDINT:
case P80211_TYPE_ENUMINT:
case P80211_TYPE_UNKDATA:
offset +=
p80211item_maxitemlen(metalist,tmpdid);
break;
default:
printf("Undefined data type for %s\n",
alist[i].name );
offset = 0xffffffff;
return offset;
break;
}
} /* for each arg meta data item up to current item */
} else {
offset = 0xffffffff;
}
return offset;
}
/*----------------------------------------------------------------
* p80211item_maxdatalen
*
* Returns the total maximum data size of an item identified
* by a given DID. This is the length of the data part of the
* item triple.
*
* Arguments:
* metalist pointer to a category metadata list
* did A complete DID
*
* Returns:
* 0xffffffff Bad DID or unrecognized type in metadata
* anything else success, return value is maxdatalen
----------------------------------------------------------------*/
UINT32 p80211item_maxdatalen( catlistitem_t *metalist, UINT32 did )
{
UINT32 maxlen;
p80211meta_t *meta;
if ( (meta = p80211_did2item(metalist, did)) != NULL ) {
switch( P80211DID_TYPE(did) ) {
case P80211_TYPE_OCTETSTR:
case P80211_TYPE_DISPLAYSTR:
/* add size of pstr length byte */
maxlen = meta->maxlen + sizeof(UINT8);
break;
case P80211_TYPE_INT:
case P80211_TYPE_BOUNDEDINT:
case P80211_TYPE_ENUMINT:
/* all int types are 4 bytes */
maxlen = 4;
break;
case P80211_TYPE_UNKDATA:
maxlen = meta->maxlen;
break;
default:
maxlen = 0xffffffffUL;
}
} else {
maxlen = 0xffffffffUL;
}
return maxlen;
}
/*----------------------------------------------------------------
* p80211item_maxitemlen
*
* Returns the total maximum data size of an item identified
* by a given DID. This is the length of the enitre triple.
*
* Arguments:
* metalist pointer to a category metadata list
* did A complete DID
*
* Returns:
* 0xffffffff Bad DID or unrecognized type in metadata
* anything else success, return value is maxdatalen
----------------------------------------------------------------*/
UINT32 p80211item_maxitemlen( catlistitem_t *metalist, UINT32 did )
{
UINT32 maxlen;
switch( P80211DID_TYPE(did) ) {
case P80211_TYPE_OCTETSTR:
case P80211_TYPE_DISPLAYSTR:
case P80211_TYPE_INT:
case P80211_TYPE_BOUNDEDINT:
case P80211_TYPE_ENUMINT:
case P80211_TYPE_UNKDATA:
maxlen = p80211item_maxdatalen(metalist, did);
if (maxlen != 0xffffffffUL ) {
maxlen += sizeof(p80211item_t);
}
break;
default:
maxlen = 0xffffffffUL;
break;
}
return maxlen;
}
/*----------------------------------------------------------------
* p80211_metaname2did
*
* Traverses the metadata looking for an item whose name matches
* the given name.
*
* Arguments:
* metalist pointer to a category metadata list
* itemname buffer containing the name to search for.
*
* Returns:
* 0 - name not found
* ~0 - complete DID of item having "itemname"
----------------------------------------------------------------*/
UINT32 p80211_metaname2did(catlistitem_t *metalist, char *itemname)
{
UINT32 result = 0UL;
int sec;
int nsec;
int grp;
int ngrp;
int item;
int nitem;
/* traverse the entire metadata for the item that matches */
nsec = GETMETASIZE(metalist);
for ( sec = 1; (sec < nsec) && (result == 0); sec++) {
if ( metalist[sec].grplist == NULL ) continue;
ngrp = GETMETASIZE(metalist[sec].grplist);
for ( grp = 1; (grp < ngrp) && (result == 0); grp++) {
if ( metalist[sec].grplist[grp].itemlist == NULL ) continue;
nitem = GETMETASIZE(metalist[sec].grplist[grp].itemlist);
for (item = 1;(item < nitem) && (result == 0);item++) {
if ( strcmp(itemname, metalist[sec].grplist
[grp].itemlist[item].name) == 0 ) {
/* found it */
result = P80211DID_MKID( sec, grp, item, 0,0,0,0);
result |= metalist[sec].grplist
[grp].itemlist[item].did;
}
} /* for all items */
} /* for all groups */
} /* for all sections */
return result;
}

View file

@ -2356,68 +2356,5 @@ UINT32 msg_catlist_size = sizeof(msg_catlist)/sizeof(catlistitem_t);
/*================================================================*/
/* Local Function Declarations */
/*================================================================*/
/* Function Definitions */
/*----------------------------------------------------------------
* p80211item_getoffset
*
* Returns the offset of the data item identified by a given DID.
* This function assumes a valid did is passed to the function.
*
* Arguments:
* did a valid, complete DID
*
* Returns:
* 0xffffffff if the type from the did doesn't match a
* known type
* offset on success
----------------------------------------------------------------*/
UINT32 p80211item_getoffset( catlistitem_t *metalist, UINT32 did )
{
UINT32 offset;
UINT32 item;
INT i;
p80211meta_t *alist=NULL;
offset = 0UL;
if ( (p80211_isvalid_did(metalist, did )) != P80211DID_INVALID ) {
alist = metalist[P80211DID_SECTION(did)].
grplist[P80211DID_GROUP(did)].itemlist;
item = P80211DID_ITEM(did);
for ( i = 1; i < item; i++ ) {
/* when generating the offset, 8 is added to the
data len which represents the size of the did and
the len of each data item triple */
switch( P80211DID_TYPE(alist[i].did) ) {
case P80211_TYPE_OCTETSTR:
case P80211_TYPE_DISPLAYSTR:
/* add one for the pstr length byte */
offset += (8UL + alist[i].maxlen + 1UL);
break;
case P80211_TYPE_INT:
case P80211_TYPE_BOUNDEDINT:
case P80211_TYPE_ENUMINT:
/* all int types are 4 bytes */
offset += 12UL;
break;
case P80211_TYPE_UNKDATA:
offset += (8UL + alist[i].maxlen);
break;
default:
printf("Unknown data type of %lu\n",
P80211DID_TYPE(alist[i].did) );
offset = 0xffffffff;
break;
}
} /* for each arg meta data item */
} else {
offset = 0xffffffff;
}
return offset;
}

View file

@ -191,103 +191,6 @@ UINT32 p80211enum_int2text(p80211enum_t *ep, UINT32 val, char *text)
return result;
}
/*----------------------------------------------------------------
* p80211item_maxlen
*
* Returns the total maximum data size of an item identified
* by a given DID. This is the length of the data part of the
* item triple.
*
* Arguments:
* metalist pointer to a category metadata list
* did A complete DID
*
* Returns:
* 0xffffffff Bad DID or unrecognized type in metadata
* anything else success, return value is maxdatalen
----------------------------------------------------------------*/
UINT32 p80211item_maxdatalen( catlistitem_t *metalist, UINT32 did )
{
UINT32 maxlen;
p80211meta_t *meta;
if ( (meta = p80211_did2item(metalist, did)) != NULL ) {
switch( P80211DID_TYPE(did) ) {
case P80211_TYPE_OCTETSTR:
case P80211_TYPE_DISPLAYSTR:
/* add one for the pstr length byte */
maxlen = meta->maxlen + 1;
break;
case P80211_TYPE_INT:
case P80211_TYPE_BOUNDEDINT:
case P80211_TYPE_ENUMINT:
/* all int types are 4 bytes */
maxlen = 4;
break;
case P80211_TYPE_UNKDATA:
maxlen = meta->maxlen;
break;
default:
maxlen = 0xffffffffUL;
}
} else {
maxlen = 0xffffffffUL;
}
return maxlen;
}
/*----------------------------------------------------------------
* p80211_metaname2did
*
* Traverses the metadata looking for an item whose name matches
* the given name.
*
* Arguments:
* metalist pointer to a category metadata list
* itemname buffer containing the name to search for.
*
* Returns:
* 0 - name not found
* ~0 - complete DID of item having "itemname"
----------------------------------------------------------------*/
UINT32 p80211_metaname2did(catlistitem_t *metalist, char *itemname)
{
UINT32 result = 0UL;
int sec;
int nsec;
int grp;
int ngrp;
int item;
int nitem;
/* traverse the entire metadata for the item that matches */
nsec = GETMETASIZE(metalist);
for ( sec = 1; (sec < nsec) && (result == 0); sec++) {
if ( metalist[sec].grplist == NULL ) continue;
ngrp = GETMETASIZE(metalist[sec].grplist);
for ( grp = 1; (grp < ngrp) && (result == 0); grp++) {
if ( metalist[sec].grplist[grp].itemlist == NULL ) continue;
nitem = GETMETASIZE(metalist[sec].grplist[grp].itemlist);
for (item = 1;(item < nitem) && (result == 0);item++) {
if ( strcmp(itemname, metalist[sec].grplist
[grp].itemlist[item].name) == 0 ) {
/* found it */
result = P80211DID_MKID( sec, grp, item, 0,0,0,0);
result |= metalist[sec].grplist
[grp].itemlist[item].did;
}
} /* for all items */
} /* for all groups */
} /* for all sections */
return result;
}
/*----------------------------------------------------------------
* p80211_totext_displaystr
@ -317,6 +220,7 @@ void p80211_totext_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *itemb
p80211itemd_t *item = (p80211itemd_t*)itembuf;
p80211pstrd_t *pstr;
UINT8 *cstr;
INT n;
*textbuf = '\0';
@ -327,9 +231,13 @@ void p80211_totext_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *itemb
if ( item->did != 0UL ) {
cstr = pstr->data;
/* now, print to the textbuf */
sprintf( textbuf, "%s=\"%s\"", meta->name,
cstr);
sprintf( textbuf, "%s=", meta->name);
for ( n=0; n < pstr->len; n++ ) {
sprintf( &textbuf[strlen(textbuf)],
"%c", (UINT8)(cstr[n]) );
}
/* add end of string character */
textbuf[strlen(textbuf)] = '\0';
} else {
sprintf( textbuf, "%s=%s", meta->name,
NOT_SUPPORTED);
@ -398,7 +306,7 @@ void p80211_fromtext_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *ite
actual number of data bytes. NOTE: the '\0' of a display
string is included in the metadata maxlen */
item->len = meta->maxlen + 1;
item->len = p80211item_maxdatalen(metalist, item->did);
/* skip past the item name to its value before converting */
textbuf = strchr(textbuf, '=');
@ -408,8 +316,8 @@ void p80211_fromtext_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *ite
textbuf++;
if ( strlen(textbuf) < meta->maxlen ) {
/* INCLUDE the '\0' in the pstr length */
pstr->len = strlen(textbuf) + 1;
strcpy( pstr->data, textbuf);
pstr->len = strlen(textbuf);
strncpy( pstr->data, textbuf, pstr->len);
item->status =
P80211ENUM_msgitem_status_data_ok;
} else {
@ -419,12 +327,11 @@ void p80211_fromtext_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *ite
}
} else {
/* bogus text string, set the item to an empty string */
pstr->len = 1;
pstr->data[0] = '\0';
pstr->len = 0;
item->status = P80211ENUM_msgitem_status_missing_itemdata;
}
} else {
pstr->len = 1;
pstr->len = 0;
pstr->data[0] = '\0';
item->did = did;
item->len = pstr->len + 1;
@ -603,7 +510,7 @@ void p80211_fromtext_octetstr( catlistitem_t *metalist, UINT32 did, UINT8 *itemb
actual number of data bytes. NOTE: the '\0' of a display
string is included in the metadata maxlen */
item->len = meta->maxlen + 1;
item->len = p80211item_maxdatalen(metalist, item->did);
/* skip past the item name to its value before converting */
textbuf = strchr(textbuf, '=');
@ -797,7 +704,7 @@ void p80211_fromtext_boundedint( catlistitem_t *metalist, UINT32 did, UINT8 *ite
if ( (meta = p80211_did2item(metalist, did)) != NULL ) {
/* set the DID and OR in the partial DID for safety */
item->did = did | meta->did;
item->len = sizeof(UINT32);
item->len = p80211item_maxdatalen(metalist, item->did);
/* skip past the item name to its value before converting */
textbuf = strchr(textbuf, '=');
@ -963,7 +870,7 @@ void p80211_fromtext_int( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, c
/* set the DID and OR in the partial DID for safety */
item->did = did | meta->did;
item->len = sizeof(int);
item->len = p80211item_maxdatalen(metalist, item->did);
/* skip past the item name to its value before converting */
textbuf = strchr(textbuf, '=');
@ -1156,7 +1063,7 @@ void p80211_fromtext_enumint( catlistitem_t *metalist, UINT32 did, UINT8 *itembu
/* set the DID and OR in the partial DID for safety */
item->did = did | meta->did;
item->len = sizeof(UINT32);
item->len = p80211item_maxdatalen(metalist, item->did);
/* skip past the item name to its value before converting */
textbuf = strchr(textbuf, '=');
@ -1470,7 +1377,7 @@ void p80211_fromtext_getmibattribute( catlistitem_t *metalist, UINT32 did, UINT8
/* set the DID (OR in the partial DID for safety)
and set the length */
item->did = did | meta->did;
item->len = meta->maxlen;
item->len = p80211item_maxdatalen(metalist, item->did);
/* collect the mib item name */
textbuf = strchr(textbuf, '=');
@ -1493,7 +1400,10 @@ void p80211_fromtext_getmibattribute( catlistitem_t *metalist, UINT32 did, UINT8
item= (p80211itemd_t *)(item->data);
item->did = mibdid;
if ( mibmeta-> maxlen > 0 ) {
item->len = mibmeta->maxlen;
item->len =
p80211item_maxdatalen(
mib_catlist,
item->did);
} else {
item->len = 4;
}
@ -1570,7 +1480,7 @@ void p80211_fromtext_setmibattribute( catlistitem_t *metalist, UINT32 did, UINT8
/* set the DID (OR in the partial DID for safety)
and set the length */
item->did = did | meta->did;
item->len = meta->maxlen;
item->len = p80211item_maxdatalen(metalist, item->did);
/* collect the mib item name */
textbuf = strchr(textbuf, '=');