Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1 | /* |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 3 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 4 | * 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 7 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 9 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 10 | * 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 16 | |
| 17 | // This file stub definitions for some BAL APIs that are unavailable |
| 18 | // in TEST_MODE |
| 19 | // |
| 20 | extern "C" { |
| 21 | #include <test_stub.h> |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
| 24 | #include <stdarg.h> |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 25 | #include <stdlib.h> |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 26 | |
| 27 | #include <bcmos_system.h> |
| 28 | #include <bcmolt_msg.h> |
| 29 | #include <bcmolt_host_api.h> |
| 30 | |
| 31 | char log_string[500]; |
| 32 | dev_log_id def_log_id=0; |
| 33 | |
| 34 | void bcmos_usleep(uint32_t us) { |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 35 | // let always sleep for 10ms irrespective of the value passed. |
| 36 | usleep (10000); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 39 | void bcmos_free(void *ptr) { |
| 40 | if (ptr) { |
| 41 | free(ptr); |
| 42 | } |
| 43 | } |
| 44 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 45 | /* Initialize API layer */ |
| 46 | bcmos_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 S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 53 | /*bcmos_errno bcmolt_cfg_set(bcmolt_oltid olt, bcmolt_cfg *cfg) |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 54 | { |
| 55 | printf("-- entering :stubbed %s\n", __FUNCTION__); |
| 56 | return BCM_ERR_OK; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 57 | }*/ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 58 | |
| 59 | /* Get configuration */ |
| 60 | /* |
| 61 | bcmos_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 Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 69 | /* |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 70 | bcmos_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 Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 75 | */ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 76 | |
| 77 | /* Get statistics */ |
| 78 | bcmos_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 */ |
| 85 | bcmos_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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 91 | /* Register Autonomous Indication Message Handler */ |
| 92 | bcmos_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() */ |
| 99 | bcmos_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 | /* |
| 107 | bcmos_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 */ |
| 115 | bcmos_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 */ |
| 125 | bcmos_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 */ |
| 136 | const 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 | |
| 188 | void bcmolt_msg_free(bcmolt_msg *msg) |
| 189 | { |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | void bcmolt_api_set_prop_present(bcmolt_msg *msg, const void *prop_ptr) |
| 194 | { |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | const bcmolt_enum_val bcmolt_obj_id_string_table[] = {"dummy string, never used"}; |
| 199 | const bcmolt_enum_val bcmolt_interface_state_string_table[] = {"dummy string, never used"}; |
| 200 | |
| 201 | dev_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 | } |
| 206 | bool bcmcli_is_stopped(bcmcli_session *sess) { |
| 207 | printf("-- stub bcmcli_is_stopped called --\n"); |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | bool bcmcli_parse(bcmcli_session *sess, char *s) { |
| 212 | printf("-- stub bcmcli_parse called --\n"); |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | bool bcmcli_driver(bcmcli_session *sess) { |
| 217 | printf("-- stub bcmcli_driver called --\n"); |
| 218 | return true; |
| 219 | } |
| 220 | void bcmcli_token_destroy(void *ptr) { |
| 221 | printf("-- stub bcmcli_token_destroy called --\n"); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | void bcmcli_session_close( bcmcli_session*ptr) { |
| 226 | printf("-- stub bcmcli_session_close called --\n"); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | bcmos_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 | |
| 235 | void bcmcli_stop(bcmcli_session *sess) { |
| 236 | printf("-- stub bcmcli_stop called --\n"); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | void bcmcli_session_print(bcmcli_session *sess, const char *s) { |
| 241 | printf("-- stub bcmcli_session_print called --\n"); |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | bcmos_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 | |
| 250 | void 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 | |
| 282 | bcmos_errno bcmos_task_query(const bcmos_task *task, bcmos_task_parm *parm) { |
| 283 | printf (" -- stub bcmos_task_query called --\n"); |
Thiyagarajan Subramani | 3e8bfd9 | 2021-04-26 15:07:14 +0530 | [diff] [blame] | 284 | return BCM_ERR_ALREADY; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | bcmos_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 | |
| 292 | int 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 | |
| 302 | bcmos_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 Gowdra | 5287fde | 2021-07-31 00:41:45 +0000 | [diff] [blame^] | 306 | |
| 307 | bcmos_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 */ |
| 319 | void bcmos_mutex_destroy(bcmos_mutex *mutex) |
| 320 | { |
| 321 | pthread_mutex_destroy(&mutex->m); |
| 322 | } |
| 323 | |
| 324 | /* Lock mutex */ |
| 325 | void bcmos_mutex_lock(bcmos_mutex *mutex) |
| 326 | { |
| 327 | pthread_mutex_lock(&mutex->m); |
| 328 | } |
| 329 | |
| 330 | /* Release mutex */ |
| 331 | void bcmos_mutex_unlock(bcmos_mutex *mutex) |
| 332 | { |
| 333 | pthread_mutex_unlock(&mutex->m); |
| 334 | } |
| 335 | |
| 336 | void *bcmos_alloc(uint32_t size) |
| 337 | { |
| 338 | return malloc(size); |
| 339 | } |
| 340 | |
| 341 | bcmos_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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 347 | } |