p80211types.c
来自「Linux的无线局域网方案是一个Linux设备驱动程序和子系统 一揽子方案的用」· C语言 代码 · 共 2,432 行 · 第 1/5 页
C
2,432 行
* p80211_fromtext_setmibattribute** 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 "mibset" 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. If message is "mibset", then the mib value is* coverted from text and stored after the DID and LEN----------------------------------------------------------------*/void p80211_fromtext_setmibattribute( 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 */ meta = p80211_did2item(metalist, did); if (meta == NULL) { item->did = did; item->len = 4; *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_invalid_msg_did; return; } /* 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; /* set the '=' between mib name and mib value to end of string character for call to metaname2did */ textbuf = strchr(textbuf, '='); if (textbuf == NULL) { *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_incomplete_itemdata; return; } *textbuf = '\0'; /* get DID of mib item based on mib name */ mibdid = p80211_metaname2did(mib_catlist,mibstr); if (mibdid == 0UL) { *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_invalid_mib_did; return; } /* put '=' back for call to mib's fromtext function */ *textbuf = '='; mibmeta = p80211_did2item(mib_catlist, mibdid); if (mibmeta == NULL) { *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_invalid_mib_did; return; } if (mibmeta->fromtextptr == NULL) { *((UINT32 *)(item->data)) = 0UL; item->status = P80211ENUM_msgitem_status_missing_conv_func; return; } (*(mibmeta->fromtextptr)) (mib_catlist, mibdid, item->data, mibstr); item->status = ((p80211itemd_t *)(item->data))->status; return;}/*----------------------------------------------------------------* p80211_isvalid_getmibattribute** This function checks the validity of the data portion of the* mibattribute DID-LEN-DATA triple. 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, so it's this* "data" that is actually checked for validity.** 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_getmibattribute( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf ){ UINT32 result = 0; p80211meta_t *msgmeta = NULL; p80211meta_t *mibmeta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211itemd_t *mibitem; if ( item->status == P80211ENUM_msgitem_status_data_ok ) { if ( (msgmeta = p80211_did2item(metalist, did)) != NULL ) { /* set up the pointers */ mibitem = (p80211itemd_t *)(item->data); if ( (mibmeta = p80211_did2item(mib_catlist, mibitem->did)) != NULL ) { result = 1; } else { item->status = P80211ENUM_msgitem_status_invalid_mib_did; } } else { item->status = P80211ENUM_msgitem_status_invalid_msg_did; } } return result;}/*----------------------------------------------------------------* p80211_isvalid_setmibattribute** This function checks the validity of the data portion of the* mibattribute DID-LEN-DATA triple. 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, so it's this* "data" that is actually checked for validity.** 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_setmibattribute( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf ){ UINT32 result = 0; p80211meta_t *msgmeta = NULL; p80211meta_t *mibmeta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211itemd_t *mibitem; if ( item->status == P80211ENUM_msgitem_status_data_ok ) { if ( (msgmeta = p80211_did2item(metalist, did)) != NULL ) { /* set up the pointers */ mibitem = (p80211itemd_t *)(item->data); if ( (mibmeta = p80211_did2item(mib_catlist, mibitem->did)) != NULL ) { /* call the valid function for the mib */ if ( mibmeta->validfunptr != NULL ) { if ( (*(mibmeta->validfunptr)) (mib_catlist, mibitem->did, (UINT8 *)mibitem) ) { result = 1; } else if ( (mibitem->status) != P80211ENUM_msgitem_status_data_ok ) { item->status = mibitem->status; } } else { item->status = P80211ENUM_msgitem_status_missing_valid_func; } } else { item->status = P80211ENUM_msgitem_status_invalid_mib_did; } } else { item->status = P80211ENUM_msgitem_status_invalid_msg_did; } } return result;}/*----------------------------------------------------------------* p80211_totext_intarray** UINT32[] ==> %d,%d,%d,...** Converts an array of UINT32's to a comma-separated list. The number* of array elements is taken from the "maxlen" field of the DID metadata.** 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 value to the buffer pointed at by* textbuf.----------------------------------------------------------------*/void p80211_totext_intarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta; p80211itemd_t *item; UINT32 *data; int i; char *buf, error_msg[MSG_BUFF_LEN]; *textbuf = '\0'; item = (p80211itemd_t *) itembuf; data = (UINT32 *) item->data; meta = p80211_did2item(metalist, did); if (meta == NULL) { p80211_error2text(P80211ENUM_msgitem_status_invalid_msg_did, error_msg); sprintf(textbuf, "0x%08lx=\"%s\"", did, error_msg); return; } if (item->status != P80211ENUM_msgitem_status_data_ok) { p80211_error2text(item->status, error_msg); sprintf(textbuf, "%s=\"%s\"", meta->name, error_msg); return; } if (item->did == 0UL) { sprintf(textbuf, "%s=%s", meta->name, NOT_SUPPORTED); return; } buf = textbuf + sprintf(textbuf, "%s=", meta->name); for (i = 0; i < meta->maxlen; i++) buf += sprintf(buf, (i == 0) ? "%lu" : ",%lu", data[i]); return;}/*----------------------------------------------------------------* p80211_fromtext_intarray** %d,%d,%d,... ==> UINT32[]** Converts a C string containing the "<item name>=<value>,<value>,..." format* to a wlan data item triple. The "values" must be integers. The number* of array elements is taken from the "maxlen" field of the DID metadata.* There must be at least 1 element in the array.** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf (out) item triple {DID, len, value}.* textbuf character buffer containing textual representation.** Returns: * nothing** Side effects:* Writes the converted value to the buffer pointed at by* itembuf.----------------------------------------------------------------*/void p80211_fromtext_intarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta; p80211itemd_t *item; UINT32 *data; int cnt; char *buf, *end, dlm; item = (p80211itemd_t *) itembuf; data = (UINT32 *) item->data; meta = p80211_did2item(metalist, did); if (meta == NULL) { item->did = did; item->len = sizeof(int); item->status = P80211ENUM_msgitem_status_invalid_itemname; return; } /* ** 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. The ** delimiter will be '='. */ dlm = '='; buf = strchr(textbuf, dlm); if (buf == NULL) { memset(data, 0, item->len); item->status = P80211ENUM_msgitem_status_missing_itemdata; return; } /* ** Keep reading array elements... */ cnt = 0; while (1) { /* ** If we're not pointing at the delimiter, then something went ** wrong. Note that the first delimiter will be '=' and all ** subsequent delimiters will be ','. Skip past the delimiter ** and any following whitespace. */ if (*buf != dlm) goto invalid; dlm = ','; buf++; buf += strspn(buf, " \t\n\r\f\v"); /* ** Quit if we now have all array elements. */ if (cnt >= meta->maxlen) break; /* ** Get the next array element. Make sure that at least ** something was found (i.e. end != buf). Skip any trailing ** whitespace. This should leave us at either the next ',' or ** at '\0'. */ data[cnt] = strtol(buf, &end, 10); if (end == buf) goto invalid; cnt++; buf = end + strspn(end, " \t\n\r\f\v"); } /* ** Make sure there is no left-over stuff at the end of the sting. */ if (*buf != '\0') goto invalid; item->status = P80211ENUM_msgitem_status_data_ok; return;invalid: memset(data, 0, item->len); item->status = P80211ENUM_msgitem_status_invalid_itemdata; return;}/*----------------------------------------------------------------* p80211_isvalid_intarray** Tests an item triple for valid range. Uses the validation* information in the metadata. All values are valid, so this * function always returns success.** 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_intarray( 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 ) { /* since integers aren't bounded, there's nothing to check */ result = 1; } else { item->status = P80211ENUM_msgitem_status_invalid_did; } } return result;}/*----------------------------------------------------------------* p80211_totext_bitarray** UINT32 ==> %d,%d,%d,...** Converts the first "maxlen" bits of a UINT32 to a comma-separated list* of bit numbers of the bits which are set. Other bits are ignored.** 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 value to the buffer pointed at by* textbuf.----------------------------------------------------------------*/void p80211_totext_bitarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta; p80211itemd_t *item; UINT32 array; int found, i; char *buf, error_msg[MSG_BUFF_LEN]; *textbuf = '\0'; item = (p80211itemd_t *) itembuf; meta = p80211_did2item(metalist, did); if (meta == NULL) { p80211_error2text(P80211ENUM_msgitem_status_invalid_msg_did, error_msg); sprintf(textbuf, "0x%08lx=\"%s\"", did, error_msg); return; } if (item->status != P80211ENUM_msgitem_status_data_ok) { p80211_error2text(item->status, error_msg); sprintf(textbuf, "%s=\"%s\"", meta->name, error_msg); return; } if (item->did == 0UL) { sprintf(textbuf, "%s=%s", meta->name, NOT_SUPPORTED); return; } array = *((UINT32 *) item->data);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?