p80211types.c
来自「Linux的无线局域网方案是一个Linux设备驱动程序和子系统 一揽子方案的用」· C语言 代码 · 共 2,432 行 · 第 1/5 页
C
2,432 行
* textbuf (out) character buffer to receive textual* representation.** Returns: * nothing** Side effects:* Writes the converted value to the buffer pointed at by* textbuf.----------------------------------------------------------------*/void p80211_totext_enumint( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211enumpair_t *enumlist = NULL; INT nitems; INT n; INT found; *textbuf = '\0'; /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { if ( item->status == P80211ENUM_msgitem_status_data_ok ) { nitems = meta->enumptr->nitems; enumlist = meta->enumptr->list; if ( item->did != 0UL ) { for ( n=0, found = 0; (!found) && (n < nitems); n++ ) { if ( enumlist[n].val == (*((UINT32 *)(item->data))) ) { /* now, print the data item name and enum text value into textbuf */ sprintf( textbuf, "%s=%s", meta->name, enumlist[n].name ); found = 1; } } if ( !found ) { char error_msg[MSG_BUFF_LEN]; p80211_error2text( P80211ENUM_msgitem_status_invalid_itemdata, error_msg); sprintf( textbuf, "%s=\"%s\"", meta->name, error_msg); } } else { sprintf( textbuf, "%s=%s", meta->name, NOT_SUPPORTED); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( item->status, error_msg); sprintf( textbuf, "%s=\"%s\"", meta->name, error_msg); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( P80211ENUM_msgitem_status_invalid_msg_did, error_msg); sprintf( textbuf, "0x%08lx=\"%s\"", did, error_msg); } return;}/*----------------------------------------------------------------* p80211_fromtext_enumint** <valuename> ==> UINT32** Converts a C string containing the "<item name>=<item value>" format* to a wlan data item triple.** The C string format is always "<item name>=<item value>".** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf (out>item triple {DID, len, value}.* textbuf character buffer to receive textual* representation.** Returns: * nothing** Side effects:* Writes the converted value to the buffer pointed at by* itembuf.----------------------------------------------------------------*/void p80211_fromtext_enumint( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211enumpair_t *enumlist = NULL; INT nitems; INT n; INT found; /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { nitems = meta->enumptr->nitems; enumlist = meta->enumptr->list; /* set the DID and OR in the partial DID for safety */ item->did = did | meta->did; item->len = p80211item_maxdatalen(metalist, item->did); /* skip past the item name to its value before converting */ textbuf = strchr(textbuf, '='); if ( textbuf != NULL ) { /* OK, got the '=', bump to the next */ textbuf++; for ( n=0, found = 0; (!found) && (n < nitems); n++ ) { if ( strcmp(enumlist[n].name, textbuf) == 0 ) { *((UINT32 *)(item->data)) = enumlist[n].val; item->status = P80211ENUM_msgitem_status_data_ok; found = 1; } } if ( !found ) { *((UINT32 *)(item->data)) = P80211ENUM_BAD; item->status = P80211ENUM_msgitem_status_invalid_itemdata; } } else { /* bogus text string, set the item data value to zero */ *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_missing_itemdata; } } else { item->did = did; item->len = sizeof(UINT32); item->status = P80211ENUM_msgitem_status_invalid_itemname; } return;}/*----------------------------------------------------------------* p80211_isvalid_enumint** Tests an item triple for valid range. Uses the validation* information in the metadata. Enumint's are validated against* their enumeration structure.** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf item triple {DID, len, value}.** Returns: * 0 - data in itembuf is invalid* ~0 - data in itembuf is valid----------------------------------------------------------------*/UINT32 p80211_isvalid_enumint( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf ){ UINT32 result = 0; p80211meta_t *meta; p80211itemd_t *item = (p80211itemd_t*)itembuf; if ( item->status == P80211ENUM_msgitem_status_data_ok ) { /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { if ( (*((UINT32 *)(item->data))) != P80211ENUM_BAD ) { result = 1; } else { item->status = P80211ENUM_msgitem_status_invalid_itemdata; } } else { item->status = P80211ENUM_msgitem_status_invalid_did; } } return result;}/*----------------------------------------------------------------* p80211_totext_getmibattribute** Converts the mibattribute of a "mibget" message into* a text string. The DATA portion of the mibattribute's* "DID-LEN-DATA" triple is itself a "DID-LEN-DATA" triple storing* the mib item's did, length and data. In other words:** DID-LEN-DATA* ^* |__________ where DATA = DID-LEN-DATA for a MIB Item** If message text format is:* "mibattribute=<mibitemname>=<mibvalue>"** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf item triple {DID, len, value}.* textbuf (out) character buffer to receive textual* representation.** Returns: * nothing** Side effects:* Writes the converted mib value to the buffer pointed at by* textbuf.----------------------------------------------------------------*/void p80211_totext_getmibattribute( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ char tmpbuf[MSG_BUFF_LEN]; UINT32 mibdid; p80211meta_t *meta = NULL; p80211meta_t *mibmeta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; *textbuf = '\0'; /* get the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { if ( item->status == P80211ENUM_msgitem_status_data_ok ) { mibdid = *((UINT32 *)(item->data)); if ( (mibmeta = p80211_did2item(mib_catlist,mibdid)) != NULL ) { if ( item->did != 0UL ) { if ( mibmeta->totextptr != NULL) { (*(mibmeta->totextptr)) (mib_catlist, mibdid, item->data, tmpbuf); /* now, print to the textbuf */ sprintf( textbuf, "%s=%s",meta->name, tmpbuf); } else { sprintf( textbuf, "%s=%s=%s", meta->name, mibmeta->name, NOT_SUPPORTED); } } else { sprintf( textbuf, "%s=%s=%s", meta->name, mibmeta->name, NOT_SUPPORTED); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( P80211ENUM_msgitem_status_invalid_mib_did, error_msg); sprintf( textbuf, "0x%08lx=\"%s\"", mibdid, error_msg); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( item->status, error_msg); sprintf( textbuf, "%s=\"%s\"", meta->name, error_msg); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( P80211ENUM_msgitem_status_invalid_msg_did, error_msg); sprintf( textbuf, "0x%08lx=\"%s\"", did, error_msg); } return;}/*----------------------------------------------------------------* p80211_totext_setmibattribute** Converts the mibattribute of a "mibset" message into* a text string. The DATA portion of the mibattribute's* "DID-LEN-DATA" triple is itself a "DID-LEN-DATA" triple storing* the mib item's did, length and data. In other words:** DID-LEN-DATA* ^* |__________ where DATA = DID-LEN-DATA for a MIB Item** If message text format is:* "mibattribute=<mibitemname>=<mibvalue>"** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf item triple {DID, len, value}.* textbuf (out) character buffer to receive textual* representation.** Returns: * nothing** Side effects:* Writes the converted mib value to the buffer pointed at by* textbuf.----------------------------------------------------------------*/void p80211_totext_setmibattribute( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ char tmpbuf[MSG_BUFF_LEN]; UINT32 mibdid; p80211meta_t *meta = NULL; p80211meta_t *mibmeta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; *textbuf = '\0'; /* get the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { if ( item->status == P80211ENUM_msgitem_status_data_ok ) { mibdid = *((UINT32 *)(item->data)); if ( (mibmeta = p80211_did2item(mib_catlist,mibdid)) != NULL ) { if ( item->did != 0UL ) { if ( mibmeta->totextptr != NULL) { (*(mibmeta->totextptr)) (mib_catlist, mibdid, item->data, tmpbuf); /* now, print to the textbuf */ sprintf( textbuf, "%s=%s",meta->name, tmpbuf); } else { sprintf( textbuf, "%s=%s=%s", meta->name, mibmeta->name, NOT_SUPPORTED); } } else { sprintf( textbuf, "%s=%s=%s", meta->name, mibmeta->name, NOT_SUPPORTED); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( P80211ENUM_msgitem_status_invalid_mib_did, error_msg); sprintf( textbuf, "0x%08lx=\"%s\"", mibdid, error_msg); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( item->status, error_msg); sprintf( textbuf, "%s=\"%s\"", meta->name, error_msg); } } else { char error_msg[MSG_BUFF_LEN]; p80211_error2text( P80211ENUM_msgitem_status_invalid_msg_did, error_msg); sprintf( textbuf, "0x%08lx=\"%s\"", did, error_msg); } return;}/*----------------------------------------------------------------* p80211_fromtext_getmibattribute** If message is mibget, then the text format is:* "mibattribute=<mibitemname>"* If message is mibset, then the text format is:* "mibattribute=<mibitemname>=<mibvalue>"** Takes the mibattribute argument of a "mibget" message, and coverts* the mib item name into a mib DID and converts the mib's value.** The DATA portion of the mibattribute's "DID-LEN-DATA" triple is* itself a "DID-LEN-DATA" triple storing the mib item's did, length* and data. In other words:** DID-LEN-DATA* ^* |__________ where DATA = DID-LEN-DATA for a MIB Item** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf (out>item triple {DID, len, value}.* textbuf character buffer to receive textual* representation.** Returns: * nothing** Side effects:* Writes the MIB DID to the buffer pointed at by* itembuf.----------------------------------------------------------------*/void p80211_fromtext_getmibattribute( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta; p80211meta_t *mibmeta; p80211itemd_t *item = (p80211itemd_t*)itembuf; char *mibstr; UINT32 mibdid; /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { /* set the DID (OR in the partial DID for safety) and set the length */ item->did = did | meta->did; item->len = p80211item_maxdatalen(metalist, item->did); /* collect the mib item name */ textbuf = strchr(textbuf, '='); if ( textbuf == NULL ) { *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_missing_itemdata; return; } textbuf++; mibstr = textbuf; /* get DID of mib item based on mib name */ mibdid = p80211_metaname2did(mib_catlist,mibstr); if ( mibdid != 0UL ) { if ( (mibmeta = p80211_did2item(mib_catlist, mibdid)) != NULL ) { item= (p80211itemd_t *)(item->data); item->did = mibdid; if ( mibmeta-> maxlen > 0 ) { item->len = p80211item_maxdatalen( mib_catlist, item->did); } else { item->len = 4; } *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_data_ok; } else { item->status = P80211ENUM_msgitem_status_invalid_mib_did; *((UINT32 *)(item->data)) = 0UL; return; } } else { item->status = P80211ENUM_msgitem_status_invalid_mib_did; *((UINT32 *)(item->data)) = 0UL; return; } } else { item->did = did; item->len = 4; *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_invalid_itemname; } return;}/*----------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?