blob: bc01bff580d48e03bfde17fb53a369d262a79748 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2016:proprietary:standard
3
4 Broadcom Proprietary and Confidential.(c) 2016 Broadcom
5 All Rights Reserved
6
7This program is the proprietary software of Broadcom Corporation and/or its
8licensors, and may only be used, duplicated, modified or distributed pursuant
9to the terms and conditions of a separate, written license agreement executed
10between you and Broadcom (an "Authorized License"). Except as set forth in
11an Authorized License, Broadcom grants no license (express or implied), right
12to use, or waiver of any kind with respect to the Software, and Broadcom
13expressly reserves all rights in and to the Software and all intellectual
14property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE
15NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY
16BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
17
18Except as expressly set forth in the Authorized License,
19
201. This program, including its structure, sequence and organization,
21 constitutes the valuable trade secrets of Broadcom, and you shall use
22 all reasonable efforts to protect the confidentiality thereof, and to
23 use this information only in connection with your use of Broadcom
24 integrated circuit products.
25
262. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
27 AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
28 WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
29 RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND
30 ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT,
31 FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
32 COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE
33 TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF USE OR
34 PERFORMANCE OF THE SOFTWARE.
35
363. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR
37 ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL,
38 INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY
39 WAY RELATING TO YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN
40 IF BROADCOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES;
41 OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE
42 SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE LIMITATIONS
43 SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY
44 LIMITED REMEDY.
45:>
46*/
47
48#ifndef BCMOLT_MSG_PACK_H_
49#define BCMOLT_MSG_PACK_H_
50
51#include "bcmos_system.h"
52#include "bcmos_common.h"
53#include "bcmos_errno.h"
54#include "bcmolt_buf.h"
55#include "bcmolt_msg.h"
56#include "bcmolt_model_types.h"
57
58/** Gets the number of bytes a message would occupy when packed.
59 *
60 * \param this The message to scan.
61 * \return The size in bytes if > 0, or an error as defined in bcmos_errno.
62 */
63int32_t bcmolt_msg_get_packed_length(bcmolt_msg *this);
64
65/** Packs a message to a byte stream.
66 *
67 * \param this The message to pack.
68 * \param buf The stream to pack into.
69 * \return An error code or BCM_ERR_OK for success.
70 */
71bcmos_errno bcmolt_msg_pack(bcmolt_msg *this, bcmolt_buf *buf);
72
73/** Unpacks a message from a byte stream.
74 *
75 * This unpacks the message from the packed form into the struct following the "unpacked" pointer. There are several
76 * special cases:
77 *
78 * if *unpacked == NULL:
79 * *unpacked will be allocated dynamically via bcmos_calloc, in a contiguous block of memory with the struct
80 * itself followed by the memory required for all variable-sized lists.
81 *
82 * if (*unpacked)->list_buf != NULL:
83 * When a variable-length list is encountered in the input stream, and the array field we're unpacking into is NULL,
84 * memory will be allocated starting from (*unpacked)->list_buf. If multiple such lists exist, they will share this
85 * buffer. If the (*unpacked)->list_buf_size is not large enough, this will return BCM_ERR_INSUFFICIENT_LIST_MEM.
86 *
87 * \param buf The stream to unpack from.
88 * \param unpacked A pointer to the message to unpack.
89 * \return An error as defined in bcmos_errno.
90 */
91bcmos_errno bcmolt_msg_unpack(bcmolt_buf *buf, bcmolt_msg **unpacked);
92
93/** Converts a generic group ID into a specific object type, group and subgroup.
94 *
95 * \param group_id The generic group ID.
96 * \param obj The object type that corresponds to the group ID.
97 * \param group The group type that corresponds to the group ID.
98 * \param subgroup The subgroup index that corresponds to the group ID.
99 * \return An error code or BCM_ERR_OK for success.
100 */
101bcmos_errno bcmolt_group_id_split(bcmolt_group_id group_id,
102 bcmolt_obj_id *obj,
103 bcmolt_mgt_group *group,
104 uint16_t *subgroup);
105
106/** Converts a specific object type, group and subgroup into a generic group ID.
107 *
108 * \param obj The object type that corresponds to the group ID.
109 * \param group The group type that corresponds to the group ID.
110 * \param subgroup The subgroup index that corresponds to the group ID.
111 * \param group_id The generic group ID.
112 * \return An error code or BCM_ERR_OK for success.
113 */
114bcmos_errno bcmolt_group_id_combine(bcmolt_obj_id obj,
115 bcmolt_mgt_group group,
116 uint16_t subgroup,
117 bcmolt_group_id *group_id);
118
119/** Returns the instance number of a given message, as determined by the object key.
120 *
121 * \param msg The message to check.
122 * \return The instance number of the message.
123 */
124uint8_t bcmolt_msg_instance(const bcmolt_msg *msg);
125
126/** Gets a mask of all readonly properties for an object's cfg group.
127 *
128 * \param obj The objecct to check.
129 * \param mask A mask of bits set to 1 per read-only property.
130 * \return An error code or BCM_ERR_OK for success.
131 */
132bcmos_errno bcmolt_get_prop_readonly_mask(bcmolt_obj_id obj, bcmolt_presence_mask *mask);
133
134/** Clones a message by packing it to a buffer then unpacking it into the destination message.
135 * This uses bcmolt_msg_unpack, so if *dest is NULL, memory will by allocated dynamically using bcmos_calloc.
136 *
137 * \param dest A pointer to the location in memory that will hold the cloned message.
138 * \param src The message that should be copied.
139 * \return An error code or BCM_ERR_OK for success.
140 */
141bcmos_errno bcmolt_msg_clone(bcmolt_msg **dest, bcmolt_msg *src);
142
143#endif /* BCMOLT_MSG_PACK_H_ */