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