xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/include/bcmtlv.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * TLV and XTLV support
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 1999-2017, Broadcom Corporation
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      Unless you and Broadcom execute a separate written software license
9*4882a593Smuzhiyun  * agreement governing use of this software, this software is licensed to you
10*4882a593Smuzhiyun  * under the terms of the GNU General Public License version 2 (the "GPL"),
11*4882a593Smuzhiyun  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12*4882a593Smuzhiyun  * following added to such license:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *      As a special exception, the copyright holders of this software give you
15*4882a593Smuzhiyun  * permission to link this software with independent modules, and to copy and
16*4882a593Smuzhiyun  * distribute the resulting executable under terms of your choice, provided that
17*4882a593Smuzhiyun  * you also meet, for each linked independent module, the terms and conditions of
18*4882a593Smuzhiyun  * the license of that module.  An independent module is a module which is not
19*4882a593Smuzhiyun  * derived from this software.  The special exception does not apply to any
20*4882a593Smuzhiyun  * modifications of the software.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  *      Notwithstanding the above, under no circumstances may you combine this
23*4882a593Smuzhiyun  * software in any way with any other Broadcom software provided under a license
24*4882a593Smuzhiyun  * other than the GPL, without Broadcom's express prior written consent.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * <<Broadcom-WL-IPTag/Open:>>
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * $Id: $
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifndef	_bcmtlv_h_
32*4882a593Smuzhiyun #define	_bcmtlv_h_
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #include <typedefs.h>
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #ifdef __cplusplus
37*4882a593Smuzhiyun extern "C" {
38*4882a593Smuzhiyun #endif /* __cplusplus */
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* begin tlvs - used in 802.11 IEs etc. */
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /* type(aka id)/length/value buffer triple */
43*4882a593Smuzhiyun typedef struct bcm_tlv {
44*4882a593Smuzhiyun 	uint8	id;
45*4882a593Smuzhiyun 	uint8	len;
46*4882a593Smuzhiyun 	uint8	data[1];
47*4882a593Smuzhiyun } bcm_tlv_t;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /* size of tlv including data */
50*4882a593Smuzhiyun #define BCM_TLV_SIZE(_tlv) ((_tlv) ? (OFFSETOF(bcm_tlv_t, data) + (_tlv)->len) : 0)
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /* get next tlv - no length checks */
53*4882a593Smuzhiyun #define BCM_TLV_NEXT(_tlv) (bcm_tlv_t *)((uint8 *)(_tlv)+ BCM_TLV_SIZE(_tlv))
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /* tlv length is restricted to 1 byte */
56*4882a593Smuzhiyun #define BCM_TLV_MAX_DATA_SIZE (255)
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /* tlv header - two bytes */
59*4882a593Smuzhiyun #define BCM_TLV_HDR_SIZE (OFFSETOF(bcm_tlv_t, data))
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /* Check that bcm_tlv_t fits into the given buffer len */
62*4882a593Smuzhiyun #define bcm_valid_tlv(elt, buflen) (\
63*4882a593Smuzhiyun 	 ((int)(buflen) >= (int)BCM_TLV_HDR_SIZE) && \
64*4882a593Smuzhiyun 	 ((int)(buflen) >= (int)(BCM_TLV_HDR_SIZE + (elt)->len)))
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /* type(aka id)/length/ext/value buffer */
67*4882a593Smuzhiyun typedef struct bcm_tlv_ext {
68*4882a593Smuzhiyun 	uint8	id;
69*4882a593Smuzhiyun 	uint8	len;
70*4882a593Smuzhiyun 	uint8	ext;
71*4882a593Smuzhiyun 	uint8	data[1];
72*4882a593Smuzhiyun } bcm_tlv_ext_t;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /* get next tlv_ext - no length checks */
75*4882a593Smuzhiyun #define BCM_TLV_EXT_NEXT(_tlv_ext) \
76*4882a593Smuzhiyun 	(bcm_tlv_ext_t *)((uint8 *)(_tlv_ext)+ BCM_TLV_EXT_SIZE(_tlv_ext))
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /* tlv_ext length is restricted to 1 byte */
79*4882a593Smuzhiyun #define BCM_TLV_EXT_MAX_DATA_SIZE (254)
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /* tlv_ext header - three bytes */
82*4882a593Smuzhiyun #define BCM_TLV_EXT_HDR_SIZE (OFFSETOF(bcm_tlv_ext_t, data))
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /* size of tlv_ext including data */
85*4882a593Smuzhiyun #define BCM_TLV_EXT_SIZE(_tlv_ext) (BCM_TLV_EXT_HDR_SIZE + (_tlv_ext)->len)
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /* find the next tlv */
88*4882a593Smuzhiyun bcm_tlv_t *bcm_next_tlv(const  bcm_tlv_t *elt, uint *buflen);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* move buffer/buflen up to the given tlv, or set to NULL/0 on error */
91*4882a593Smuzhiyun void bcm_tlv_buffer_advance_to(const bcm_tlv_t *elt, const uint8 **buffer, uint *buflen);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /* move buffer/buflen past the given tlv, or set to NULL/0 on error */
94*4882a593Smuzhiyun void bcm_tlv_buffer_advance_past(const bcm_tlv_t *elt, const uint8 **buffer, uint *buflen);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /* find the tlv for a given id */
97*4882a593Smuzhiyun bcm_tlv_t *bcm_parse_tlvs(const  void *buf, uint buflen, uint key);
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun  * Traverse tlvs and return pointer to the first tlv that
101*4882a593Smuzhiyun  * matches the key. Return NULL if not found or tlv len < min_bodylen
102*4882a593Smuzhiyun  */
103*4882a593Smuzhiyun bcm_tlv_t *bcm_parse_tlvs_min_bodylen(const  void *buf, int buflen, uint key, int min_bodylen);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /* parse tlvs for dot11 - same as parse_tlvs but supports 802.11 id extension */
106*4882a593Smuzhiyun bcm_tlv_t *bcm_parse_tlvs_dot11(const  void *buf, int buflen, uint key, bool id_ext);
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun /* same as parse_tlvs, but stops when found id > key */
109*4882a593Smuzhiyun const  bcm_tlv_t *bcm_parse_ordered_tlvs(const  void *buf, int buflen, uint key);
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /* find a tlv with DOT11_MNG_PROPR_ID as id, and the given oui and type */
112*4882a593Smuzhiyun 	bcm_tlv_t *bcm_find_vendor_ie(const  void *tlvs, uint tlvs_len, const char *voui,
113*4882a593Smuzhiyun 	                              uint8 *type, uint type_len);
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /* write tlv at dst and return next tlv ptr */
116*4882a593Smuzhiyun uint8 *bcm_write_tlv(int type, const void *data, int datalen, uint8 *dst);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /* write tlv_ext at dst and return next tlv ptr */
119*4882a593Smuzhiyun uint8 *bcm_write_tlv_ext(uint8 type, uint8 ext, const void *data, uint8 datalen, uint8 *dst);
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /* write tlv at dst if space permits and return next tlv ptr */
122*4882a593Smuzhiyun uint8 *bcm_write_tlv_safe(int type, const void *data, int datalen, uint8 *dst,
123*4882a593Smuzhiyun 	int dst_maxlen);
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /* copy a tlv  and return next tlv ptr */
126*4882a593Smuzhiyun uint8 *bcm_copy_tlv(const void *src, uint8 *dst);
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun /* copy a tlv if space permits and return next tlv ptr */
129*4882a593Smuzhiyun uint8 *bcm_copy_tlv_safe(const void *src, uint8 *dst, int dst_maxlen);
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /* end tlvs */
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* begin xtlv - used for iovars, nan attributes etc. */
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun /* bcm type(id), length, value with w/16 bit id/len. The structure below
136*4882a593Smuzhiyun  * is nominal, and is used to support variable length id and type. See
137*4882a593Smuzhiyun  * xtlv options below.
138*4882a593Smuzhiyun  */
139*4882a593Smuzhiyun typedef struct bcm_xtlv {
140*4882a593Smuzhiyun 	uint16	id;
141*4882a593Smuzhiyun 	uint16	len;
142*4882a593Smuzhiyun 	uint8	data[1];
143*4882a593Smuzhiyun } bcm_xtlv_t;
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun /* xtlv options */
146*4882a593Smuzhiyun #define BCM_XTLV_OPTION_NONE	0x0000
147*4882a593Smuzhiyun #define BCM_XTLV_OPTION_ALIGN32	0x0001 /* 32bit alignment of type.len.data */
148*4882a593Smuzhiyun #define BCM_XTLV_OPTION_IDU8	0x0002 /* shorter id */
149*4882a593Smuzhiyun #define BCM_XTLV_OPTION_LENU8	0x0004 /* shorted length */
150*4882a593Smuzhiyun #define BCM_XTLV_OPTION_IDBE	0x0008 /* big endian format id */
151*4882a593Smuzhiyun #define BCM_XTLV_OPTION_LENBE	0x0010 /* big endian format length */
152*4882a593Smuzhiyun typedef uint16 bcm_xtlv_opts_t;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /* header size. depends on options. Macros names ending w/ _EX are where
155*4882a593Smuzhiyun  * options are explcitly specified that may be less common. The ones
156*4882a593Smuzhiyun  * without use default values that correspond to ...OPTION_NONE
157*4882a593Smuzhiyun  */
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /* xtlv header size depends on options */
160*4882a593Smuzhiyun #define BCM_XTLV_HDR_SIZE 4
161*4882a593Smuzhiyun #define BCM_XTLV_HDR_SIZE_EX(_opts) bcm_xtlv_hdr_size(_opts)
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun /* note: xtlv len only stores the value's length without padding */
164*4882a593Smuzhiyun #define BCM_XTLV_LEN(_elt) ltoh16_ua(&(_elt)->len)
165*4882a593Smuzhiyun #define BCM_XTLV_LEN_EX(_elt, _opts) bcm_xtlv_len(_elt, _opts)
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun #define BCM_XTLV_ID(_elt) ltoh16_ua(&(_elt)->id)
168*4882a593Smuzhiyun #define BCM_XTLV_ID_EX(_elt, _opts) bcm_xtlv_id(_elt, _opts)
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /* entire size of the XTLV including header, data, and optional padding */
171*4882a593Smuzhiyun #define BCM_XTLV_SIZE(elt, opts) bcm_xtlv_size(elt, opts)
172*4882a593Smuzhiyun #define BCM_XTLV_SIZE_EX(_elt, _opts) bcm_xtlv_size(_elt, _opts)
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun /* max xtlv data size */
175*4882a593Smuzhiyun #define BCM_XTLV_MAX_DATA_SIZE 65535
176*4882a593Smuzhiyun #define BCM_XTLV_MAX_DATA_SIZE_EX(_opts) ((_opts & BCM_XTLV_OPTION_LENU8) ? \
177*4882a593Smuzhiyun 	255 : 65535)
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /* descriptor of xtlv data, packing(src) and unpacking(dst) support  */
180*4882a593Smuzhiyun typedef struct {
181*4882a593Smuzhiyun 	uint16	type;
182*4882a593Smuzhiyun 	uint16	len;
183*4882a593Smuzhiyun 	void	*ptr; /* ptr to memory location */
184*4882a593Smuzhiyun } xtlv_desc_t;
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun /* xtlv buffer - packing/unpacking support */
187*4882a593Smuzhiyun struct bcm_xtlvbuf {
188*4882a593Smuzhiyun 	bcm_xtlv_opts_t opts;
189*4882a593Smuzhiyun 	uint16 size;
190*4882a593Smuzhiyun 	uint8 *head; /* point to head of buffer */
191*4882a593Smuzhiyun 	uint8 *buf; /* current position of buffer */
192*4882a593Smuzhiyun 	/* allocated buffer may follow, but not necessarily */
193*4882a593Smuzhiyun };
194*4882a593Smuzhiyun typedef struct bcm_xtlvbuf bcm_xtlvbuf_t;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun /* valid xtlv ? */
197*4882a593Smuzhiyun bool bcm_valid_xtlv(const bcm_xtlv_t *elt, int buf_len, bcm_xtlv_opts_t opts);
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun /* return the next xtlv element, and update buffer len (remaining). Buffer length
200*4882a593Smuzhiyun  * updated includes padding as specified by options
201*4882a593Smuzhiyun  */
202*4882a593Smuzhiyun bcm_xtlv_t *bcm_next_xtlv(const bcm_xtlv_t *elt, int *buf_len, bcm_xtlv_opts_t opts);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /* initialize an xtlv buffer. Use options specified for packing/unpacking using
205*4882a593Smuzhiyun  * the buffer. Caller is responsible for allocating both buffers.
206*4882a593Smuzhiyun  */
207*4882a593Smuzhiyun int bcm_xtlv_buf_init(bcm_xtlvbuf_t *tlv_buf, uint8 *buf, uint16 len,
208*4882a593Smuzhiyun 	bcm_xtlv_opts_t opts);
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun /* length of data in the xtlv buffer */
211*4882a593Smuzhiyun uint16 bcm_xtlv_buf_len(struct bcm_xtlvbuf *tbuf);
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun /* remaining space in the xtlv buffer */
214*4882a593Smuzhiyun uint16 bcm_xtlv_buf_rlen(struct bcm_xtlvbuf *tbuf);
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun /* write ptr */
217*4882a593Smuzhiyun uint8 *bcm_xtlv_buf(struct bcm_xtlvbuf *tbuf);
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun /* head */
220*4882a593Smuzhiyun uint8 *bcm_xtlv_head(struct bcm_xtlvbuf *tbuf);
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /* put a data buffer into xtlv */
223*4882a593Smuzhiyun int bcm_xtlv_put_data(bcm_xtlvbuf_t *tbuf, uint16 type, const uint8 *data, int n);
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun /* put one or more u16 elts into xtlv */
226*4882a593Smuzhiyun int bcm_xtlv_put16(bcm_xtlvbuf_t *tbuf, uint16 type, const uint16 *data, int n);
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun /* put one or more u32 elts into xtlv */
229*4882a593Smuzhiyun int bcm_xtlv_put32(bcm_xtlvbuf_t *tbuf, uint16 type, const uint32 *data, int n);
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun /* put one or more u64 elts into xtlv */
232*4882a593Smuzhiyun int bcm_xtlv_put64(bcm_xtlvbuf_t *tbuf, uint16 type, const uint64 *data, int n);
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun /* note: there are no get equivalent of integer unpacking, becasuse bcmendian.h
235*4882a593Smuzhiyun  * can be used directly using pointers returned in the buffer being processed.
236*4882a593Smuzhiyun  */
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun /* unpack a single xtlv entry, advances buffer and copies data to dst_data on match
239*4882a593Smuzhiyun  * type and length match must be exact
240*4882a593Smuzhiyun  */
241*4882a593Smuzhiyun int bcm_unpack_xtlv_entry(const uint8 **buf, uint16 expected_type, uint16 expected_len,
242*4882a593Smuzhiyun 	uint8 *dst_data, bcm_xtlv_opts_t opts);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun /* packs an xtlv into buffer, and advances buffer, decreements buffer length.
245*4882a593Smuzhiyun  * buffer length is checked and must be >= size of xtlv - otherwise BCME_BADLEN
246*4882a593Smuzhiyun  */
247*4882a593Smuzhiyun int bcm_pack_xtlv_entry(uint8 **buf, uint16 *buflen, uint16 type, uint16 len,
248*4882a593Smuzhiyun 	const uint8 *src_data, bcm_xtlv_opts_t opts);
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun /* accessors and lengths for element given options */
251*4882a593Smuzhiyun int bcm_xtlv_size(const bcm_xtlv_t *elt, bcm_xtlv_opts_t opts);
252*4882a593Smuzhiyun int bcm_xtlv_hdr_size(bcm_xtlv_opts_t opts);
253*4882a593Smuzhiyun int bcm_xtlv_len(const bcm_xtlv_t *elt, bcm_xtlv_opts_t opts);
254*4882a593Smuzhiyun int bcm_xtlv_id(const bcm_xtlv_t *elt, bcm_xtlv_opts_t opts);
255*4882a593Smuzhiyun int bcm_xtlv_size_for_data(int dlen, bcm_xtlv_opts_t opts);
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun /* compute size needed for number of tlvs whose total data len is given */
258*4882a593Smuzhiyun #define BCM_XTLV_SIZE_FOR_TLVS(_data_len, _num_tlvs, _opts) (\
259*4882a593Smuzhiyun 	bcm_xtlv_size_for_data(_data_len, _opts) + (\
260*4882a593Smuzhiyun 	(_num_tlvs) * BCM_XTLV_HDR_SIZE_EX(_opts)))
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun /* unsafe copy xtlv */
263*4882a593Smuzhiyun #define BCM_XTLV_BCOPY(_src, _dst, _opts) \
264*4882a593Smuzhiyun 	bcm_xtlv_bcopy(_src, _dst, BCM_XTLV_MAX_DATA_SIZE_EX(_opts), \
265*4882a593Smuzhiyun 		BCM_XTLV_MAX_DATA_SIZE_EX(_opts), _opts)
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun /* copy xtlv - note: src->dst bcopy order - to be compatible w/ tlv version */
268*4882a593Smuzhiyun bcm_xtlv_t* bcm_xtlv_bcopy(const bcm_xtlv_t *src, bcm_xtlv_t *dst,
269*4882a593Smuzhiyun 	int src_buf_len, int dst_buf_len, bcm_xtlv_opts_t opts);
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun /* callback for unpacking xtlv from a buffer into context. */
272*4882a593Smuzhiyun typedef int (bcm_xtlv_unpack_cbfn_t)(void *ctx, const uint8 *buf,
273*4882a593Smuzhiyun 	uint16 type, uint16 len);
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /* unpack a tlv buffer using buffer, options, and callback */
276*4882a593Smuzhiyun int bcm_unpack_xtlv_buf(void *ctx, const uint8 *buf, uint16 buflen,
277*4882a593Smuzhiyun 	bcm_xtlv_opts_t opts, bcm_xtlv_unpack_cbfn_t *cbfn);
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun /* unpack a set of tlvs from the buffer using provided xtlv descriptors */
280*4882a593Smuzhiyun int bcm_unpack_xtlv_buf_to_mem(uint8 *buf, int *buflen, xtlv_desc_t *items,
281*4882a593Smuzhiyun 	bcm_xtlv_opts_t opts);
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun /* pack a set of tlvs into buffer using provided xtlv descriptors */
284*4882a593Smuzhiyun int bcm_pack_xtlv_buf_from_mem(uint8 **buf, uint16 *buflen,
285*4882a593Smuzhiyun 	const xtlv_desc_t *items, bcm_xtlv_opts_t opts);
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun /* return data pointer and data length of a given id from xtlv buffer
288*4882a593Smuzhiyun  * data_len may be NULL
289*4882a593Smuzhiyun  */
290*4882a593Smuzhiyun const uint8* bcm_get_data_from_xtlv_buf(const uint8 *tlv_buf, uint16 buflen,
291*4882a593Smuzhiyun 	uint16 id, uint16 *datalen, bcm_xtlv_opts_t opts);
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun /* callback to return next tlv id and len to pack, if there is more tlvs to come and
294*4882a593Smuzhiyun  * options e.g. alignment
295*4882a593Smuzhiyun  */
296*4882a593Smuzhiyun typedef bool (*bcm_pack_xtlv_next_info_cbfn_t)(void *ctx, uint16 *tlv_id, uint16 *tlv_len);
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun /* callback to pack the tlv into length validated buffer */
299*4882a593Smuzhiyun typedef void (*bcm_pack_xtlv_pack_next_cbfn_t)(void *ctx,
300*4882a593Smuzhiyun 	uint16 tlv_id, uint16 tlv_len, uint8* buf);
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun /* pack a set of tlvs into buffer using get_next to interate */
303*4882a593Smuzhiyun int bcm_pack_xtlv_buf(void *ctx, uint8 *tlv_buf, uint16 buflen,
304*4882a593Smuzhiyun 	bcm_xtlv_opts_t opts, bcm_pack_xtlv_next_info_cbfn_t get_next,
305*4882a593Smuzhiyun 	bcm_pack_xtlv_pack_next_cbfn_t pack_next, int *outlen);
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun /* pack an xtlv. does not do any error checking. if data is not NULL
308*4882a593Smuzhiyun  * data of given length is copied  to buffer (xtlv)
309*4882a593Smuzhiyun  */
310*4882a593Smuzhiyun void bcm_xtlv_pack_xtlv(bcm_xtlv_t *xtlv, uint16 type, uint16 len,
311*4882a593Smuzhiyun 	const uint8 *data, bcm_xtlv_opts_t opts);
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun /* unpack an xtlv and return ptr to data, and data length */
314*4882a593Smuzhiyun void bcm_xtlv_unpack_xtlv(const bcm_xtlv_t *xtlv, uint16 *type, uint16 *len,
315*4882a593Smuzhiyun 	const uint8 **data, bcm_xtlv_opts_t opts);
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun /* end xtlvs */
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun /* length value pairs */
320*4882a593Smuzhiyun struct bcm_xlv {
321*4882a593Smuzhiyun 	uint16 len;
322*4882a593Smuzhiyun 	uint8 data[1];
323*4882a593Smuzhiyun };
324*4882a593Smuzhiyun typedef struct bcm_xlv bcm_xlv_t;
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun struct bcm_xlvp {
327*4882a593Smuzhiyun 	uint16 len;
328*4882a593Smuzhiyun 	uint8 *data;
329*4882a593Smuzhiyun };
330*4882a593Smuzhiyun typedef struct bcm_xlvp bcm_xlvp_t;
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun struct bcm_const_xlvp {
333*4882a593Smuzhiyun 	uint16 len;
334*4882a593Smuzhiyun 	const uint8 *data;
335*4882a593Smuzhiyun };
336*4882a593Smuzhiyun typedef struct bcm_const_xlvp bcm_const_xlvp_t;
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun /* end length value pairs */
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun #ifdef __cplusplus
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun #endif /* __cplusplus */
343*4882a593Smuzhiyun 
344*4882a593Smuzhiyun #endif	/* _bcmtlv_h_ */
345