?? p80211types.c
字號:
/* src/shared/p80211types.c** Defines globally used types in linux-wlan** Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.* --------------------------------------------------------------------** linux-wlan** The contents of this file are subject to the Mozilla Public* License Version 1.1 (the "License"); you may not use this file* except in compliance with the License. You may obtain a copy of* the License at http://www.mozilla.org/MPL/** Software distributed under the License is distributed on an "AS* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** Alternatively, the contents of this file may be used under the* terms of the GNU Public License version 2 (the "GPL"), in which* case the provisions of the GPL are applicable instead of the* above. If you wish to allow the use of your version of this file* only under the terms of the GPL and not to allow others to use* your version of this file under the MPL, indicate your decision* by deleting the provisions above and replace them with the notice* and other provisions required by the GPL. If you do not delete* the provisions above, a recipient may use your version of this* file under either the MPL or the GPL.** --------------------------------------------------------------------** Inquiries regarding the linux-wlan Open Source project can be* made directly to:** AbsoluteValue Systems Inc.* info@linux-wlan.com* http://www.linux-wlan.com** --------------------------------------------------------------------** Portions of the development of this software were funded by * Intersil Corporation as part of PRISM(R) chipset product development.** --------------------------------------------------------------------** This file defines the data and functions for handling the linux-wlan* globally recognized data types: OCTETSTR, DISPLAYSTR, INT, BOUNDEDINT,* ENUMINT, INTARRAY, BITARRY, and MACARRAY.** For each type there is a collection of 3 functions, totext_<type>,* fromtext_<type>, and isvalid_<type>. They all have identical* signatures:** void p80211_totext_<type>( UINT32 did, UINT8 *itembuf, char *textbuf )* void p80211_fromtext_<type>( UINT32 did, UINT8 *itembuf, char *textbuf )* UINT32 p80211_isvalid_<type>( UINT32 did, UINT8 *itembuf )** The idea is that these functions will be called via pointers stored* in the metadata for each item.* Here are some important notes for these functions:* - all of these functions assume:* - a valid complete DID as the first argument* - (for to/fromtext) a valid pointer to a buffer containing * sufficient memory.* - All textual representations are "<itemname>=<itemvalue>"* - All itembufs are pointing to a p80211item_t* - isvalid functions return:* 0 if item is invalid* non-zero if item is valid** NOTE: these functions assume that the argument "itembuf" is a* data item and whose data field is always the maximum data* size (i.e. a PSTR255) with the exception of a collection.* In the case of a collection, the itembuf argument is a* pointer to a collection data item where the data value field* is itself a list of data items.*** Additionally, there are functions for converting enumeration values* from text to binary and back.* --------------------------------------------------------------------*//*================================================================*//* System Includes */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>/*================================================================*//* Project Includes */#include <wlan/wlan_compat.h>#include <wlan/p80211types.h>#include <wlan/p80211meta.h>#include <wlan/p80211metamib.h>#include <wlan/p80211msg.h>/*================================================================*//* Local Constants *//*================================================================*//* Local Macros *//* the following depends on the following defines: P80211_NOINCLUDESTRINGS - ifdef, all metadata name fields are empty strings */#define MKENUM(name) \p80211enum_t MKENUMNAME(name) = \{ \sizeof((p80211enumpair_ ## name)) / sizeof(p80211enumpair_t), \(p80211enumpair_ ## name) \}#ifdef P80211_NOINCLUDESTRINGS#define MKENUMPAIR(n,s) { (n), ("") }#else#define MKENUMPAIR(n,s) { (n), (s) }#endif#define MKENUMPAIRLIST(name) p80211enumpair_t p80211enumpair_ ## name [] =/*================================================================*//* Local Types *//*================================================================*//* Local Static Definitions *//* too much data in this file, we moved to the bottom for readability *//*================================================================*//* Local Function Declarations *//*================================================================*//* Function Definitions *//*----------------------------------------------------------------* p80211enum_text2int** Returns the numeric value of an enum item given its textual* name and a ptr to the enum struct.** Arguments:* ep ptr to enum metadata* text textual enum item name** Returns: * P80211_ENUMBAD no match on name* !P80211_ENUMBAD success, return value is enum value----------------------------------------------------------------*/UINT32 p80211enum_text2int(p80211enum_t *ep, char *text){ UINT32 result = P80211ENUM_BAD; int i; for ( i = 0; i < ep->nitems; i++ ) { if ( strcmp(text, ep->list[i].name ) == 0 ) { result = ep->list[i].val; break; } } return result;}/*----------------------------------------------------------------* p80211enum_int2text** Fills a buffer with the name string for a given integer * quantity and a ptr to the enum struct.** Arguments:* ep ptr to enum metadata* val integer value to convert* text (out)buffer to write enum name to** Returns: * P80211_ENUMBAD no match on number* !P80211_ENUMBAD success** Side effects:* Argument 'text' is filled with the textual name of the* enum value. If the lookup fails, 'text' is set to the* string P80211ENUM_BADSTR----------------------------------------------------------------*/UINT32 p80211enum_int2text(p80211enum_t *ep, UINT32 val, char *text){ UINT32 result = P80211ENUM_BAD; int i; strcpy(text, P80211ENUM_BADSTR); for ( i = 0; i < ep->nitems; i++) { if ( ep->list[i].val == val ) { strcpy( text, ep->list[i].name ); result = val; break; } } return result;}/*----------------------------------------------------------------* p80211_totext_displaystr** pstr ==> cstr ** Converts a pascal string to a C string appropriate for display.* The C string format is always "<item name>=<item value>".** 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_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211pstrd_t *pstr; *textbuf = '\0'; if ( (meta = p80211_did2item(metalist, did)) != NULL ) { /* collect the C string stored in the data item */ if ( item->status == P80211ENUM_msgitem_status_data_ok ) { pstr = (p80211pstrd_t*)item->data; if ( item->did != 0UL ) { sprintf( textbuf, "%s=\'", meta->name); strncat( textbuf, pstr->data, pstr->len); strncat( textbuf, "\'", 1); } 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%08x=\"%s\"", did, error_msg); } return;}/*----------------------------------------------------------------* p80211_fromtext_displaystr** cstr ==> pstr** 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_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211pstrd_t *pstr; int len; /* set up the pascal string pointer, i.e. the display str data item */ pstr = (p80211pstrd_t*)item->data; /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { /* set the DID and OR in the partial DID for safety */ item->did = did | meta->did; /* adding 1 to the metadata maxlen takes into account the first byte of the pascal string containing the actual number of data bytes. NOTE: the '\0' of a display string is included in the metadata maxlen */ 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++; len = strlen(textbuf); if ( len > meta->maxlen ) { item->status = P80211ENUM_msgitem_status_string_too_long; } else if ( len < meta->minlen ) { item->status = P80211ENUM_msgitem_status_string_too_short; } else { pstr->len = len; strncpy( pstr->data, textbuf, len); item->status = P80211ENUM_msgitem_status_data_ok; } } else { /* bogus text string, set the item to an empty string */ pstr->len = 0; item->status = P80211ENUM_msgitem_status_missing_itemdata; } } else { pstr->len = 0; pstr->data[0] = '\0'; item->did = did; item->len = pstr->len + 1; item->status = P80211ENUM_msgitem_status_invalid_itemname; } return;}/*----------------------------------------------------------------* p80211_isvalid_displaystr** Tests an item triple for valid range. Uses the validation* information in the metadata. Displaystr's are validated for* length.** 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_displaystr( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf ){ UINT32 result = 0; p80211meta_t *meta; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211pstrd_t *pstr; if ( (item->status) == P80211ENUM_msgitem_status_data_ok ) { if ( (meta = p80211_did2item(metalist, did)) != NULL ) { /* set up the pointers */ pstr = (p80211pstrd_t*)item->data; if ( pstr->len < meta->minlen ) { item->status = P80211ENUM_msgitem_status_string_too_short; } else if ( pstr->len > meta->maxlen ) { item->status = P80211ENUM_msgitem_status_string_too_long; } else { result =1; } } else { item->status = P80211ENUM_msgitem_status_invalid_did; } } return result;}/*----------------------------------------------------------------* p80211_totext_octetstr** pstr ==> "xx:xx:..."** Converts a pascal string to a hex represenation of its contents.* The C string format is always "<item name>=<item value>".** 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_octetstr( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta = NULL; p80211itemd_t *item = (p80211itemd_t*)itembuf; p80211pstrd_t *pstr; UINT8 *cstr; INT len; INT n; *textbuf = '\0'; /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { if ( item->status == P80211ENUM_msgitem_status_data_ok ) { /* collect the C string stored in the data item */ pstr = (p80211pstrd_t*)item->data; if ( item->did != 0UL ) { len = pstr->len; cstr = pstr->data; sprintf( textbuf, "%s=", meta->name); for ( n=0; n < len; n++ ) { sprintf( &textbuf[strlen(textbuf)], "%02x:", (UINT)(cstr[n]) ); } /* get rid of trailing colon */ textbuf[strlen(textbuf) - 1] = '\0'; } 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%08x=\"%s\"", did, error_msg); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -