blob: 62eb9319521ac12ce5c9b9a9dde2dbcf60fc8d06 [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_calloc(uint32_t size) {
40 void *ptr = malloc(size);
41 if (ptr) {
42 memset(ptr, 0, size);
43 }
44 return ptr;
45}
46
47void bcmos_free(void *ptr) {
48 if (ptr) {
49 free(ptr);
50 }
51}
52
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000053void bcmos_fastlock_init(bcmos_fastlock *lock, uint32_t flags) {
54 pthread_mutex_init(&(lock->lock), NULL);
55}
56
57long bcmos_fastlock_lock(bcmos_fastlock *lock) {
58 pthread_mutex_lock(&(lock->lock));
59}
60
61void bcmos_fastlock_unlock(bcmos_fastlock *lock, long flags) {
62 pthread_mutex_unlock(&(lock->lock));
63}
64
65/* Initialize API layer */
66bcmos_errno bcmolt_api_init(void)
67{
68 printf("-- entering :stubbed %s\n", __FUNCTION__);
69 return BCM_ERR_OK;
70}
71
72/* Set configuration */
Chaitrashree G S73e084d2019-11-20 16:18:59 -050073/*bcmos_errno bcmolt_cfg_set(bcmolt_oltid olt, bcmolt_cfg *cfg)
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000074{
75 printf("-- entering :stubbed %s\n", __FUNCTION__);
76 return BCM_ERR_OK;
Chaitrashree G S73e084d2019-11-20 16:18:59 -050077}*/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000078
79/* Get configuration */
80/*
81bcmos_errno bcmolt_cfg_get(bcmolt_oltid olt, bcmolt_cfg *cfg)
82{
83 printf("-- entering :stubbed %s\n", __FUNCTION__);
84 return BCM_ERR_OK;
85}
86*/
87
88/* Clear configuration */
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050089/*
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000090bcmos_errno bcmolt_cfg_clear(bcmolt_oltid olt, bcmolt_cfg *cfg)
91{
92 printf("-- entering :stubbed %s\n", __FUNCTION__);
93 return BCM_ERR_OK;
94}
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050095*/
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000096
97/* Get statistics */
98bcmos_errno bcmolt_stat_get(bcmolt_oltid olt, bcmolt_stat *stat, bcmolt_stat_flags flags)
99{
100 printf("-- entering :stubbed %s\n", __FUNCTION__);
101 return BCM_ERR_OK;
102}
103
104/* Get statistics configuration */
105bcmos_errno bcmolt_stat_cfg_get(bcmolt_oltid olt, bcmolt_stat_cfg *cfg)
106{
107 printf("-- entering :stubbed %s\n", __FUNCTION__);
108 return BCM_ERR_OK;
109}
110
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000111/* Register Autonomous Indication Message Handler */
112bcmos_errno bcmolt_ind_subscribe(bcmolt_oltid olt, bcmolt_rx_cfg *rx_cfg)
113{
114 printf("-- entering :stubbed %s\n", __FUNCTION__);
115 return BCM_ERR_OK;
116}
117
118/* Un-register Autonomous Indication Message Handler registered by bcmolt_ind_subscribe() */
119bcmos_errno bcmolt_ind_unsubscribe(bcmolt_oltid olt, bcmolt_rx_cfg *rx_cfg)
120{
121 printf("-- entering :stubbed %s\n", __FUNCTION__);
122 return BCM_ERR_OK;
123}
124
125/* Submit Operation */
126/*
127bcmos_errno bcmolt_oper_submit(bcmolt_oltid olt, bcmolt_oper *oper)
128{
129 printf("-- entering :stubbed %s\n", __FUNCTION__);
130 return BCM_ERR_OK;
131}
132*/
133
134/* Get configuration of multiple objects */
135bcmos_errno bcmolt_multi_cfg_get(
136 bcmolt_oltid olt,
137 bcmolt_multi_cfg *cfg,
138 bcmolt_filter_flags filter_flags)
139{
140 printf("-- entering :stubbed %s\n", __FUNCTION__);
141 return BCM_ERR_OK;
142}
143
144/* Get statistics of multiple objects */
145bcmos_errno bcmolt_multi_stat_get(
146 bcmolt_oltid olt,
147 bcmolt_multi_stat *stat,
148 bcmolt_stat_flags stat_flags,
149 bcmolt_filter_flags filter_flags)
150{
151 printf("-- entering :stubbed %s\n", __FUNCTION__);
152 return BCM_ERR_OK;
153}
154
155/* Map error code to error string */
156const char *bcmos_strerror(bcmos_errno err)
157{
158 static const char *errstr[] = {
159 [-BCM_ERR_OK] = "OK",
160 [-BCM_ERR_IN_PROGRESS] = "In progress",
161 [-BCM_ERR_PARM] = "Error in parameters",
162 [-BCM_ERR_NOMEM] = "No memory",
163 [-BCM_ERR_NORES] = "No resources",
164 [-BCM_ERR_INTERNAL] = "Internal error",
165 [-BCM_ERR_NOENT] = "Entry doesn't exist",
166 [-BCM_ERR_NODEV] = "Device doesn't exist",
167 [-BCM_ERR_ALREADY] = "Entry already exists/already in requested state",
168 [-BCM_ERR_RANGE] = "Out of range",
169 [-BCM_ERR_PERM] = "No permission to perform an operation",
170 [-BCM_ERR_NOT_SUPPORTED] = "Operation is not supported",
171 [-BCM_ERR_PARSE] = "Parsing error",
172 [-BCM_ERR_INVALID_OP] = "Invalid operation",
173 [-BCM_ERR_IO] = "I/O error",
174 [-BCM_ERR_STATE] = "Object is in bad state",
175 [-BCM_ERR_DELETED] = "Object is deleted",
176 [-BCM_ERR_TOO_MANY] = "Too many objects",
177 [-BCM_ERR_NO_MORE] = "No more entries",
178 [-BCM_ERR_OVERFLOW] = "Buffer overflow",
179 [-BCM_ERR_COMM_FAIL] = "Communication failure",
180 [-BCM_ERR_NOT_CONNECTED] = "No connection with the target system",
181 [-BCM_ERR_SYSCALL_ERR] = "System call returned error",
182 [-BCM_ERR_MSG_ERROR] = "Received message is insane",
183 [-BCM_ERR_TOO_MANY_REQS] = "Too many outstanding requests",
184 [-BCM_ERR_TIMEOUT] = "Operation timed out",
185 [-BCM_ERR_TOO_MANY_FRAGS] = "Too many fragments",
186 [-BCM_ERR_NULL] = "Got NULL pointer",
187 [-BCM_ERR_READ_ONLY] = "Attempt to set read-only parameter",
188 [-BCM_ERR_ONU_ERR_RESP] = "ONU returned an error response",
189 [-BCM_ERR_MANDATORY_PARM_IS_MISSING] = "Mandatory parameter is missing",
190 [-BCM_ERR_KEY_RANGE] = "Key field out of range",
191 [-BCM_ERR_QUEUE_EMPTY] = "Rx of PCIe empty",
192 [-BCM_ERR_QUEUE_FULL] = "Tx of PCIe full",
193 [-BCM_ERR_TOO_LONG] = "Processing is taking too long, but will finish eventually",
194 [-BCM_ERR_INSUFFICIENT_LIST_MEM] = "Insufficient list memory provided",
195 [-BCM_ERR_OUT_OF_SYNC] = "Sequence number or operation step was out of sync",
196 [-BCM_ERR_CHECKSUM] = "Checksum error",
197 [-BCM_ERR_IMAGE_TYPE] = "Unsupported file/image type",
198 [-BCM_ERR_INCOMPLETE_TERMINATION] = "Incomplete premature termination",
199 [-BCM_ERR_MISMATCH] = "Parameters mismatch",
200 };
201 static const char *unknown = "*unknown*";
202
203 if ((unsigned)(-err) >= sizeof(errstr)/sizeof(errstr[0]) || !errstr[-err])
204 return unknown;
205 return errstr[-err];
206}
207
208void bcmolt_msg_free(bcmolt_msg *msg)
209{
210 return;
211}
212
213void bcmolt_api_set_prop_present(bcmolt_msg *msg, const void *prop_ptr)
214{
215 return;
216}
217
218const bcmolt_enum_val bcmolt_obj_id_string_table[] = {"dummy string, never used"};
219const bcmolt_enum_val bcmolt_interface_state_string_table[] = {"dummy string, never used"};
220
221dev_log_id bcm_dev_log_id_register(const char *xi_name,
222 bcm_dev_log_level xi_default_log_level,
223 bcm_dev_log_id_type xi_default_log_type) {
224 return 0;
225}
226bool bcmcli_is_stopped(bcmcli_session *sess) {
227 printf("-- stub bcmcli_is_stopped called --\n");
228 return true;
229}
230
231bool bcmcli_parse(bcmcli_session *sess, char *s) {
232 printf("-- stub bcmcli_parse called --\n");
233 return true;
234}
235
236bool bcmcli_driver(bcmcli_session *sess) {
237 printf("-- stub bcmcli_driver called --\n");
238 return true;
239}
240void bcmcli_token_destroy(void *ptr) {
241 printf("-- stub bcmcli_token_destroy called --\n");
242 return;
243}
244
245void bcmcli_session_close( bcmcli_session*ptr) {
246 printf("-- stub bcmcli_session_close called --\n");
247 return;
248}
249
250bcmos_errno bcm_api_cli_set_commands(bcmcli_session *sess) {
251 printf("-- stub bcm_api_cli_set_commands called --\n");
252 return BCM_ERR_OK;
253}
254
255void bcmcli_stop(bcmcli_session *sess) {
256 printf("-- stub bcmcli_stop called --\n");
257 return;
258}
259
260void bcmcli_session_print(bcmcli_session *sess, const char *s) {
261 printf("-- stub bcmcli_session_print called --\n");
262 return;
263}
264
265bcmos_errno bcmcli_session_open(bcmcli_session_parm *mon_sess, bcmcli_session **curr_sess) {
266 printf("-- stub bcmcli_session_open called --\n");
267 return BCM_ERR_OK;
268}
269
270void bcm_dev_log_log(dev_log_id xi_id,
271 bcm_dev_log_level xi_log_level,
272 uint32_t xi_flags,
273 const char *fmt,
274 ...) {
275 memset(log_string, '\0', sizeof(log_string));
276 va_list args;
277 va_start(args, fmt);
278 vsnprintf(log_string, 490, fmt, args);
279 switch (xi_log_level) {
280 case DEV_LOG_LEVEL_FATAL:
281 printf("FATAL: %s\n", log_string);
282 // exit (0);
283 break;
284 case DEV_LOG_LEVEL_ERROR:
285 printf("ERROR : %s\n", log_string);
286 break;
287 case DEV_LOG_LEVEL_WARNING:
288 printf("WARNING : %s\n", log_string);
289 break;
290 case DEV_LOG_LEVEL_INFO:
291 printf("INFO : %s\n", log_string);
292 break;
293 case DEV_LOG_LEVEL_DEBUG:
294 printf("DEBUG : %s\n", log_string);
295 break;
296 default:
297 printf("%s\n", log_string);
298 }
299 va_end(args);
300}
301
302bcmos_errno bcmos_task_query(const bcmos_task *task, bcmos_task_parm *parm) {
303 printf (" -- stub bcmos_task_query called --\n");
Thiyagarajan Subramani3e8bfd92021-04-26 15:07:14 +0530304 return BCM_ERR_ALREADY;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000305}
306
307bcmos_errno bcmos_task_create(bcmos_task *task, const bcmos_task_parm *parm) {
308 printf (" -- stub bcmos_task_create called --\n");
309 return BCM_ERR_OK;
310}
311
312int bcmos_printf(const char *fmt, ...) {
313 memset(log_string, '\0', sizeof(log_string));
314 va_list args;
315 va_start(args, fmt);
316 vsnprintf(log_string, 490, fmt, args);
317 printf("%s\n", log_string);
318 va_end(args);
319
320}
321
322bcmos_bool bcmolt_api_conn_mgr_is_connected(bcmolt_goid olt) {
323 printf ("-- stub bcmolt_api_conn_mgr_is_connected called --\n");
324 return true;
325}
326}