/* Traverse a string of 1-byte tag/1-byte length/variable-length value triples, returning a pointer to the substring whose first element matches tag  */
bcm_tlv_t* bcm_parse_tlvs(void *buf, int buflen, uint key)
/* Traverse a string of 1-byte tag/1-byte length/variable-length value triples, returning a pointer to the substring whose first element matches tag  */
bcm_tlv_t* bcm_parse_tlvs(void *buf, int buflen, uint key)
{
	bcm_tlv_t *elt;
	int totlen;
	elt = (bcm_tlv_t*)buf;
	totlen = buflen;
	while (totlen >= TLV_HDR_LEN) {
		int len = elt->len;
		if ((elt->id == key) &&
		    (totlen >= (len + TLV_HDR_LEN)))
			return (elt);
		elt = (bcm_tlv_t*)((uint8*)elt + (len + TLV_HDR_LEN));
		totlen -= (len + TLV_HDR_LEN);
	}
	return NULL;
}