blob: 73e9c5caebc0a1519561fc3b6a88c6434151d2eb [file] [log] [blame]
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000016
17// This file stub definitions for some BAL APIs that are unavailable
18// in TEST_MODE
19//
20extern "C" {
21#include <test_stub.h>
22#include <stdio.h>
23#include <string.h>
24#include <stdarg.h>
Jason Huang09b73ea2020-01-08 17:52:05 +080025#include <stdlib.h>
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000026
27#include <bcmos_system.h>
28#include <bcmolt_msg.h>
29#include <bcmolt_host_api.h>
30
31char log_string[500];
32dev_log_id def_log_id=0;
33
34void bcmos_usleep(uint32_t us) {
Amit Ghoshfcad4d32019-11-13 10:24:55 +000035 // let always sleep for 10ms irrespective of the value passed.
36 usleep (10000);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000037}
38
Jason Huang09b73ea2020-01-08 17:52:05 +080039void bcmos_free(void *ptr) {
40 if (ptr) {
41 free(ptr);
42 }
43}
44
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000045/* Initialize API layer */
46bcmos_errno bcmolt_api_init(void)
47{
48 printf("-- entering :stubbed %s\n", __FUNCTION__);
49 return BCM_ERR_OK;
50}
51
52/* Set configuration */
Chaitrashree G S73e084d2019-11-20 16:18:59 -050053/*bcmos_errno bcmolt_cfg_set(bcmolt_oltid olt, bcmolt_cfg *cfg)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000054{
55 printf("-- entering :stubbed %s\n", __FUNCTION__);
56 return BCM_ERR_OK;
Chaitrashree G S73e084d2019-11-20 16:18:59 -050057}*/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000058
59/* Get configuration */
60/*
61bcmos_errno bcmolt_cfg_get(bcmolt_oltid olt, bcmolt_cfg *cfg)
62{
63 printf("-- entering :stubbed %s\n", __FUNCTION__);
64 return BCM_ERR_OK;
65}
66*/
67
68/* Clear configuration */
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050069/*
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000070bcmos_errno bcmolt_cfg_clear(bcmolt_oltid olt, bcmolt_cfg *cfg)
71{
72 printf("-- entering :stubbed %s\n", __FUNCTION__);
73 return BCM_ERR_OK;
74}
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050075*/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000076
77/* Get statistics */
78bcmos_errno bcmolt_stat_get(bcmolt_oltid olt, bcmolt_stat *stat, bcmolt_stat_flags flags)
79{
80 printf("-- entering :stubbed %s\n", __FUNCTION__);
81 return BCM_ERR_OK;
82}
83
84/* Get statistics configuration */
85bcmos_errno bcmolt_stat_cfg_get(bcmolt_oltid olt, bcmolt_stat_cfg *cfg)
86{
87 printf("-- entering :stubbed %s\n", __FUNCTION__);
88 return BCM_ERR_OK;
89}
90
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000091/* Register Autonomous Indication Message Handler */
92bcmos_errno bcmolt_ind_subscribe(bcmolt_oltid olt, bcmolt_rx_cfg *rx_cfg)
93{
94 printf("-- entering :stubbed %s\n", __FUNCTION__);
95 return BCM_ERR_OK;
96}
97
98/* Un-register Autonomous Indication Message Handler registered by bcmolt_ind_subscribe() */
99bcmos_errno bcmolt_ind_unsubscribe(bcmolt_oltid olt, bcmolt_rx_cfg *rx_cfg)
100{
101 printf("-- entering :stubbed %s\n", __FUNCTION__);
102 return BCM_ERR_OK;
103}
104
105/* Submit Operation */
106/*
107bcmos_errno bcmolt_oper_submit(bcmolt_oltid olt, bcmolt_oper *oper)
108{
109 printf("-- entering :stubbed %s\n", __FUNCTION__);
110 return BCM_ERR_OK;
111}
112*/
113
114/* Get configuration of multiple objects */
115bcmos_errno bcmolt_multi_cfg_get(
116 bcmolt_oltid olt,
117 bcmolt_multi_cfg *cfg,
118 bcmolt_filter_flags filter_flags)
119{
120 printf("-- entering :stubbed %s\n", __FUNCTION__);
121 return BCM_ERR_OK;
122}
123
124/* Get statistics of multiple objects */
125bcmos_errno bcmolt_multi_stat_get(
126 bcmolt_oltid olt,
127 bcmolt_multi_stat *stat,
128 bcmolt_stat_flags stat_flags,
129 bcmolt_filter_flags filter_flags)
130{
131 printf("-- entering :stubbed %s\n", __FUNCTION__);
132 return BCM_ERR_OK;
133}
134
135/* Map error code to error string */
136const char *bcmos_strerror(bcmos_errno err)
137{
138 static const char *errstr[] = {
139 [-BCM_ERR_OK] = "OK",
140 [-BCM_ERR_IN_PROGRESS] = "In progress",
141 [-BCM_ERR_PARM] = "Error in parameters",
142 [-BCM_ERR_NOMEM] = "No memory",
143 [-BCM_ERR_NORES] = "No resources",
144 [-BCM_ERR_INTERNAL] = "Internal error",
145 [-BCM_ERR_NOENT] = "Entry doesn't exist",
146 [-BCM_ERR_NODEV] = "Device doesn't exist",
147 [-BCM_ERR_ALREADY] = "Entry already exists/already in requested state",
148 [-BCM_ERR_RANGE] = "Out of range",
149 [-BCM_ERR_PERM] = "No permission to perform an operation",
150 [-BCM_ERR_NOT_SUPPORTED] = "Operation is not supported",
151 [-BCM_ERR_PARSE] = "Parsing error",
152 [-BCM_ERR_INVALID_OP] = "Invalid operation",
153 [-BCM_ERR_IO] = "I/O error",
154 [-BCM_ERR_STATE] = "Object is in bad state",
155 [-BCM_ERR_DELETED] = "Object is deleted",
156 [-BCM_ERR_TOO_MANY] = "Too many objects",
157 [-BCM_ERR_NO_MORE] = "No more entries",
158 [-BCM_ERR_OVERFLOW] = "Buffer overflow",
159 [-BCM_ERR_COMM_FAIL] = "Communication failure",
160 [-BCM_ERR_NOT_CONNECTED] = "No connection with the target system",
161 [-BCM_ERR_SYSCALL_ERR] = "System call returned error",
162 [-BCM_ERR_MSG_ERROR] = "Received message is insane",
163 [-BCM_ERR_TOO_MANY_REQS] = "Too many outstanding requests",
164 [-BCM_ERR_TIMEOUT] = "Operation timed out",
165 [-BCM_ERR_TOO_MANY_FRAGS] = "Too many fragments",
166 [-BCM_ERR_NULL] = "Got NULL pointer",
167 [-BCM_ERR_READ_ONLY] = "Attempt to set read-only parameter",
168 [-BCM_ERR_ONU_ERR_RESP] = "ONU returned an error response",
169 [-BCM_ERR_MANDATORY_PARM_IS_MISSING] = "Mandatory parameter is missing",
170 [-BCM_ERR_KEY_RANGE] = "Key field out of range",
171 [-BCM_ERR_QUEUE_EMPTY] = "Rx of PCIe empty",
172 [-BCM_ERR_QUEUE_FULL] = "Tx of PCIe full",
173 [-BCM_ERR_TOO_LONG] = "Processing is taking too long, but will finish eventually",
174 [-BCM_ERR_INSUFFICIENT_LIST_MEM] = "Insufficient list memory provided",
175 [-BCM_ERR_OUT_OF_SYNC] = "Sequence number or operation step was out of sync",
176 [-BCM_ERR_CHECKSUM] = "Checksum error",
177 [-BCM_ERR_IMAGE_TYPE] = "Unsupported file/image type",
178 [-BCM_ERR_INCOMPLETE_TERMINATION] = "Incomplete premature termination",
179 [-BCM_ERR_MISMATCH] = "Parameters mismatch",
180 };
181 static const char *unknown = "*unknown*";
182
183 if ((unsigned)(-err) >= sizeof(errstr)/sizeof(errstr[0]) || !errstr[-err])
184 return unknown;
185 return errstr[-err];
186}
187
188void bcmolt_msg_free(bcmolt_msg *msg)
189{
190 return;
191}
192
193void bcmolt_api_set_prop_present(bcmolt_msg *msg, const void *prop_ptr)
194{
195 return;
196}
197
198const bcmolt_enum_val bcmolt_obj_id_string_table[] = {"dummy string, never used"};
199const bcmolt_enum_val bcmolt_interface_state_string_table[] = {"dummy string, never used"};
200
201dev_log_id bcm_dev_log_id_register(const char *xi_name,
202 bcm_dev_log_level xi_default_log_level,
203 bcm_dev_log_id_type xi_default_log_type) {
204 return 0;
205}
206bool bcmcli_is_stopped(bcmcli_session *sess) {
207 printf("-- stub bcmcli_is_stopped called --\n");
208 return true;
209}
210
211bool bcmcli_parse(bcmcli_session *sess, char *s) {
212 printf("-- stub bcmcli_parse called --\n");
213 return true;
214}
215
216bool bcmcli_driver(bcmcli_session *sess) {
217 printf("-- stub bcmcli_driver called --\n");
218 return true;
219}
220void bcmcli_token_destroy(void *ptr) {
221 printf("-- stub bcmcli_token_destroy called --\n");
222 return;
223}
224
225void bcmcli_session_close( bcmcli_session*ptr) {
226 printf("-- stub bcmcli_session_close called --\n");
227 return;
228}
229
230bcmos_errno bcm_api_cli_set_commands(bcmcli_session *sess) {
231 printf("-- stub bcm_api_cli_set_commands called --\n");
232 return BCM_ERR_OK;
233}
234
235void bcmcli_stop(bcmcli_session *sess) {
236 printf("-- stub bcmcli_stop called --\n");
237 return;
238}
239
240void bcmcli_session_print(bcmcli_session *sess, const char *s) {
241 printf("-- stub bcmcli_session_print called --\n");
242 return;
243}
244
245bcmos_errno bcmcli_session_open(bcmcli_session_parm *mon_sess, bcmcli_session **curr_sess) {
246 printf("-- stub bcmcli_session_open called --\n");
247 return BCM_ERR_OK;
248}
249
250void bcm_dev_log_log(dev_log_id xi_id,
251 bcm_dev_log_level xi_log_level,
252 uint32_t xi_flags,
253 const char *fmt,
254 ...) {
255 memset(log_string, '\0', sizeof(log_string));
256 va_list args;
257 va_start(args, fmt);
258 vsnprintf(log_string, 490, fmt, args);
259 switch (xi_log_level) {
260 case DEV_LOG_LEVEL_FATAL:
261 printf("FATAL: %s\n", log_string);
262 // exit (0);
263 break;
264 case DEV_LOG_LEVEL_ERROR:
265 printf("ERROR : %s\n", log_string);
266 break;
267 case DEV_LOG_LEVEL_WARNING:
268 printf("WARNING : %s\n", log_string);
269 break;
270 case DEV_LOG_LEVEL_INFO:
271 printf("INFO : %s\n", log_string);
272 break;
273 case DEV_LOG_LEVEL_DEBUG:
274 printf("DEBUG : %s\n", log_string);
275 break;
276 default:
277 printf("%s\n", log_string);
278 }
279 va_end(args);
280}
281
282bcmos_errno bcmos_task_query(const bcmos_task *task, bcmos_task_parm *parm) {
283 printf (" -- stub bcmos_task_query called --\n");
Thiyagarajan Subramani3e8bfd92021-04-26 15:07:14 +0530284 return BCM_ERR_ALREADY;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000285}
286
287bcmos_errno bcmos_task_create(bcmos_task *task, const bcmos_task_parm *parm) {
288 printf (" -- stub bcmos_task_create called --\n");
289 return BCM_ERR_OK;
290}
291
292int bcmos_printf(const char *fmt, ...) {
293 memset(log_string, '\0', sizeof(log_string));
294 va_list args;
295 va_start(args, fmt);
296 vsnprintf(log_string, 490, fmt, args);
297 printf("%s\n", log_string);
298 va_end(args);
299
300}
301
302bcmos_bool bcmolt_api_conn_mgr_is_connected(bcmolt_goid olt) {
303 printf ("-- stub bcmolt_api_conn_mgr_is_connected called --\n");
304 return true;
305}
Girish Gowdra5287fde2021-07-31 00:41:45 +0000306
307bcmos_errno bcmos_mutex_create(bcmos_mutex *mutex, uint32_t flags, const char *name)
308{
309 pthread_mutexattr_t attr;
310 if (pthread_mutexattr_init(&attr) != 0) {
311 printf("pthread_mutex_attr_init() error");
312 exit(1);
313 }
314 pthread_mutex_init(&mutex->m, &attr);
315 return BCM_ERR_OK;
316}
317
318/* Destroy mutex */
319void bcmos_mutex_destroy(bcmos_mutex *mutex)
320{
321 pthread_mutex_destroy(&mutex->m);
322}
323
324/* Lock mutex */
325void bcmos_mutex_lock(bcmos_mutex *mutex)
326{
327 pthread_mutex_lock(&mutex->m);
328}
329
330/* Release mutex */
331void bcmos_mutex_unlock(bcmos_mutex *mutex)
332{
333 pthread_mutex_unlock(&mutex->m);
334}
335
336void *bcmos_alloc(uint32_t size)
337{
338 return malloc(size);
339}
340
341bcmos_errno bcmcli_cmd_add(bcmcli_entry *dir, const char *name, bcmcli_cmd_cb cmd_cb,
342 const char *help, bcmcli_access_right access_right,
343 const bcmcli_cmd_extra_parm *extras, bcmcli_cmd_parm parms[]) {
344 return BCM_ERR_OK;
345}
346
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000347}