mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 09:17:08 +00:00
New ONLP APIs - WIP.
This commit is contained in:
@@ -20,7 +20,7 @@ void __onlp_snmp_module_init__(void)
|
||||
{
|
||||
AIM_LOG_STRUCT_REGISTER();
|
||||
datatypes_init__();
|
||||
onlp_init();
|
||||
onlp_sw_init(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,11 @@
|
||||
#include <net-snmp/net-snmp-config.h>
|
||||
#include <net-snmp/net-snmp-includes.h>
|
||||
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
||||
#include <onlp/sys.h>
|
||||
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlp/stdattrs.h>
|
||||
#include <onlp/attribute.h>
|
||||
#include <onlplib/onie.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
@@ -211,25 +215,26 @@ onlp_snmp_platform_init(void)
|
||||
/**
|
||||
* This is the base of the platform:general:system tree
|
||||
*/
|
||||
onlp_sys_info_t si;
|
||||
if(onlp_sys_info_get(&si) >= 0) {
|
||||
int rv;
|
||||
onlp_onie_info_t* oip = NULL;
|
||||
|
||||
if(ONLP_SUCCESS(rv = onlp_attribute_get(ONLP_OID_CHASSIS,
|
||||
ONLP_ATTRIBUTE_ONIE_INFO,
|
||||
(void**)&oip))) {
|
||||
#define REGISTER_STR(_index, _field) \
|
||||
do { \
|
||||
platform_string_register(_index, #_field, (char*)si.onie_info._field); \
|
||||
platform_string_register(_index, #_field, (char*)oip->_field); \
|
||||
} while(0)
|
||||
|
||||
#define REGISTER_INT(_index, _field) \
|
||||
do { \
|
||||
platform_int_register(_index, #_field, si.onie_info._field); \
|
||||
platform_int_register(_index, #_field, oip->_field); \
|
||||
} while(0)
|
||||
|
||||
REGISTER_STR(1, product_name);
|
||||
REGISTER_STR(2, part_number);
|
||||
REGISTER_STR(3, serial_number);
|
||||
char* mstring = aim_fstrdup("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
|
||||
si.onie_info.mac[0], si.onie_info.mac[1], si.onie_info.mac[2],
|
||||
si.onie_info.mac[3], si.onie_info.mac[4], si.onie_info.mac[5]);
|
||||
char* mstring = aim_dfstrdup("%{mac}", oip->mac);
|
||||
platform_string_register(4, "mac", mstring);
|
||||
aim_free(mstring);
|
||||
|
||||
@@ -244,6 +249,10 @@ onlp_snmp_platform_init(void)
|
||||
REGISTER_STR(13, diag_version);
|
||||
REGISTER_STR(14, service_tag);
|
||||
REGISTER_STR(15, onie_version);
|
||||
|
||||
onlp_attribute_free(ONLP_OID_CHASSIS,
|
||||
ONLP_ATTRIBUTE_ONIE_INFO,
|
||||
oip);
|
||||
}
|
||||
|
||||
resource_int_register(1, "CpuAllPercentUtilization", utilization_handler);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <onlp/oids.h>
|
||||
#include <onlp/thermal.h>
|
||||
#include <onlp/fan.h>
|
||||
#include <onlp/psu.h>
|
||||
@@ -321,9 +322,9 @@ temp_status_handler__(netsnmp_request_info *req,
|
||||
}
|
||||
|
||||
value = ONLP_SNMP_SENSOR_STATUS_MISSING;
|
||||
if (ti->status & ONLP_THERMAL_STATUS_PRESENT) {
|
||||
if (ONLP_OID_PRESENT(ti)) {
|
||||
value = ONLP_SNMP_SENSOR_STATUS_GOOD;
|
||||
if (ti->status & ONLP_THERMAL_STATUS_FAILED) {
|
||||
if (ONLP_OID_FAILED(ti)) {
|
||||
value = ONLP_SNMP_SENSOR_STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
@@ -346,7 +347,7 @@ temp_value_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (ti->status & ONLP_THERMAL_STATUS_PRESENT)? ti->mcelsius: 0;
|
||||
value = ONLP_OID_PRESENT(ti) ? ti->mcelsius: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -425,9 +426,9 @@ fan_status_handler__(netsnmp_request_info *req,
|
||||
}
|
||||
|
||||
value = ONLP_SNMP_SENSOR_STATUS_MISSING;
|
||||
if (fi->status & ONLP_FAN_STATUS_PRESENT) {
|
||||
if (ONLP_OID_PRESENT(fi)) {
|
||||
value = ONLP_SNMP_SENSOR_STATUS_GOOD;
|
||||
if (fi->status & ONLP_FAN_STATUS_FAILED) {
|
||||
if (ONLP_OID_FAILED(fi)) {
|
||||
value = ONLP_SNMP_SENSOR_STATUS_FAILED;
|
||||
}
|
||||
}
|
||||
@@ -452,10 +453,10 @@ fan_flow_type_handler__(netsnmp_request_info *req,
|
||||
|
||||
name_index = ONLP_SNMP_FAN_FLOW_TYPE_UNKNOWN;
|
||||
|
||||
if (fi->status & ONLP_FAN_STATUS_PRESENT) {
|
||||
if (fi->status & ONLP_FAN_STATUS_B2F) {
|
||||
if (ONLP_OID_PRESENT(fi)) {
|
||||
if (fi->dir == ONLP_FAN_DIR_B2F) {
|
||||
name_index = ONLP_SNMP_FAN_FLOW_TYPE_B2F;
|
||||
} else if (fi->status & ONLP_FAN_STATUS_F2B) {
|
||||
} else if (fi->dir == ONLP_FAN_DIR_F2B) {
|
||||
name_index = ONLP_SNMP_FAN_FLOW_TYPE_F2B;
|
||||
} else {
|
||||
/* Unknown */
|
||||
@@ -481,7 +482,7 @@ fan_rpm_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (fi->status & ONLP_FAN_STATUS_PRESENT)? fi->rpm: 0;
|
||||
value = ONLP_OID_PRESENT(fi) ? fi->rpm: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -502,7 +503,7 @@ fan_pct_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (fi->status & ONLP_FAN_STATUS_PRESENT)? fi->percentage: 0;
|
||||
value = ONLP_OID_PRESENT(fi) ? fi->percentage: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -522,7 +523,7 @@ fan_model_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
int len = (fi->status & ONLP_FAN_STATUS_PRESENT)? strlen(fi->model): 0;
|
||||
int len = ONLP_OID_PRESENT(fi) ? strlen(fi->model): 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_OCTET_STR,
|
||||
@@ -542,7 +543,7 @@ fan_serial_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
int len = (fi->status & ONLP_FAN_STATUS_PRESENT)? strlen(fi->serial): 0;
|
||||
int len = ONLP_OID_PRESENT(fi) ? strlen(fi->serial): 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_OCTET_STR,
|
||||
@@ -624,16 +625,16 @@ psu_status_handler__(netsnmp_request_info *req,
|
||||
}
|
||||
|
||||
value = ONLP_SNMP_SENSOR_STATUS_MISSING;
|
||||
if (pi->status & ONLP_PSU_STATUS_PRESENT) {
|
||||
if (ONLP_OID_PRESENT(pi)) {
|
||||
value = ONLP_SNMP_SENSOR_STATUS_GOOD;
|
||||
|
||||
/* failed or good is always reported */
|
||||
if (pi->status & ONLP_PSU_STATUS_FAILED) {
|
||||
if (ONLP_OID_FAILED(pi)) {
|
||||
value = ONLP_SNMP_SENSOR_STATUS_FAILED;
|
||||
}
|
||||
|
||||
/* if additional unplugged status is reported */
|
||||
if (pi->status & ONLP_PSU_STATUS_UNPLUGGED) {
|
||||
if (ONLP_OID_STATUS_FLAG_IS_SET(pi, UNPLUGGED)) {
|
||||
value = ONLP_SNMP_SENSOR_STATUS_FAILED;
|
||||
}
|
||||
|
||||
@@ -658,15 +659,22 @@ psu_current_type_handler__(netsnmp_request_info *req,
|
||||
}
|
||||
|
||||
name_index = ONLP_SNMP_PSU_TYPE_UNKNOWN;
|
||||
/* These values are mutual exclusive */
|
||||
if (pi->caps & ONLP_PSU_CAPS_AC) {
|
||||
name_index = ONLP_SNMP_PSU_TYPE_AC;
|
||||
} else if (pi->caps & ONLP_PSU_CAPS_DC12) {
|
||||
name_index = ONLP_SNMP_PSU_TYPE_DC12;
|
||||
} else if (pi->caps & ONLP_PSU_CAPS_DC48) {
|
||||
name_index = ONLP_SNMP_PSU_TYPE_DC48;
|
||||
} else {
|
||||
/* Unknown type */
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(pi, GET_TYPE)) {
|
||||
switch(pi->type)
|
||||
{
|
||||
case ONLP_PSU_TYPE_AC:
|
||||
name_index = ONLP_SNMP_PSU_TYPE_AC;
|
||||
break;
|
||||
case ONLP_PSU_TYPE_DC12:
|
||||
name_index = ONLP_SNMP_PSU_TYPE_DC12;
|
||||
break;
|
||||
case ONLP_PSU_TYPE_DC48:
|
||||
name_index = ONLP_SNMP_PSU_TYPE_DC48;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char* s = onlp_snmp_psu_type_name(name_index);
|
||||
@@ -687,7 +695,7 @@ psu_model_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
int len = (pi->status & ONLP_PSU_STATUS_PRESENT)? strlen(pi->model): 0;
|
||||
int len = ONLP_OID_PRESENT(pi) ? strlen(pi->model): 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_OCTET_STR,
|
||||
@@ -707,7 +715,7 @@ psu_serial_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
int len = (pi->status & ONLP_PSU_STATUS_PRESENT)? strlen(pi->serial): 0;
|
||||
int len = ONLP_OID_PRESENT(pi) ? strlen(pi->serial): 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_OCTET_STR,
|
||||
@@ -728,7 +736,7 @@ psu_vin_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (pi->status & ONLP_PSU_STATUS_PRESENT)? pi->mvin: 0;
|
||||
value = ONLP_OID_PRESENT(pi) ? pi->mvin: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -749,7 +757,7 @@ psu_vout_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (pi->status & ONLP_PSU_STATUS_PRESENT)? pi->mvout: 0;
|
||||
value = ONLP_OID_PRESENT(pi) ? pi->mvout: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -770,7 +778,7 @@ psu_iin_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (pi->status & ONLP_PSU_STATUS_PRESENT)? pi->miin: 0;
|
||||
value = ONLP_OID_PRESENT(pi) ? pi->miin: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -791,7 +799,7 @@ psu_iout_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (pi->status & ONLP_PSU_STATUS_PRESENT)? pi->miout: 0;
|
||||
value = ONLP_OID_PRESENT(pi) ? pi->miout: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -812,7 +820,7 @@ psu_pin_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (pi->status & ONLP_PSU_STATUS_PRESENT)? pi->mpin: 0;
|
||||
value = ONLP_OID_PRESENT(pi) ? pi->mpin: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -833,7 +841,7 @@ psu_pout_handler__(netsnmp_request_info *req,
|
||||
return;
|
||||
}
|
||||
|
||||
value = (pi->status & ONLP_PSU_STATUS_PRESENT)? pi->mpout: 0;
|
||||
value = ONLP_OID_PRESENT(pi) ? pi->mpout: 0;
|
||||
|
||||
snmp_set_var_typed_value(req->requestvb,
|
||||
ASN_GAUGE,
|
||||
@@ -1014,7 +1022,7 @@ update_tables__(void)
|
||||
|
||||
/* discover new sensors for all tables,
|
||||
* writing validity into next_info for all sensors */
|
||||
onlp_oid_iterate(ONLP_OID_SYS, 0, collect_sensors__, NULL);
|
||||
onlp_oid_iterate(ONLP_OID_CHASSIS, 0, collect_sensors__, NULL);
|
||||
|
||||
/* for each table: update all sensor info */
|
||||
for (i = ONLP_SNMP_SENSOR_TYPE_TEMP; i <= ONLP_SNMP_SENSOR_TYPE_MAX; i++) {
|
||||
|
||||
@@ -27,7 +27,7 @@ include $(ONL)/make/any.mk
|
||||
MODULE := libonlp-module
|
||||
include $(BUILDER)/standardinit.mk
|
||||
|
||||
DEPENDMODULES := AIM onlplib onlp cjson cjson_util sff IOF timer_wheel OS
|
||||
DEPENDMODULES := AIM onlplib onlp cjson cjson_util sff IOF timer_wheel OS uCli ELS
|
||||
|
||||
LIBONLP_PLATFORM_DEFAULTS := ../onlp-platform-defaults/$(BUILD_DIR)/bin/libonlp-platform-defaults.so
|
||||
LIBONLP_PLATFORM := ../onlp-platform/$(BUILD_DIR)/bin/libonlp-platform.so
|
||||
@@ -46,9 +46,11 @@ GLOBAL_CFLAGS += -DONLP_CONFIG_API_LOCK_GLOBAL_SHARED=1
|
||||
GLOBAL_CFLAGS += -DONLP_CONFIG_INCLUDE_SHLOCK_GLOBAL_INIT=1
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_PVS_SYSLOG=1
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_DAEMONIZE=1
|
||||
GLOBAL_CFLAGS += -DONLP_CONFIG_INCLUDE_UCLI=1
|
||||
GLOBAL_CFLAGS += -DUCLI_CONFIG_INCLUDE_ELS_LOOP=1
|
||||
|
||||
GLOBAL_CFLAGS += -fPIC
|
||||
GLOBAL_LINK_LIBS += -lpthread $(LIBONLP_PLATFORM) $(LIBONLP_PLATFORM_DEFAULTS)
|
||||
GLOBAL_LINK_LIBS += -lpthread -ledit $(LIBONLP_PLATFORM) $(LIBONLP_PLATFORM_DEFAULTS)
|
||||
|
||||
include $(BUILDER)/targets.mk
|
||||
|
||||
|
||||
32
packages/base/any/onlp/builds/platform/common.mk
Normal file
32
packages/base/any/onlp/builds/platform/common.mk
Normal file
@@ -0,0 +1,32 @@
|
||||
ifndef PLATFORM
|
||||
$(error $$PLATFORM not set)
|
||||
endif
|
||||
|
||||
ifndef ARCH
|
||||
# Determine ARCH from platform name
|
||||
ifeq ($(findstring x86-64-,$(PLATFORM)),x86-64-)
|
||||
ARCH := amd64
|
||||
endif
|
||||
|
||||
ifeq ($(findstring powerpc-,$(PLATFORM)),powerpc-)
|
||||
ARCH := powerpc
|
||||
endif
|
||||
|
||||
ifeq ($(findstring arm-,$(PLATFORM)),arm-)
|
||||
ARCH := armel
|
||||
endif
|
||||
|
||||
ifeq ($(findstring arm64-,$(PLATFORM)),arm64-)
|
||||
ARCH := arm64
|
||||
endif
|
||||
endif
|
||||
|
||||
ifndef ARCH
|
||||
$(error $$ARCH not set and the architecture cannot be determined from the given platform name ($(PLATFORM)))
|
||||
endif
|
||||
|
||||
ifndef PLATFORM_MODULE
|
||||
PLATFORM_MODULE := $(subst -,_,$(PLATFORM))
|
||||
endif
|
||||
|
||||
include $(ONL)/make/config.$(ARCH).mk
|
||||
41
packages/base/any/onlp/builds/platform/libonlp-platform.mk
Normal file
41
packages/base/any/onlp/builds/platform/libonlp-platform.mk
Normal file
@@ -0,0 +1,41 @@
|
||||
############################################################
|
||||
# <bsn.cl fy=2014 v=onl>
|
||||
#
|
||||
# Copyright 2014-2018 BigSwitch Networks, Inc.
|
||||
#
|
||||
# Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
# either express or implied. See the License for the specific
|
||||
# language governing permissions and limitations under the
|
||||
# License.
|
||||
#
|
||||
# </bsn.cl>
|
||||
############################################################
|
||||
include $(ONL)/packages/base/any/onlp/builds/platform/common.mk
|
||||
|
||||
MODULE := libonlp-$(PLATFORM)
|
||||
include $(BUILDER)/standardinit.mk
|
||||
|
||||
DEPENDMODULES := AIM IOF onlplib $(DEPENDMODULES) $(PLATFORM_MODULE)
|
||||
DEPENDMODULE_HEADERS := $(DEPENDMODULE_HEADERS) sff
|
||||
|
||||
include $(BUILDER)/dependmodules.mk
|
||||
|
||||
SHAREDLIB := libonlp-$(PLATFORM).so
|
||||
$(SHAREDLIB)_TARGETS := $(ALL_TARGETS)
|
||||
include $(BUILDER)/so.mk
|
||||
.DEFAULT_GOAL := $(SHAREDLIB)
|
||||
|
||||
GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
|
||||
GLOBAL_CFLAGS += -fPIC
|
||||
GLOBAL_LINK_LIBS += -lpthread
|
||||
|
||||
include $(BUILDER)/targets.mk
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################
|
||||
# <bsn.cl fy=2014 v=onl>
|
||||
#
|
||||
# Copyright 2014 BigSwitch Networks, Inc.
|
||||
# Copyright 2014-2018 BigSwitch Networks, Inc.
|
||||
#
|
||||
# Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
@@ -18,29 +18,26 @@
|
||||
#
|
||||
# </bsn.cl>
|
||||
############################################################
|
||||
#
|
||||
#
|
||||
#
|
||||
############################################################
|
||||
include $(ONL)/make/config.amd64.mk
|
||||
include $(ONL)/packages/base/any/onlp/builds/platform/common.mk
|
||||
|
||||
.DEFAULT_GOAL := onlpdump
|
||||
.DEFAULT_GOAL := onlps
|
||||
|
||||
MODULE := onlpdump
|
||||
MODULE := onlps
|
||||
include $(BUILDER)/standardinit.mk
|
||||
|
||||
DEPENDMODULES := AIM IOF onlp x86_64_accton_as7712_32x onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS
|
||||
DEPENDMODULES := $(DEPENDMODULES) AIM IOF onlp onlplib $(PLATFORM_MODULE) onlp_platform_defaults sff cjson cjson_util timer_wheel OS uCli ELS
|
||||
|
||||
include $(BUILDER)/dependmodules.mk
|
||||
|
||||
BINARY := onlpdump
|
||||
BINARY := onlps
|
||||
$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS)
|
||||
include $(BUILDER)/bin.mk
|
||||
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1
|
||||
GLOBAL_LINK_LIBS += -lpthread -lm
|
||||
GLOBAL_CFLAGS += -DUCLI_CONFIG_INCLUDE_ELS_LOOP=1
|
||||
GLOBAL_CFLAGS += -DONLP_CONFIG_INCLUDE_UCLI=1
|
||||
GLOBAL_LINK_LIBS += -lpthread -lm -ledit
|
||||
|
||||
include $(BUILDER)/targets.mk
|
||||
|
||||
1
packages/base/any/onlp/src/onlp/.gitignore
vendored
1
packages/base/any/onlp/src/onlp/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
*.mk
|
||||
@@ -51,12 +51,9 @@ cdefs: &cdefs
|
||||
- ONLP_CONFIG_INCLUDE_SHLOCK_GLOBAL_INIT:
|
||||
doc: "Include global shlock initialization at module init time."
|
||||
default: 0
|
||||
- ONLP_CONFIG_INCLUDE_PLATFORM_STATIC:
|
||||
doc: "Specify the platform name directly as a compile-time option."
|
||||
default: 0
|
||||
- ONLP_CONFIG_PLATFORM_STATIC:
|
||||
doc: "The name of the static platform if configured."
|
||||
default: "\"unknown\""
|
||||
- ONLP_CONFIG_PLATFORM_NAME:
|
||||
doc: "Static platform configuration."
|
||||
default: 'NULL'
|
||||
- ONLP_CONFIG_PLATFORM_FILENAME:
|
||||
doc: "The local filename containing the current platform identifier."
|
||||
default: "\"/etc/onl/platform\""
|
||||
@@ -88,6 +85,11 @@ cdefs: &cdefs
|
||||
doc: "Include API timing profiles."
|
||||
default: 0
|
||||
|
||||
|
||||
# Log Types
|
||||
onlp_log_types: &onlp_log_types
|
||||
- JSON
|
||||
|
||||
# Error codes
|
||||
onlp_status: &onlp_status
|
||||
- OK : 0
|
||||
@@ -101,13 +103,33 @@ onlp_status: &onlp_status
|
||||
|
||||
# OID Types
|
||||
oid_types: &oid_types
|
||||
- SYS : 1
|
||||
- THERMAL : 2
|
||||
- FAN : 3
|
||||
- PSU : 4
|
||||
- LED : 5
|
||||
- MODULE : 6
|
||||
- RTC : 7
|
||||
- CHASSIS : 1
|
||||
- MODULE : 2
|
||||
- THERMAL : 3
|
||||
- FAN : 4
|
||||
- PSU : 5
|
||||
- LED : 6
|
||||
- SFP : 7
|
||||
- GENERIC : 8
|
||||
|
||||
# OID Status Flags
|
||||
oid_status: &oid_status
|
||||
- PRESENT
|
||||
- FAILED
|
||||
- OPERATIONAL
|
||||
- UNPLUGGED
|
||||
|
||||
# OID Output Format
|
||||
oid_format_types: &oid_format_types
|
||||
- JSON
|
||||
- YAML
|
||||
- USER
|
||||
- DEBUG
|
||||
|
||||
# OID Output Flags
|
||||
oid_format_flags: &oid_format_flags
|
||||
- RECURSIVE
|
||||
- MISSING
|
||||
|
||||
# OID dump options
|
||||
oid_dump: &oid_dump
|
||||
@@ -120,8 +142,13 @@ oid_show: &oid_show
|
||||
- EXTENDED
|
||||
- YAML
|
||||
|
||||
# OID JSON Flags
|
||||
oid_json_flags: &oid_json_flags
|
||||
- RECURSIVE
|
||||
- UNSUPPORTED_FIELDS
|
||||
|
||||
# SFP Control
|
||||
sfp_control: &sfp_control
|
||||
sfp_control: &sfp_controls
|
||||
- RESET
|
||||
- RESET_STATE
|
||||
- RX_LOS
|
||||
@@ -131,46 +158,34 @@ sfp_control: &sfp_control
|
||||
- LP_MODE
|
||||
- POWER_OVERRIDE
|
||||
|
||||
# Fan modes
|
||||
fan_modes: &fan_modes
|
||||
- 'OFF'
|
||||
- SLOW
|
||||
- NORMAL
|
||||
- FAST
|
||||
- MAX
|
||||
# SFP Types
|
||||
sfp_types: &sfp_types
|
||||
- SFP
|
||||
- QSFP
|
||||
- SFP28
|
||||
- QSFP28
|
||||
|
||||
# Fan Capabilities
|
||||
fan_caps: &fan_caps
|
||||
- B2F : (1 << 0)
|
||||
- F2B : (1 << 1)
|
||||
- SET_RPM : (1 << 2)
|
||||
- SET_PERCENTAGE : (1 << 3)
|
||||
- GET_RPM : (1 << 4)
|
||||
- GET_PERCENTAGE : (1 << 5)
|
||||
- SET_DIR
|
||||
- GET_DIR
|
||||
- SET_RPM
|
||||
- SET_PERCENTAGE
|
||||
- GET_RPM
|
||||
- GET_PERCENTAGE
|
||||
|
||||
# Fan Direction
|
||||
fan_dirs: &fan_dirs
|
||||
- UNKNOWN
|
||||
- B2F
|
||||
- F2B
|
||||
|
||||
# Fan status
|
||||
fan_status: &fan_status
|
||||
- PRESENT : (1 << 0)
|
||||
- FAILED : (1 << 1)
|
||||
- B2F : (1 << 2)
|
||||
- F2B : (1 << 3)
|
||||
|
||||
# Thermal status
|
||||
thermal_status: &thermal_status
|
||||
- PRESENT : (1 << 0)
|
||||
- FAILED : (1 << 1)
|
||||
|
||||
# Thermal caps
|
||||
thermal_caps: &thermal_caps
|
||||
- GET_TEMPERATURE : (1 << 0)
|
||||
- GET_WARNING_THRESHOLD : (1 << 1)
|
||||
- GET_ERROR_THRESHOLD : (1 << 2)
|
||||
- GET_SHUTDOWN_THRESHOLD : (1 << 3)
|
||||
- GET_TEMPERATURE
|
||||
- GET_WARNING_THRESHOLD
|
||||
- GET_ERROR_THRESHOLD
|
||||
- GET_SHUTDOWN_THRESHOLD
|
||||
|
||||
# Thermal threshold, in milli-celsius
|
||||
thermal_threshold: &thermal_threshold
|
||||
@@ -180,78 +195,45 @@ thermal_threshold: &thermal_threshold
|
||||
|
||||
# LED caps
|
||||
led_caps: &led_caps
|
||||
- ON_OFF : (1 << 0)
|
||||
- CHAR : (1 << 1)
|
||||
- RED : (1 << 10)
|
||||
- RED_BLINKING : (1 << 11)
|
||||
- ORANGE : (1 << 12)
|
||||
- ORANGE_BLINKING : (1 << 13)
|
||||
- YELLOW : (1 << 14)
|
||||
- YELLOW_BLINKING : (1 << 15)
|
||||
- GREEN : (1 << 16)
|
||||
- GREEN_BLINKING : (1 << 17)
|
||||
- BLUE : (1 << 18)
|
||||
- BLUE_BLINKING : (1 << 19)
|
||||
- PURPLE : (1 << 20)
|
||||
- PURPLE_BLINKING : (1 << 21)
|
||||
- AUTO : (1 << 22)
|
||||
- AUTO_BLINKING : (1 << 23)
|
||||
|
||||
# LED status
|
||||
led_status: &led_status
|
||||
- PRESENT : (1 << 0)
|
||||
- FAILED : (1 << 1)
|
||||
- 'ON' : (1 << 2)
|
||||
|
||||
# LED modes
|
||||
# The enumerations MUST match the CAP bit positions.
|
||||
led_mode: &led_mode
|
||||
- 'OFF'
|
||||
- 'ON'
|
||||
- 'BLINKING'
|
||||
- 'RED' : 10
|
||||
- 'RED_BLINKING' : 11
|
||||
- 'ORANGE' : 12
|
||||
- 'ORANGE_BLINKING' : 13
|
||||
- 'YELLOW' : 14
|
||||
- 'YELLOW_BLINKING' : 15
|
||||
- 'GREEN' : 16
|
||||
- 'GREEN_BLINKING' : 17
|
||||
- 'BLUE' : 18
|
||||
- 'BLUE_BLINKING' : 19
|
||||
- 'PURPLE' : 20
|
||||
- 'PURPLE_BLINKING' : 21
|
||||
- 'AUTO' : 22
|
||||
- 'AUTO_BLINKING' : 23
|
||||
- AUTO
|
||||
- AUTO_BLINKING
|
||||
- CHAR
|
||||
- RED
|
||||
- RED_BLINKING
|
||||
- ORANGE
|
||||
- ORANGE_BLINKING
|
||||
- YELLOW
|
||||
- YELLOW_BLINKING
|
||||
- GREEN
|
||||
- GREEN_BLINKING
|
||||
- BLUE
|
||||
- BLUE_BLINKING
|
||||
- PURPLE
|
||||
- PURPLE_BLINKING
|
||||
|
||||
# PSU Status
|
||||
psu_status: &psu_status
|
||||
- PRESENT : (1 << 0)
|
||||
- FAILED : (1 << 1)
|
||||
- UNPLUGGED : (1 << 2)
|
||||
# PSU types
|
||||
psu_types: &psu_types
|
||||
- AC
|
||||
- DC12
|
||||
- DC48
|
||||
|
||||
# PSU caps
|
||||
psu_caps: &psu_caps
|
||||
- AC : (1 << 0)
|
||||
- DC12 : (1 << 1)
|
||||
- DC48 : (1 << 2)
|
||||
- VIN : (1 << 3)
|
||||
- VOUT : (1 << 4)
|
||||
- IIN : (1 << 5)
|
||||
- IOUT : (1 << 6)
|
||||
- PIN : (1 << 7)
|
||||
- POUT : (1 << 8)
|
||||
- GET_TYPE
|
||||
- GET_VIN
|
||||
- GET_VOUT
|
||||
- GET_IIN
|
||||
- GET_IOUT
|
||||
- GET_PIN
|
||||
- GET_POUT
|
||||
|
||||
# SFP Controls
|
||||
sfp_controls: &sfp_controls
|
||||
- RESET
|
||||
- RESET_STATE
|
||||
- RX_LOS
|
||||
- TX_FAULT
|
||||
- TX_DISABLE
|
||||
- TX_DISABLE_CHANNEL
|
||||
- LP_MODE
|
||||
- POWER_OVERRIDE
|
||||
|
||||
# OID Field Masks
|
||||
oid_field_masks:
|
||||
- OID_HDR_DESCRIPTION
|
||||
- OID_HDR_POID
|
||||
- OID_HDR_COIDS
|
||||
|
||||
definitions:
|
||||
cdefs:
|
||||
@@ -259,30 +241,66 @@ definitions:
|
||||
defs: *cdefs
|
||||
basename: onlp_config
|
||||
|
||||
aim_custom_log_macro:
|
||||
onlp:
|
||||
flags: *onlp_log_types
|
||||
prefix: ONLP_LOG_FLAG_
|
||||
|
||||
enum: &enums
|
||||
onlp_log_flag:
|
||||
members: *onlp_log_types
|
||||
|
||||
onlp_status:
|
||||
tag: onlp
|
||||
members: *onlp_status
|
||||
|
||||
onlp_oid_type:
|
||||
tag: oid
|
||||
members: *oid_types
|
||||
|
||||
onlp_oid_type_flag:
|
||||
tag: oid
|
||||
members: *oid_types
|
||||
flags: True
|
||||
flag_offset: 1
|
||||
|
||||
onlp_oid_status_flag:
|
||||
tag: oid
|
||||
members: *oid_status
|
||||
flags: True
|
||||
|
||||
onlp_oid_format:
|
||||
tag: oid
|
||||
members: *oid_format_types
|
||||
|
||||
onlp_oid_format_flags:
|
||||
tag: oid
|
||||
members: *oid_format_flags
|
||||
flags: True
|
||||
|
||||
onlp_oid_show:
|
||||
tag: oid
|
||||
members: *oid_show
|
||||
flags: True
|
||||
|
||||
onlp_oid_dump:
|
||||
tag: oid
|
||||
members: *oid_dump
|
||||
|
||||
onlp_oid_json_flag:
|
||||
tag: oid
|
||||
members: *oid_json_flags
|
||||
flags: True
|
||||
onlp_thermal_status:
|
||||
tag: thermal
|
||||
members: *thermal_status
|
||||
|
||||
onlp_thermal_caps:
|
||||
tag: thermal
|
||||
members: *thermal_caps
|
||||
flags: True
|
||||
|
||||
onlp_thermal_threshold:
|
||||
tag: thermal
|
||||
members: *thermal_threshold
|
||||
|
||||
onlp_sfp_control:
|
||||
tag: sfp1
|
||||
members: *sfp_controls
|
||||
@@ -292,33 +310,36 @@ definitions:
|
||||
members: *sfp_controls
|
||||
flags: True
|
||||
|
||||
onlp_fan_mode:
|
||||
tag: fan
|
||||
members: *fan_modes
|
||||
onlp_fan_status:
|
||||
tag: fan
|
||||
members: *fan_status
|
||||
onlp_sfp_type:
|
||||
tag: sfp2
|
||||
members: *sfp_types
|
||||
|
||||
onlp_fan_dir:
|
||||
tag: fan
|
||||
members: *fan_dirs
|
||||
|
||||
onlp_fan_caps:
|
||||
tag: fan
|
||||
members: *fan_caps
|
||||
flags: True
|
||||
|
||||
onlp_led_caps:
|
||||
tag: led
|
||||
members: *led_caps
|
||||
onlp_led_status:
|
||||
tag: led
|
||||
members: *led_status
|
||||
flags: True
|
||||
|
||||
onlp_led_mode:
|
||||
tag: led
|
||||
members: *led_mode
|
||||
onlp_psu_status:
|
||||
members: *led_caps
|
||||
|
||||
onlp_psu_type:
|
||||
tag: psu
|
||||
members: *psu_status
|
||||
members: *psu_types
|
||||
|
||||
onlp_psu_caps:
|
||||
tag: psu
|
||||
members: *psu_caps
|
||||
flags: True
|
||||
|
||||
pyenum: *enums
|
||||
|
||||
@@ -330,6 +351,8 @@ definitions:
|
||||
- strncpy
|
||||
- strlen
|
||||
|
||||
|
||||
|
||||
xenum:
|
||||
ONLP_ENUMERATION_ENTRY:
|
||||
members: *enums
|
||||
@@ -337,3 +360,19 @@ definitions:
|
||||
xmacro:
|
||||
ONLP_OID_TYPE_ENTRY:
|
||||
members: *oid_types
|
||||
allcases: True
|
||||
|
||||
ONLP_ASSET_INFO_ENTRY:
|
||||
members:
|
||||
- manufacturer, Manufacture, str
|
||||
- date, Date, str
|
||||
- part_number, Part Number, str
|
||||
- serial_number, Serial Number, str
|
||||
- hardware_revision, Hardware Revision, str
|
||||
- firmware_revision, Firmware Revision, str
|
||||
- cpld_revision, CPLD Revision, str
|
||||
- manufacture_date, Manufacter Date, str
|
||||
- description, Description, str
|
||||
- additional, Additional, str
|
||||
|
||||
pyenum: *enums
|
||||
79
packages/base/any/onlp/src/onlp/module/inc/onlp/attribute.h
Normal file
79
packages/base/any/onlp/src/onlp/module/inc/onlp/attribute.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2017 v=onl>
|
||||
*
|
||||
* Copyright 2017 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Attributes.
|
||||
*
|
||||
* @addtogroup attributes
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_ATTRIBUTE_H__
|
||||
#define __ONLP_ATTRIBUTE_H__
|
||||
|
||||
#include <onlp/oids.h>
|
||||
#include <onlp/onlp.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the attribute subsystem.
|
||||
*/
|
||||
int onlp_attribute_sw_init(void);
|
||||
int onlp_attribute_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Determine whether the OID supports the given attribute.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute name.
|
||||
*/
|
||||
int onlp_attribute_supported(onlp_oid_t oid, const char* attribute);
|
||||
|
||||
/**
|
||||
* @brief Set an attribute on the given OID.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute name.
|
||||
* @param value A pointer to the value.
|
||||
*/
|
||||
int onlp_attribute_set(onlp_oid_t oid, const char* attribute, void* value);
|
||||
|
||||
/**
|
||||
* @brief Get an attribute from the given OID.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute to retrieve.
|
||||
* @param[out] value Receives the attribute's value.
|
||||
*/
|
||||
int onlp_attribute_get(onlp_oid_t oid, const char* attribute,
|
||||
void** value);
|
||||
|
||||
/**
|
||||
* @brief Free an attribute value returned from onlp_attribute_get().
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute.
|
||||
* @param value The value.
|
||||
*/
|
||||
int onlp_attribute_free(onlp_oid_t oid, const char* attribute, void* value);
|
||||
|
||||
/**
|
||||
* @brief Attribute comparitor.
|
||||
*/
|
||||
#define ONLP_ATTRIBUTE_EQUALS(_a, _b) (!strcmp(_a, _b))
|
||||
|
||||
#endif /* __ONLP_ATTRIBUTE_H__ */
|
||||
/* @} */
|
||||
119
packages/base/any/onlp/src/onlp/module/inc/onlp/chassis.h
Normal file
119
packages/base/any/onlp/src/onlp/module/inc/onlp/chassis.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Chassis OID Interface.
|
||||
*
|
||||
* The Chassis OID represents the root of the system OID tree.
|
||||
* There must be one and only one Chassis OID.
|
||||
*
|
||||
*
|
||||
* @addtogroup oid-chassis
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
#ifndef __ONLP_CHASSIS_H__
|
||||
#define __ONLP_CHASSIS_H__
|
||||
|
||||
#include <onlp/onlp_config.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlplib/onie.h>
|
||||
#include <onlplib/pi.h>
|
||||
#include <onlp/oids.h>
|
||||
|
||||
/**
|
||||
* @brief Chassis Information Structure.
|
||||
*/
|
||||
|
||||
typedef struct onlp_chassis_info_s {
|
||||
/** OID Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/* Chassis objects have no dedicated fields. */
|
||||
|
||||
} onlp_chassis_info_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the chassis software module.
|
||||
* @note This will be called at software initialization
|
||||
* time. This should not initialize any hardware.
|
||||
*/
|
||||
int onlp_chassis_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize the chassis.
|
||||
* @param flags The initialization flags.
|
||||
*/
|
||||
int onlp_chassis_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the chassis software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_chassis_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the Chassis Header structure.
|
||||
* @param oid The Chassis oid.
|
||||
* @param[out] hdr Receives the hdr.
|
||||
*/
|
||||
int onlp_chassis_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
|
||||
/**
|
||||
* @brief Get the chassis info structure.
|
||||
* @param oid The Chassis oid.
|
||||
* @param[out] info
|
||||
*/
|
||||
int onlp_chassis_info_get(onlp_oid_t oid, onlp_chassis_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Format a chassis oid.
|
||||
* @param oid The chassis oid.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_chassis_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Format a chassis info structure.
|
||||
* @param info The chassis info structure.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_chassis_info_format(onlp_chassis_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_chassis_info_to_user_json(onlp_chassis_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_chassis_info_to_json(onlp_chassis_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_chassis_info_from_json(cJSON* cj, onlp_chassis_info_t* info);
|
||||
|
||||
|
||||
int onlp_chassis_environment(aim_pvs_t* pvs);
|
||||
|
||||
#endif /* __ONLP_CHASSIS_H_ */
|
||||
/* @} */
|
||||
@@ -1,44 +1,35 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
* Debug
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlp/sys.h>
|
||||
#include <onlp/oids.h>
|
||||
#include <onlp/sfp.h>
|
||||
#ifndef __ONLP_DEBUG_H__
|
||||
#define __ONLP_DEBUG_H__
|
||||
|
||||
void
|
||||
onlp_platform_dump(aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
/* Dump all OIDS, starting with the SYS OID */
|
||||
onlp_oid_dump(ONLP_OID_SYS, pvs, flags);
|
||||
aim_printf(pvs, "\nSFPs:\n");
|
||||
/* Dump all SFPs */
|
||||
onlp_sfp_dump(pvs);
|
||||
}
|
||||
#include <AIM/aim_pvs.h>
|
||||
|
||||
void
|
||||
onlp_platform_show(aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
onlp_oid_show(ONLP_OID_SYS, pvs, flags);
|
||||
}
|
||||
/**
|
||||
* @brief Debug Tool Entry Point
|
||||
*/
|
||||
int onlp_debug(aim_pvs_t* pvs, int argc, char* argv[]);
|
||||
|
||||
#endif /* __ONL_DEBUG_H__ */
|
||||
@@ -1,25 +1,28 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Fan Management.
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Fan Management.
|
||||
* @addtogroup oid-fan
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_FAN_H__
|
||||
@@ -28,11 +31,13 @@
|
||||
#include <onlp/oids.h>
|
||||
#include <onlp/onlp.h>
|
||||
|
||||
#include <BigList/biglist.h>
|
||||
|
||||
/* <auto.start.enum(tag:fan).define> */
|
||||
/** onlp_fan_caps */
|
||||
typedef enum onlp_fan_caps_e {
|
||||
ONLP_FAN_CAPS_B2F = (1 << 0),
|
||||
ONLP_FAN_CAPS_F2B = (1 << 1),
|
||||
ONLP_FAN_CAPS_SET_DIR = (1 << 0),
|
||||
ONLP_FAN_CAPS_GET_DIR = (1 << 1),
|
||||
ONLP_FAN_CAPS_SET_RPM = (1 << 2),
|
||||
ONLP_FAN_CAPS_SET_PERCENTAGE = (1 << 3),
|
||||
ONLP_FAN_CAPS_GET_RPM = (1 << 4),
|
||||
@@ -41,32 +46,13 @@ typedef enum onlp_fan_caps_e {
|
||||
|
||||
/** onlp_fan_dir */
|
||||
typedef enum onlp_fan_dir_e {
|
||||
ONLP_FAN_DIR_UNKNOWN,
|
||||
ONLP_FAN_DIR_B2F,
|
||||
ONLP_FAN_DIR_F2B,
|
||||
ONLP_FAN_DIR_LAST = ONLP_FAN_DIR_F2B,
|
||||
ONLP_FAN_DIR_COUNT,
|
||||
ONLP_FAN_DIR_INVALID = -1,
|
||||
} onlp_fan_dir_t;
|
||||
|
||||
/** onlp_fan_mode */
|
||||
typedef enum onlp_fan_mode_e {
|
||||
ONLP_FAN_MODE_OFF,
|
||||
ONLP_FAN_MODE_SLOW,
|
||||
ONLP_FAN_MODE_NORMAL,
|
||||
ONLP_FAN_MODE_FAST,
|
||||
ONLP_FAN_MODE_MAX,
|
||||
ONLP_FAN_MODE_LAST = ONLP_FAN_MODE_MAX,
|
||||
ONLP_FAN_MODE_COUNT,
|
||||
ONLP_FAN_MODE_INVALID = -1,
|
||||
} onlp_fan_mode_t;
|
||||
|
||||
/** onlp_fan_status */
|
||||
typedef enum onlp_fan_status_e {
|
||||
ONLP_FAN_STATUS_PRESENT = (1 << 0),
|
||||
ONLP_FAN_STATUS_FAILED = (1 << 1),
|
||||
ONLP_FAN_STATUS_B2F = (1 << 2),
|
||||
ONLP_FAN_STATUS_F2B = (1 << 3),
|
||||
} onlp_fan_status_t;
|
||||
/* <auto.end.enum(tag:fan).define> */
|
||||
|
||||
/**
|
||||
@@ -76,59 +62,83 @@ typedef struct onlp_fan_info_s {
|
||||
/** OID Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/* Status */
|
||||
uint32_t status;
|
||||
/** Current direction */
|
||||
onlp_fan_dir_t dir;
|
||||
|
||||
/* Capabilities */
|
||||
/** Capabilities */
|
||||
uint32_t caps;
|
||||
|
||||
/* Current fan speed, in RPM, if available */
|
||||
/** Current fan speed, in RPM, if available */
|
||||
int rpm;
|
||||
|
||||
/* Current fan percentage, if available */
|
||||
/** Current fan percentage, if available */
|
||||
int percentage;
|
||||
|
||||
/* Current fan mode, if available */
|
||||
onlp_fan_mode_t mode;
|
||||
|
||||
/* Model (if applicable) */
|
||||
/** Model (if applicable) */
|
||||
char model[ONLP_CONFIG_INFO_STR_MAX];
|
||||
|
||||
/* Serial Number (if applicable) */
|
||||
/** Serial Number (if applicable) */
|
||||
char serial[ONLP_CONFIG_INFO_STR_MAX];
|
||||
|
||||
} onlp_fan_info_t;
|
||||
|
||||
#define ONLP_FAN_INFO_CAP_IS_SET(_pinfo, _name) \
|
||||
((_pinfo)->caps & ONLP_FAN_CAPS_##_name)
|
||||
|
||||
/**
|
||||
* @brief Initialize the fan subsystem.
|
||||
* @brief Software Initialization of the Fan module.
|
||||
*/
|
||||
int onlp_fan_init(void);
|
||||
|
||||
int onlp_fan_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieve fan information.
|
||||
* @param id The fan OID.
|
||||
* @param rv [out] Receives the fan information.
|
||||
* @brief Hardware Initialization of the Fan module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_fan_info_get(onlp_oid_t id, onlp_fan_info_t* rv);
|
||||
int onlp_fan_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the fan's operational status.
|
||||
* @param id The fan OID.
|
||||
* @param rv [out] Receives the fan's operations status flags.
|
||||
* @notes Only operational state needs to be returned -
|
||||
* PRESENT/FAILED
|
||||
* @brief Deinitialize the fan software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_fan_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_fan_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the fan's OID hdr.
|
||||
* @param id The fan OID.
|
||||
* @param rv [out] Receives the OID header.
|
||||
* @param[out] hdr Receives the OID header.
|
||||
*/
|
||||
int onlp_fan_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* hdr);
|
||||
|
||||
/**
|
||||
* @brief Retrieve fan information.
|
||||
* @param id The fan OID.
|
||||
* @param[out] rv Receives the fan information.
|
||||
*/
|
||||
int onlp_fan_info_get(onlp_oid_t id, onlp_fan_info_t* rv);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Format a fan oid.
|
||||
* @param oid The fan oid.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_fan_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Format a fan information structure.
|
||||
* @param info The fan information structure.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_fan_info_format(onlp_fan_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Set the fan speed in RPMs.
|
||||
* @param id The fan OID.
|
||||
@@ -145,48 +155,36 @@ int onlp_fan_rpm_set(onlp_oid_t id, int rpm);
|
||||
*/
|
||||
int onlp_fan_percentage_set(onlp_oid_t id, int p);
|
||||
|
||||
/**
|
||||
* @brief Set the fan speed by mode.
|
||||
* @param id The fan OID.
|
||||
* @param mode The fan mode value.
|
||||
*/
|
||||
int onlp_fan_mode_set(onlp_oid_t id, onlp_fan_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief Set the fan direction.
|
||||
* @param id The fan OID.
|
||||
* @param dir The fan direction (B2F or F2B)
|
||||
* @notes Only called if both capabilities are set.
|
||||
* @note Only called if both capabilities are set.
|
||||
*/
|
||||
int onlp_fan_dir_set(onlp_oid_t id, onlp_fan_dir_t dir);
|
||||
|
||||
/**
|
||||
* @brief Fan OID debug dump.
|
||||
* @param id The fan OID.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
void onlp_fan_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags);
|
||||
/** Fan is present. */
|
||||
#define ONLP_FAN_STATUS_PRESENT(_fi) ((_fi).hdr.status & ONLP_OID_STATUS.PRESENT)
|
||||
|
||||
/**
|
||||
* @brief Show the given Fan OID.
|
||||
* @param id The Fan OID
|
||||
* @param pvs The output pvs
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
void onlp_fan_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Convenience macros for processing Fan status information.
|
||||
*/
|
||||
#define ONLP_FAN_STATUS_PRESENT(_fi) ((_fi).status & ONLP_FAN_STATUS_PRESENT)
|
||||
/** Fan is missing. */
|
||||
#define ONLP_FAN_STATUS_MISSING(_fi) (!ONLP_FAN_INFO_PRESENT(_fi))
|
||||
#define ONLP_FAN_STATUS_FAILED(_fi) ( (_fi).status & ONLP_FAN_STATUS_FAILED)
|
||||
|
||||
/** Fan has failed. */
|
||||
#define ONLP_FAN_STATUS_FAILED(_fi) ( (_fi).hdr.status & ONLP_OID_STATUS.FAILED)
|
||||
|
||||
/** Fan is operating normally */
|
||||
#define ONLP_FAN_STATUS_NORMAL(_fi) ( ONLP_FAN_STATUS_PRESENT(_fi) && !ONLP_FAN_STATUS_FAILED(_fi) )
|
||||
|
||||
|
||||
|
||||
|
||||
int onlp_fan_info_to_user_json(onlp_fan_info_t* info, cJSON** cj,
|
||||
uint32_t flags);
|
||||
|
||||
int onlp_fan_info_to_json(onlp_fan_info_t* info, cJSON** cj, uint32_t flags);
|
||||
int onlp_fan_info_from_json(cJSON* cj, onlp_fan_info_t* info);
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Enumeration Support Definitions.
|
||||
@@ -219,6 +217,7 @@ extern aim_map_si_t onlp_fan_caps_desc_map[];
|
||||
/** Strings macro. */
|
||||
#define ONLP_FAN_DIR_STRINGS \
|
||||
{\
|
||||
"UNKNOWN", \
|
||||
"B2F", \
|
||||
"F2B", \
|
||||
}
|
||||
@@ -239,56 +238,8 @@ const char* onlp_fan_dir_desc(onlp_fan_dir_t e);
|
||||
extern aim_map_si_t onlp_fan_dir_map[];
|
||||
/** onlp_fan_dir_desc_map table. */
|
||||
extern aim_map_si_t onlp_fan_dir_desc_map[];
|
||||
|
||||
/** Strings macro. */
|
||||
#define ONLP_FAN_MODE_STRINGS \
|
||||
{\
|
||||
"OFF", \
|
||||
"SLOW", \
|
||||
"NORMAL", \
|
||||
"FAST", \
|
||||
"MAX", \
|
||||
}
|
||||
/** Enum names. */
|
||||
const char* onlp_fan_mode_name(onlp_fan_mode_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_fan_mode_value(const char* str, onlp_fan_mode_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_fan_mode_desc(onlp_fan_mode_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_FAN_MODE_VALID(_e) \
|
||||
( (0 <= (_e)) && ((_e) <= ONLP_FAN_MODE_MAX))
|
||||
|
||||
/** onlp_fan_mode_map table. */
|
||||
extern aim_map_si_t onlp_fan_mode_map[];
|
||||
/** onlp_fan_mode_desc_map table. */
|
||||
extern aim_map_si_t onlp_fan_mode_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_fan_status_name(onlp_fan_status_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_fan_status_value(const char* str, onlp_fan_status_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_fan_status_desc(onlp_fan_status_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_fan_status_valid(onlp_fan_status_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_FAN_STATUS_VALID(_e) \
|
||||
(onlp_fan_status_valid((_e)))
|
||||
|
||||
/** onlp_fan_status_map table. */
|
||||
extern aim_map_si_t onlp_fan_status_map[];
|
||||
/** onlp_fan_status_desc_map table. */
|
||||
extern aim_map_si_t onlp_fan_status_desc_map[];
|
||||
/* <auto.end.enum(tag:fan).supportheader> */
|
||||
|
||||
|
||||
#endif /* __ONLP_FAN_H__ */
|
||||
|
||||
/* @} */
|
||||
|
||||
110
packages/base/any/onlp/src/onlp/module/inc/onlp/generic.h
Normal file
110
packages/base/any/onlp/src/onlp/module/inc/onlp/generic.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Generic OID Interface.
|
||||
* @addtogroup oid-generic
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
#ifndef __ONLP_GENERIC_H__
|
||||
#define __ONLP_GENERIC_H__
|
||||
|
||||
#include <onlp/onlp_config.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlplib/onie.h>
|
||||
#include <onlplib/pi.h>
|
||||
#include <onlp/oids.h>
|
||||
|
||||
/**
|
||||
* @brief Generic OID Information Structure.
|
||||
*/
|
||||
typedef struct onlp_generic_info_s {
|
||||
/** OID Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/* Generic objects have no dedicated fields. */
|
||||
|
||||
} onlp_generic_info_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the module software module.
|
||||
* @note This will be called at software initialization
|
||||
* time. This should not initialize any hardware.
|
||||
*/
|
||||
int onlp_generic_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize the module.
|
||||
* @param flags The initialization flags.
|
||||
*/
|
||||
int onlp_generic_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the generic software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_generic_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the generic header structure.
|
||||
* @param oid The Generic oid.
|
||||
* @param[out] hdr Receives the header.
|
||||
*/
|
||||
int onlp_generic_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
|
||||
/**
|
||||
* @brief Get the module info structure.
|
||||
* @param oid The Generic oid.
|
||||
* @param[out] info
|
||||
*/
|
||||
int onlp_generic_info_get(onlp_oid_t oid, onlp_generic_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Format a Generic OID.
|
||||
* @param oid The generic oid.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_generic_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Format a generic information structure.
|
||||
* @param info The generic info structure.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_generic_info_format(onlp_generic_info_t* info,
|
||||
onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_generic_info_to_user_json(onlp_generic_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_generic_info_to_json(onlp_generic_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_generic_info_from_json(cJSON* cj, onlp_generic_info_t* info);
|
||||
|
||||
#endif /* __ONLP_GENERIC_H_ */
|
||||
/* @} */
|
||||
@@ -31,51 +31,46 @@
|
||||
/* <auto.start.enum(tag:led).define> */
|
||||
/** onlp_led_caps */
|
||||
typedef enum onlp_led_caps_e {
|
||||
ONLP_LED_CAPS_ON_OFF = (1 << 0),
|
||||
ONLP_LED_CAPS_CHAR = (1 << 1),
|
||||
ONLP_LED_CAPS_RED = (1 << 10),
|
||||
ONLP_LED_CAPS_RED_BLINKING = (1 << 11),
|
||||
ONLP_LED_CAPS_ORANGE = (1 << 12),
|
||||
ONLP_LED_CAPS_ORANGE_BLINKING = (1 << 13),
|
||||
ONLP_LED_CAPS_YELLOW = (1 << 14),
|
||||
ONLP_LED_CAPS_YELLOW_BLINKING = (1 << 15),
|
||||
ONLP_LED_CAPS_GREEN = (1 << 16),
|
||||
ONLP_LED_CAPS_GREEN_BLINKING = (1 << 17),
|
||||
ONLP_LED_CAPS_BLUE = (1 << 18),
|
||||
ONLP_LED_CAPS_BLUE_BLINKING = (1 << 19),
|
||||
ONLP_LED_CAPS_PURPLE = (1 << 20),
|
||||
ONLP_LED_CAPS_PURPLE_BLINKING = (1 << 21),
|
||||
ONLP_LED_CAPS_AUTO = (1 << 22),
|
||||
ONLP_LED_CAPS_AUTO_BLINKING = (1 << 23),
|
||||
ONLP_LED_CAPS_OFF = (1 << 0),
|
||||
ONLP_LED_CAPS_AUTO = (1 << 1),
|
||||
ONLP_LED_CAPS_AUTO_BLINKING = (1 << 2),
|
||||
ONLP_LED_CAPS_CHAR = (1 << 3),
|
||||
ONLP_LED_CAPS_RED = (1 << 4),
|
||||
ONLP_LED_CAPS_RED_BLINKING = (1 << 5),
|
||||
ONLP_LED_CAPS_ORANGE = (1 << 6),
|
||||
ONLP_LED_CAPS_ORANGE_BLINKING = (1 << 7),
|
||||
ONLP_LED_CAPS_YELLOW = (1 << 8),
|
||||
ONLP_LED_CAPS_YELLOW_BLINKING = (1 << 9),
|
||||
ONLP_LED_CAPS_GREEN = (1 << 10),
|
||||
ONLP_LED_CAPS_GREEN_BLINKING = (1 << 11),
|
||||
ONLP_LED_CAPS_BLUE = (1 << 12),
|
||||
ONLP_LED_CAPS_BLUE_BLINKING = (1 << 13),
|
||||
ONLP_LED_CAPS_PURPLE = (1 << 14),
|
||||
ONLP_LED_CAPS_PURPLE_BLINKING = (1 << 15),
|
||||
} onlp_led_caps_t;
|
||||
|
||||
/** onlp_led_mode */
|
||||
typedef enum onlp_led_mode_e {
|
||||
ONLP_LED_MODE_OFF,
|
||||
ONLP_LED_MODE_ON,
|
||||
ONLP_LED_MODE_BLINKING,
|
||||
ONLP_LED_MODE_RED = 10,
|
||||
ONLP_LED_MODE_RED_BLINKING = 11,
|
||||
ONLP_LED_MODE_ORANGE = 12,
|
||||
ONLP_LED_MODE_ORANGE_BLINKING = 13,
|
||||
ONLP_LED_MODE_YELLOW = 14,
|
||||
ONLP_LED_MODE_YELLOW_BLINKING = 15,
|
||||
ONLP_LED_MODE_GREEN = 16,
|
||||
ONLP_LED_MODE_GREEN_BLINKING = 17,
|
||||
ONLP_LED_MODE_BLUE = 18,
|
||||
ONLP_LED_MODE_BLUE_BLINKING = 19,
|
||||
ONLP_LED_MODE_PURPLE = 20,
|
||||
ONLP_LED_MODE_PURPLE_BLINKING = 21,
|
||||
ONLP_LED_MODE_AUTO = 22,
|
||||
ONLP_LED_MODE_AUTO_BLINKING = 23,
|
||||
ONLP_LED_MODE_AUTO,
|
||||
ONLP_LED_MODE_AUTO_BLINKING,
|
||||
ONLP_LED_MODE_CHAR,
|
||||
ONLP_LED_MODE_RED,
|
||||
ONLP_LED_MODE_RED_BLINKING,
|
||||
ONLP_LED_MODE_ORANGE,
|
||||
ONLP_LED_MODE_ORANGE_BLINKING,
|
||||
ONLP_LED_MODE_YELLOW,
|
||||
ONLP_LED_MODE_YELLOW_BLINKING,
|
||||
ONLP_LED_MODE_GREEN,
|
||||
ONLP_LED_MODE_GREEN_BLINKING,
|
||||
ONLP_LED_MODE_BLUE,
|
||||
ONLP_LED_MODE_BLUE_BLINKING,
|
||||
ONLP_LED_MODE_PURPLE,
|
||||
ONLP_LED_MODE_PURPLE_BLINKING,
|
||||
ONLP_LED_MODE_LAST = ONLP_LED_MODE_PURPLE_BLINKING,
|
||||
ONLP_LED_MODE_COUNT,
|
||||
ONLP_LED_MODE_INVALID = -1,
|
||||
} onlp_led_mode_t;
|
||||
|
||||
/** onlp_led_status */
|
||||
typedef enum onlp_led_status_e {
|
||||
ONLP_LED_STATUS_PRESENT = (1 << 0),
|
||||
ONLP_LED_STATUS_FAILED = (1 << 1),
|
||||
ONLP_LED_STATUS_ON = (1 << 2),
|
||||
} onlp_led_status_t;
|
||||
/* <auto.end.enum(tag:led).define> */
|
||||
|
||||
|
||||
@@ -86,9 +81,6 @@ typedef struct onlp_led_info_s {
|
||||
/** Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/** Status */
|
||||
uint32_t status;
|
||||
|
||||
/** Capabilities */
|
||||
uint32_t caps;
|
||||
|
||||
@@ -101,41 +93,59 @@ typedef struct onlp_led_info_s {
|
||||
} onlp_led_info_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the LED subsystem.
|
||||
* @brief Software initialization of the LED module.
|
||||
*/
|
||||
int onlp_led_init(void);
|
||||
int onlp_led_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get LED information.
|
||||
* @param id The LED OID
|
||||
* @param rv [out] Receives the information structure.
|
||||
* @brief Hardware initialization of the LED module.
|
||||
*/
|
||||
int onlp_led_info_get(onlp_oid_t id, onlp_led_info_t* rv);
|
||||
int onlp_led_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Get the LED operational status.
|
||||
* @param id The LED OID
|
||||
* @param rv [out] Receives the operational status.
|
||||
* @brief Deinitialize the led software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_led_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_led_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the LED header.
|
||||
* @param id The LED OID
|
||||
* @param rv [out] Receives the header.
|
||||
* @param[out] rv Receives the header.
|
||||
*/
|
||||
int onlp_led_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Turn an LED on or off.
|
||||
* @brief Get LED information.
|
||||
* @param id The LED OID
|
||||
* @param on_or_off Led on (1) or LED off (0)
|
||||
* @param Relevant if the LED has the ON_OFF capability.
|
||||
* @note For the purposes of this function the
|
||||
* interpretation of "on" for multi-mode or multi-color LEDs
|
||||
* is up to the platform implementation.
|
||||
* @param[out] rv Receives the information structure.
|
||||
*/
|
||||
int onlp_led_set(onlp_oid_t id, int on_or_off);
|
||||
int onlp_led_info_get(onlp_oid_t id, onlp_led_info_t* rv);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Format an LED OID.
|
||||
* @param oid The OID.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_led_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Format an LED information structure.
|
||||
* @param info The information structure.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
int onlp_led_info_format(onlp_led_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the LED color
|
||||
@@ -143,7 +153,7 @@ int onlp_led_set(onlp_oid_t id, int on_or_off);
|
||||
* @param color The color.
|
||||
* @note Only relevant if the LED supports the color capability.
|
||||
*/
|
||||
int onlp_led_mode_set(onlp_oid_t id, onlp_led_mode_t color);
|
||||
int onlp_led_mode_set(onlp_oid_t id, onlp_led_mode_t mode);
|
||||
|
||||
|
||||
/**
|
||||
@@ -154,24 +164,9 @@ int onlp_led_mode_set(onlp_oid_t id, onlp_led_mode_t color);
|
||||
*/
|
||||
int onlp_led_char_set(onlp_oid_t id, char c);
|
||||
|
||||
/**
|
||||
* @brief LED OID debug dump
|
||||
* @param id The LED OID
|
||||
* @param pvs The output pvs
|
||||
* @param flags The output flags
|
||||
*/
|
||||
void onlp_led_dump(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Show the given LED OID.
|
||||
* @param id The LED OID
|
||||
* @param pvs The output pvs
|
||||
* @param flags The output flags
|
||||
*/
|
||||
void onlp_led_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
|
||||
|
||||
int onlp_led_info_to_user_json(onlp_led_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_led_info_to_json(onlp_led_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_led_info_from_json(cJSON* cj, onlp_led_info_t* info);
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
@@ -202,6 +197,26 @@ extern aim_map_si_t onlp_led_caps_map[];
|
||||
/** onlp_led_caps_desc_map table. */
|
||||
extern aim_map_si_t onlp_led_caps_desc_map[];
|
||||
|
||||
/** Strings macro. */
|
||||
#define ONLP_LED_MODE_STRINGS \
|
||||
{\
|
||||
"OFF", \
|
||||
"AUTO", \
|
||||
"AUTO_BLINKING", \
|
||||
"CHAR", \
|
||||
"RED", \
|
||||
"RED_BLINKING", \
|
||||
"ORANGE", \
|
||||
"ORANGE_BLINKING", \
|
||||
"YELLOW", \
|
||||
"YELLOW_BLINKING", \
|
||||
"GREEN", \
|
||||
"GREEN_BLINKING", \
|
||||
"BLUE", \
|
||||
"BLUE_BLINKING", \
|
||||
"PURPLE", \
|
||||
"PURPLE_BLINKING", \
|
||||
}
|
||||
/** Enum names. */
|
||||
const char* onlp_led_mode_name(onlp_led_mode_t e);
|
||||
|
||||
@@ -211,38 +226,14 @@ int onlp_led_mode_value(const char* str, onlp_led_mode_t* e, int substr);
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_led_mode_desc(onlp_led_mode_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_led_mode_valid(onlp_led_mode_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_LED_MODE_VALID(_e) \
|
||||
(onlp_led_mode_valid((_e)))
|
||||
( (0 <= (_e)) && ((_e) <= ONLP_LED_MODE_PURPLE_BLINKING))
|
||||
|
||||
/** onlp_led_mode_map table. */
|
||||
extern aim_map_si_t onlp_led_mode_map[];
|
||||
/** onlp_led_mode_desc_map table. */
|
||||
extern aim_map_si_t onlp_led_mode_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_led_status_name(onlp_led_status_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_led_status_value(const char* str, onlp_led_status_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_led_status_desc(onlp_led_status_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_led_status_valid(onlp_led_status_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_LED_STATUS_VALID(_e) \
|
||||
(onlp_led_status_valid((_e)))
|
||||
|
||||
/** onlp_led_status_map table. */
|
||||
extern aim_map_si_t onlp_led_status_map[];
|
||||
/** onlp_led_status_desc_map table. */
|
||||
extern aim_map_si_t onlp_led_status_desc_map[];
|
||||
/* <auto.end.enum(tag:led).supportheader> */
|
||||
|
||||
#endif /* __ONLP_LED_H__ */
|
||||
|
||||
95
packages/base/any/onlp/src/onlp/module/inc/onlp/module.h
Normal file
95
packages/base/any/onlp/src/onlp/module/inc/onlp/module.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Module OID Interface.
|
||||
* @addtogroup oid-module
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
#ifndef __ONLP_MODULE_H__
|
||||
#define __ONLP_MODULE_H__
|
||||
|
||||
#include <onlp/onlp_config.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlplib/onie.h>
|
||||
#include <onlplib/pi.h>
|
||||
#include <onlp/oids.h>
|
||||
|
||||
/**
|
||||
* @brief Module OID Information Structure.
|
||||
*/
|
||||
typedef struct onlp_module_info_s {
|
||||
/** OID Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/* Module objects have no dedicated fields. */
|
||||
|
||||
} onlp_module_info_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the module software module.
|
||||
* @note This will be called at software initialization
|
||||
* time. This should not initialize any hardware.
|
||||
*/
|
||||
int onlp_module_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize the module.
|
||||
* @param flags The initialization flags.
|
||||
*/
|
||||
int onlp_module_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the module software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_module_sw_denit(void);
|
||||
|
||||
/*
|
||||
* @brief Get the module header structure.
|
||||
* @param oid The Module oid.
|
||||
* @param[out] hdr Receives the header.
|
||||
*/
|
||||
int onlp_module_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
|
||||
/**
|
||||
* @brief Get the module info structure.
|
||||
* @param oid The Module oid.
|
||||
* @param[out] info
|
||||
*/
|
||||
int onlp_module_info_get(onlp_oid_t oid, onlp_module_info_t* info);
|
||||
|
||||
int onlp_module_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_module_info_format(onlp_module_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_module_info_to_user_json(onlp_module_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_module_info_to_json(onlp_module_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_module_info_from_json(cJSON* cj, onlp_module_info_t* info);
|
||||
|
||||
#endif /* __ONLP_MODULE_H_ */
|
||||
/* @} */
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <stdint.h>
|
||||
#include <AIM/aim_pvs.h>
|
||||
#include <IOF/iof.h>
|
||||
#include <BigList/biglist.h>
|
||||
#include <cjson/cJSON.h>
|
||||
|
||||
/**
|
||||
* System peripherals are identified by a 32bit OID.
|
||||
@@ -49,10 +51,36 @@ typedef uint32_t onlp_oid_t;
|
||||
/* <auto.start.enum(tag:oid).define> */
|
||||
/** onlp_oid_dump */
|
||||
typedef enum onlp_oid_dump_e {
|
||||
ONLP_OID_DUMP_RECURSE = (1 << 0),
|
||||
ONLP_OID_DUMP_EVEN_IF_ABSENT = (1 << 1),
|
||||
ONLP_OID_DUMP_RECURSE,
|
||||
ONLP_OID_DUMP_EVEN_IF_ABSENT,
|
||||
ONLP_OID_DUMP_LAST = ONLP_OID_DUMP_EVEN_IF_ABSENT,
|
||||
ONLP_OID_DUMP_COUNT,
|
||||
ONLP_OID_DUMP_INVALID = -1,
|
||||
} onlp_oid_dump_t;
|
||||
|
||||
/** onlp_oid_format */
|
||||
typedef enum onlp_oid_format_e {
|
||||
ONLP_OID_FORMAT_JSON,
|
||||
ONLP_OID_FORMAT_YAML,
|
||||
ONLP_OID_FORMAT_USER,
|
||||
ONLP_OID_FORMAT_DEBUG,
|
||||
ONLP_OID_FORMAT_LAST = ONLP_OID_FORMAT_DEBUG,
|
||||
ONLP_OID_FORMAT_COUNT,
|
||||
ONLP_OID_FORMAT_INVALID = -1,
|
||||
} onlp_oid_format_t;
|
||||
|
||||
/** onlp_oid_format_flags */
|
||||
typedef enum onlp_oid_format_flags_e {
|
||||
ONLP_OID_FORMAT_FLAGS_RECURSIVE = (1 << 0),
|
||||
ONLP_OID_FORMAT_FLAGS_MISSING = (1 << 1),
|
||||
} onlp_oid_format_flags_t;
|
||||
|
||||
/** onlp_oid_json_flag */
|
||||
typedef enum onlp_oid_json_flag_e {
|
||||
ONLP_OID_JSON_FLAG_RECURSIVE = (1 << 0),
|
||||
ONLP_OID_JSON_FLAG_UNSUPPORTED_FIELDS = (1 << 1),
|
||||
} onlp_oid_json_flag_t;
|
||||
|
||||
/** onlp_oid_show */
|
||||
typedef enum onlp_oid_show_e {
|
||||
ONLP_OID_SHOW_RECURSE = (1 << 0),
|
||||
@@ -60,18 +88,48 @@ typedef enum onlp_oid_show_e {
|
||||
ONLP_OID_SHOW_YAML = (1 << 2),
|
||||
} onlp_oid_show_t;
|
||||
|
||||
/** onlp_oid_status_flag */
|
||||
typedef enum onlp_oid_status_flag_e {
|
||||
ONLP_OID_STATUS_FLAG_PRESENT = (1 << 0),
|
||||
ONLP_OID_STATUS_FLAG_FAILED = (1 << 1),
|
||||
ONLP_OID_STATUS_FLAG_OPERATIONAL = (1 << 2),
|
||||
ONLP_OID_STATUS_FLAG_UNPLUGGED = (1 << 3),
|
||||
} onlp_oid_status_flag_t;
|
||||
|
||||
/** onlp_oid_type */
|
||||
typedef enum onlp_oid_type_e {
|
||||
ONLP_OID_TYPE_SYS = 1,
|
||||
ONLP_OID_TYPE_THERMAL = 2,
|
||||
ONLP_OID_TYPE_FAN = 3,
|
||||
ONLP_OID_TYPE_PSU = 4,
|
||||
ONLP_OID_TYPE_LED = 5,
|
||||
ONLP_OID_TYPE_MODULE = 6,
|
||||
ONLP_OID_TYPE_RTC = 7,
|
||||
ONLP_OID_TYPE_CHASSIS = 1,
|
||||
ONLP_OID_TYPE_MODULE = 2,
|
||||
ONLP_OID_TYPE_THERMAL = 3,
|
||||
ONLP_OID_TYPE_FAN = 4,
|
||||
ONLP_OID_TYPE_PSU = 5,
|
||||
ONLP_OID_TYPE_LED = 6,
|
||||
ONLP_OID_TYPE_SFP = 7,
|
||||
ONLP_OID_TYPE_GENERIC = 8,
|
||||
} onlp_oid_type_t;
|
||||
|
||||
/** onlp_oid_type_flag */
|
||||
typedef enum onlp_oid_type_flag_e {
|
||||
ONLP_OID_TYPE_FLAG_CHASSIS = (1 << 1),
|
||||
ONLP_OID_TYPE_FLAG_MODULE = (1 << 2),
|
||||
ONLP_OID_TYPE_FLAG_THERMAL = (1 << 3),
|
||||
ONLP_OID_TYPE_FLAG_FAN = (1 << 4),
|
||||
ONLP_OID_TYPE_FLAG_PSU = (1 << 5),
|
||||
ONLP_OID_TYPE_FLAG_LED = (1 << 6),
|
||||
ONLP_OID_TYPE_FLAG_SFP = (1 << 7),
|
||||
ONLP_OID_TYPE_FLAG_GENERIC = (1 << 8),
|
||||
} onlp_oid_type_flag_t;
|
||||
/* <auto.end.enum(tag:oid).define> */
|
||||
|
||||
/**
|
||||
* Represents a set of oid_type_flags.
|
||||
*/
|
||||
typedef uint32_t onlp_oid_type_flags_t;
|
||||
|
||||
/**
|
||||
* Represents a set of oid_status_flags;
|
||||
*/
|
||||
typedef uint32_t onlp_oid_status_flags_t;
|
||||
|
||||
/**
|
||||
* Get the or set the type of an OID
|
||||
@@ -80,23 +138,68 @@ typedef enum onlp_oid_type_e {
|
||||
#define ONLP_OID_TYPE_CREATE(_type, _id) ( ( (_type) << 24) | (_id))
|
||||
#define ONLP_OID_IS_TYPE(_type,_id) (ONLP_OID_TYPE_GET((_id)) == _type)
|
||||
#define ONLP_OID_ID_GET(_id) (_id & 0xFFFFFF)
|
||||
#define ONLP_OID_TYPE_VALIDATE(_type, _id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_TYPE(_type, _id)) { \
|
||||
return ONLP_STATUS_E_PARAM; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ONLP_OID_TYPE_VALIDATE_NR(_type, _id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_TYPE(_type, _id)) { \
|
||||
return; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ONLP_OID_IS_TYPE_FLAGS(_flags, _id) ((_flags & (1 << ONLP_OID_TYPE_GET(_id))))
|
||||
#define ONLP_OID_IS_TYPE_FLAGSZ(_flags, _id) ((_flags == 0) || ONLP_OID_IS_TYPE_FLAGS(_flags, _id))
|
||||
|
||||
#define ONLP_CHASSIS_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_CHASSIS, _id)
|
||||
#define ONLP_THERMAL_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_THERMAL, _id)
|
||||
#define ONLP_FAN_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_FAN, _id)
|
||||
#define ONLP_PSU_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_PSU, _id)
|
||||
#define ONLP_LED_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, _id)
|
||||
#define ONLP_SFP_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_SFP, _id)
|
||||
#define ONLP_MODULE_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_MODULE, _id)
|
||||
|
||||
#define ONLP_OID_IS_THERMAL(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_THERMAL,_id)
|
||||
#define ONLP_OID_IS_FAN(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_FAN,_id)
|
||||
#define ONLP_OID_IS_PSU(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_PSU,_id)
|
||||
#define ONLP_OID_IS_LED(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_LED,_id)
|
||||
#define ONLP_OID_IS_MODULE(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_MODULE,_id)
|
||||
#define ONLP_OID_IS_CHASSIS(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_CHASSIS, _id)
|
||||
#define ONLP_OID_CHASSIS_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_CHASSIS, _id)
|
||||
#define ONLP_OID_CHASSIS_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_CHASSIS, _id)
|
||||
|
||||
#define ONLP_OID_IS_THERMAL(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_THERMAL, _id)
|
||||
#define ONLP_OID_THERMAL_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_THERMAL, _id)
|
||||
#define ONLP_OID_THERMAL_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_THERMAL, _id)
|
||||
|
||||
#define ONLP_OID_IS_FAN(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_FAN, _id)
|
||||
#define ONLP_OID_FAN_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_FAN, _id)
|
||||
#define ONLP_OID_FAN_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_FAN, _id)
|
||||
|
||||
#define ONLP_OID_IS_PSU(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_PSU, _id)
|
||||
#define ONLP_OID_PSU_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_PSU, _id)
|
||||
#define ONLP_OID_PSU_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_PSU, _id)
|
||||
|
||||
#define ONLP_OID_IS_LED(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_LED, _id)
|
||||
#define ONLP_OID_LED_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_LED, _id)
|
||||
#define ONLP_OID_LED_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_LED, _id)
|
||||
|
||||
#define ONLP_OID_IS_SFP(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_SFP, _id)
|
||||
#define ONLP_OID_SFP_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_SFP, _id)
|
||||
#define ONLP_OID_SFP_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_SFP, _id)
|
||||
|
||||
#define ONLP_OID_IS_MODULE(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_MODULE, _id)
|
||||
#define ONLP_OID_MODULE_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_MODULE, _id)
|
||||
#define ONLP_OID_MODULE_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_MODULE, _id)
|
||||
|
||||
#define ONLP_OID_IS_GENERIC(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_GENERIC, _id)
|
||||
#define ONLP_OID_GENERIC_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_GENERIC, _id)
|
||||
#define ONLP_OID_GENERIC_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_GENERIC, _id)
|
||||
|
||||
|
||||
/**
|
||||
* There is only one SYS OID. This value should be used.
|
||||
* There is only one Chassis OID. This value should be used.
|
||||
*/
|
||||
#define ONLP_OID_SYS ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_SYS, 1)
|
||||
#define ONLP_OID_CHASSIS ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_CHASSIS, 1)
|
||||
|
||||
/**
|
||||
* All OIDs have user-level description strings:
|
||||
@@ -106,7 +209,7 @@ typedef enum onlp_oid_type_e {
|
||||
typedef char onlp_oid_desc_t[ONLP_OID_DESC_SIZE];
|
||||
|
||||
/* fixme */
|
||||
#define ONLP_OID_TABLE_SIZE 32
|
||||
#define ONLP_OID_TABLE_SIZE 256
|
||||
typedef onlp_oid_t onlp_oid_table_t[ONLP_OID_TABLE_SIZE];
|
||||
#define ONLP_OID_TABLE_SIZE_BYTES (sizeof(onlp_oid_t)*ONLP_OID_TABLE_SIZE)
|
||||
#define ONLP_OID_TABLE_COPY(_dst, _src) memcpy(_dst, _src, ONLP_OID_TABLE_SIZE_BYTES)
|
||||
@@ -119,6 +222,7 @@ typedef onlp_oid_t onlp_oid_table_t[ONLP_OID_TABLE_SIZE];
|
||||
#define ONLP_OID_THERMAL_ENTRY(_id, _desc, _parent_type, _parent_id) \
|
||||
{ ONLP_THERMAL_ID_CREATE(_id), _desc, ONLP_OID_TYPE_CREATE(_parent_type, _parent_id) }
|
||||
|
||||
|
||||
/**
|
||||
* All OID objects contain this header as the first member.
|
||||
*/
|
||||
@@ -131,16 +235,102 @@ typedef struct onlp_oid_hdr_s {
|
||||
onlp_oid_t poid;
|
||||
/** The children of this OID */
|
||||
onlp_oid_table_t coids;
|
||||
|
||||
/** The current status (if applicable) */
|
||||
onlp_oid_status_flags_t status;
|
||||
|
||||
} onlp_oid_hdr_t;
|
||||
|
||||
|
||||
void onlp_oid_dump(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags);
|
||||
void onlp_oid_table_dump(onlp_oid_table_t table, aim_pvs_t* pvs,
|
||||
uint32_t flags);
|
||||
/**
|
||||
* @brief Get the OID header for a given OID.
|
||||
* @param oid The oid
|
||||
* @param[out] hdr Receives the header
|
||||
*/
|
||||
int onlp_oid_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
|
||||
void onlp_oid_show(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags);
|
||||
void onlp_oid_table_show(onlp_oid_table_t table, aim_pvs_t* pvs,
|
||||
uint32_t flags);
|
||||
/**
|
||||
* @brief Get the information structure for a given OID.
|
||||
* @param oid The oid
|
||||
* @param[out] info Receives a pointer to the information structure.
|
||||
*/
|
||||
int onlp_oid_info_get(onlp_oid_t oid, onlp_oid_hdr_t** info);
|
||||
|
||||
int onlp_oid_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_oid_info_format(onlp_oid_hdr_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_oid_table_format(onlp_oid_table_t table, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Iterator
|
||||
*/
|
||||
typedef int (*onlp_oid_iterate_f)(onlp_oid_t oid, void* cookie);
|
||||
|
||||
/**
|
||||
* @brief Iterate over all platform OIDs.
|
||||
* @param oid The root OID.
|
||||
* @param type The OID type filter (optional)
|
||||
* @param itf The iterator function.
|
||||
* @param cookie The cookie.
|
||||
*/
|
||||
int onlp_oid_iterate(onlp_oid_t oid, onlp_oid_type_flags_t types,
|
||||
onlp_oid_iterate_f itf, void* cookie);
|
||||
|
||||
|
||||
int onlp_oid_info_get_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t flags, biglist_t** list);
|
||||
|
||||
int onlp_oid_info_format_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t get_flags,
|
||||
onlp_oid_format_t format, aim_pvs_t* pvs,
|
||||
uint32_t format_flags);
|
||||
|
||||
int onlp_oid_hdr_get_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t flags, biglist_t** list);
|
||||
|
||||
int onlp_oid_hdr_format_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t get_flags,
|
||||
onlp_oid_format_t format, aim_pvs_t* pvs,
|
||||
uint32_t format_flags);
|
||||
|
||||
int onlp_oid_get_all_free(biglist_t* list);
|
||||
|
||||
/**
|
||||
* Manipulating OID Status Flags
|
||||
*/
|
||||
#define ONLP_OID_STATUS_FLAGS_GET(_ptr) \
|
||||
(((onlp_oid_hdr_t*)_ptr)->status)
|
||||
|
||||
#define ONLP_OID_STATUS_FLAG_GET_VALUE(_ptr, _name) \
|
||||
AIM_FLAG_GET_VALUE(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name)
|
||||
|
||||
#define ONLP_OID_STATUS_FLAG_SET_VALUE(_ptr, _name) \
|
||||
AIM_FLAG_SET_VALUE(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name)
|
||||
|
||||
#define ONLP_OID_STATUS_FLAG_SET(_ptr, _name) \
|
||||
AIM_FLAG_SET(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name)
|
||||
|
||||
#define ONLP_OID_STATUS_FLAG_CLR(_ptr, _name) \
|
||||
AIM_FLAG_CLR(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name)
|
||||
|
||||
#define ONLP_OID_STATUS_FLAG_IS_SET(_ptr, _name) \
|
||||
AIM_FLAG_IS_SET(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name)
|
||||
|
||||
#define ONLP_OID_STATUS_FLAG_NOT_SET(_ptr, _name) \
|
||||
AIM_FLAG_NOT_SET(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name)
|
||||
|
||||
/**
|
||||
* Common Shorthands
|
||||
*/
|
||||
#define ONLP_OID_PRESENT(_ptr) \
|
||||
ONLP_OID_STATUS_FLAG_IS_SET(_ptr, PRESENT)
|
||||
|
||||
#define ONLP_OID_FAILED(_ptr) \
|
||||
ONLP_OID_STATUS_FLAG_IS_SET(_ptr, FAILED)
|
||||
|
||||
/**
|
||||
* @brief Iterate over all OIDS in the given table that match the given expression.
|
||||
@@ -171,31 +361,62 @@ void onlp_oid_table_show(onlp_oid_table_t table, aim_pvs_t* pvs,
|
||||
|
||||
|
||||
/**
|
||||
* Iterator
|
||||
* @brief Return whether an OID is present or not.
|
||||
*/
|
||||
typedef int (*onlp_oid_iterate_f)(onlp_oid_t oid, void* cookie);
|
||||
int onlp_oid_is_present(onlp_oid_t* oid);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Iterate over all platform OIDs.
|
||||
* @param oid The root OID.
|
||||
* @param type The OID type filter (optional)
|
||||
* @param itf The iterator function.
|
||||
* @param cookie The cookie.
|
||||
* @brief OID -> String Representation
|
||||
*/
|
||||
int onlp_oid_iterate(onlp_oid_t oid, onlp_oid_type_t type,
|
||||
onlp_oid_iterate_f itf, void* cookie);
|
||||
int onlp_oid_to_str(onlp_oid_t oid, char* rstr);
|
||||
int onlp_oid_to_user_str(onlp_oid_t oid, char* rstr);
|
||||
|
||||
/**
|
||||
* @brief Get the OID header for a given OID.
|
||||
* @param oid The oid
|
||||
* @param hdr [out] Receives the header
|
||||
* @brief String Represenation -> OID
|
||||
*/
|
||||
int onlp_oid_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
int onlp_oid_from_str(char* str, onlp_oid_t* roid);
|
||||
|
||||
/**
|
||||
* @brief OID Table -> JSON
|
||||
* @param table The table.
|
||||
* @param[out] Receives the JSON array object.
|
||||
*/
|
||||
int onlp_oid_table_to_json(onlp_oid_table_t table, cJSON** cjp);
|
||||
|
||||
/**
|
||||
* @brief JSON -> OID Table
|
||||
* @param cj The CJSON array object.
|
||||
* @param[out] table The table to populate.
|
||||
*/
|
||||
int onlp_oid_table_from_json(cJSON* cj, onlp_oid_table_t table);
|
||||
|
||||
/**
|
||||
* @brief OID Header -> JSON
|
||||
* @param hdr The header
|
||||
* @param[out] cj Receives the JSON representation.
|
||||
*/
|
||||
int onlp_oid_hdr_to_json(onlp_oid_hdr_t* hdr, cJSON** cj, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief JSON -> OID Header
|
||||
* @param cj The source json
|
||||
* @param[out] hdr receives the header.
|
||||
*/
|
||||
int onlp_oid_hdr_from_json(cJSON* cj, onlp_oid_hdr_t* hdr);
|
||||
|
||||
int onlp_oid_info_to_json(onlp_oid_hdr_t* info, cJSON** cj, uint32_t flags);
|
||||
/**
|
||||
* @brief OID -> JSON
|
||||
*/
|
||||
int onlp_oid_to_user_json(onlp_oid_t oid, cJSON** rv, uint32_t flags);
|
||||
int onlp_oid_to_json(onlp_oid_t oid, cJSON** rv, uint32_t flags);
|
||||
int onlp_oid_from_json(cJSON* cj, onlp_oid_hdr_t** hdr, biglist_t** all, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Verify OID <-> JSON conversions for the given OID (testing).
|
||||
*/
|
||||
int onlp_oid_json_verify(onlp_oid_t oid);
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
@@ -205,6 +426,12 @@ int onlp_oid_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
*
|
||||
*****************************************************************************/
|
||||
/* <auto.start.enum(tag:oid).supportheader> */
|
||||
/** Strings macro. */
|
||||
#define ONLP_OID_DUMP_STRINGS \
|
||||
{\
|
||||
"RECURSE", \
|
||||
"EVEN_IF_ABSENT", \
|
||||
}
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_dump_name(onlp_oid_dump_t e);
|
||||
|
||||
@@ -214,18 +441,83 @@ int onlp_oid_dump_value(const char* str, onlp_oid_dump_t* e, int substr);
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_dump_desc(onlp_oid_dump_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_oid_dump_valid(onlp_oid_dump_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_DUMP_VALID(_e) \
|
||||
(onlp_oid_dump_valid((_e)))
|
||||
( (0 <= (_e)) && ((_e) <= ONLP_OID_DUMP_EVEN_IF_ABSENT))
|
||||
|
||||
/** onlp_oid_dump_map table. */
|
||||
extern aim_map_si_t onlp_oid_dump_map[];
|
||||
/** onlp_oid_dump_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_dump_desc_map[];
|
||||
|
||||
/** Strings macro. */
|
||||
#define ONLP_OID_FORMAT_STRINGS \
|
||||
{\
|
||||
"JSON", \
|
||||
"YAML", \
|
||||
"USER", \
|
||||
"DEBUG", \
|
||||
}
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_format_name(onlp_oid_format_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_oid_format_value(const char* str, onlp_oid_format_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_format_desc(onlp_oid_format_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_FORMAT_VALID(_e) \
|
||||
( (0 <= (_e)) && ((_e) <= ONLP_OID_FORMAT_DEBUG))
|
||||
|
||||
/** onlp_oid_format_map table. */
|
||||
extern aim_map_si_t onlp_oid_format_map[];
|
||||
/** onlp_oid_format_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_format_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_format_flags_name(onlp_oid_format_flags_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_oid_format_flags_value(const char* str, onlp_oid_format_flags_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_format_flags_desc(onlp_oid_format_flags_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_oid_format_flags_valid(onlp_oid_format_flags_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_FORMAT_FLAGS_VALID(_e) \
|
||||
(onlp_oid_format_flags_valid((_e)))
|
||||
|
||||
/** onlp_oid_format_flags_map table. */
|
||||
extern aim_map_si_t onlp_oid_format_flags_map[];
|
||||
/** onlp_oid_format_flags_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_format_flags_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_json_flag_name(onlp_oid_json_flag_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_oid_json_flag_value(const char* str, onlp_oid_json_flag_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_json_flag_desc(onlp_oid_json_flag_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_oid_json_flag_valid(onlp_oid_json_flag_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_JSON_FLAG_VALID(_e) \
|
||||
(onlp_oid_json_flag_valid((_e)))
|
||||
|
||||
/** onlp_oid_json_flag_map table. */
|
||||
extern aim_map_si_t onlp_oid_json_flag_map[];
|
||||
/** onlp_oid_json_flag_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_json_flag_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_show_name(onlp_oid_show_t e);
|
||||
|
||||
@@ -247,6 +539,27 @@ extern aim_map_si_t onlp_oid_show_map[];
|
||||
/** onlp_oid_show_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_show_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_status_flag_name(onlp_oid_status_flag_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_oid_status_flag_value(const char* str, onlp_oid_status_flag_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_status_flag_desc(onlp_oid_status_flag_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_oid_status_flag_valid(onlp_oid_status_flag_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_STATUS_FLAG_VALID(_e) \
|
||||
(onlp_oid_status_flag_valid((_e)))
|
||||
|
||||
/** onlp_oid_status_flag_map table. */
|
||||
extern aim_map_si_t onlp_oid_status_flag_map[];
|
||||
/** onlp_oid_status_flag_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_status_flag_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_type_name(onlp_oid_type_t e);
|
||||
|
||||
@@ -267,6 +580,27 @@ int onlp_oid_type_valid(onlp_oid_type_t e);
|
||||
extern aim_map_si_t onlp_oid_type_map[];
|
||||
/** onlp_oid_type_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_type_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_type_flag_name(onlp_oid_type_flag_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_oid_type_flag_value(const char* str, onlp_oid_type_flag_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_type_flag_desc(onlp_oid_type_flag_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_oid_type_flag_valid(onlp_oid_type_flag_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_TYPE_FLAG_VALID(_e) \
|
||||
(onlp_oid_type_flag_valid((_e)))
|
||||
|
||||
/** onlp_oid_type_flag_map table. */
|
||||
extern aim_map_si_t onlp_oid_type_flag_map[];
|
||||
/** onlp_oid_type_flag_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_type_flag_desc_map[];
|
||||
/* <auto.end.enum(tag:oid).supportheader> */
|
||||
|
||||
#endif /* __ONLP_OID_H__ */
|
||||
|
||||
@@ -54,12 +54,24 @@ typedef enum onlp_status_e {
|
||||
#define ONLP_UNSUPPORTED(_rv) \
|
||||
((_rv) == ONLP_STATUS_E_UNSUPPORTED)
|
||||
|
||||
#define ONLP_TRY(_expr) \
|
||||
do { \
|
||||
int _rv = (_expr); \
|
||||
if(ONLP_FAILURE(_rv)) { \
|
||||
AIM_LOG_ERROR("%s returned %{onlp_status}", #_expr, _rv); \
|
||||
return _rv; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize all subsystems.
|
||||
*/
|
||||
int onlp_init(void);
|
||||
int onlp_sw_init(const char* platform);
|
||||
|
||||
int onlp_denit(void);
|
||||
int onlp_hw_init(uint32_t flags);
|
||||
|
||||
int onlp_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Dump the current platform data.
|
||||
|
||||
@@ -27,14 +27,29 @@
|
||||
|
||||
|
||||
/* <auto.start.xmacro(ALL).define> */
|
||||
#ifdef ONLP_ASSET_INFO_ENTRY
|
||||
ONLP_ASSET_INFO_ENTRY(manufacturer, Manufacture, str)
|
||||
ONLP_ASSET_INFO_ENTRY(date, Date, str)
|
||||
ONLP_ASSET_INFO_ENTRY(part_number, Part Number, str)
|
||||
ONLP_ASSET_INFO_ENTRY(serial_number, Serial Number, str)
|
||||
ONLP_ASSET_INFO_ENTRY(hardware_revision, Hardware Revision, str)
|
||||
ONLP_ASSET_INFO_ENTRY(firmware_revision, Firmware Revision, str)
|
||||
ONLP_ASSET_INFO_ENTRY(cpld_revision, CPLD Revision, str)
|
||||
ONLP_ASSET_INFO_ENTRY(manufacture_date, Manufacter Date, str)
|
||||
ONLP_ASSET_INFO_ENTRY(description, Description, str)
|
||||
ONLP_ASSET_INFO_ENTRY(additional, Additional, str)
|
||||
#undef ONLP_ASSET_INFO_ENTRY
|
||||
#endif
|
||||
|
||||
#ifdef ONLP_OID_TYPE_ENTRY
|
||||
ONLP_OID_TYPE_ENTRY(SYS, 1)
|
||||
ONLP_OID_TYPE_ENTRY(THERMAL, 2)
|
||||
ONLP_OID_TYPE_ENTRY(FAN, 3)
|
||||
ONLP_OID_TYPE_ENTRY(PSU, 4)
|
||||
ONLP_OID_TYPE_ENTRY(LED, 5)
|
||||
ONLP_OID_TYPE_ENTRY(MODULE, 6)
|
||||
ONLP_OID_TYPE_ENTRY(RTC, 7)
|
||||
ONLP_OID_TYPE_ENTRY(CHASSIS, 1, CHASSIS, chassis)
|
||||
ONLP_OID_TYPE_ENTRY(MODULE, 2, MODULE, module)
|
||||
ONLP_OID_TYPE_ENTRY(THERMAL, 3, THERMAL, thermal)
|
||||
ONLP_OID_TYPE_ENTRY(FAN, 4, FAN, fan)
|
||||
ONLP_OID_TYPE_ENTRY(PSU, 5, PSU, psu)
|
||||
ONLP_OID_TYPE_ENTRY(LED, 6, LED, led)
|
||||
ONLP_OID_TYPE_ENTRY(SFP, 7, SFP, sfp)
|
||||
ONLP_OID_TYPE_ENTRY(GENERIC, 8, GENERIC, generic)
|
||||
#undef ONLP_OID_TYPE_ENTRY
|
||||
#endif
|
||||
/* <auto.end.xmacro(ALL).define> */
|
||||
@@ -43,21 +58,24 @@ ONLP_OID_TYPE_ENTRY(RTC, 7)
|
||||
#ifdef ONLP_ENUMERATION_ENTRY
|
||||
ONLP_ENUMERATION_ENTRY(onlp_fan_caps, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_fan_dir, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_fan_mode, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_fan_status, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_led_caps, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_led_mode, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_led_status, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_log_flag, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_dump, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_format, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_format_flags, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_json_flag, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_show, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_status_flag, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_type, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_type_flag, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_psu_caps, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_psu_status, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_psu_type, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_sfp_control, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_sfp_control_flag, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_sfp_type, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_status, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_thermal_caps, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_thermal_status, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_thermal_threshold, "")
|
||||
#undef ONLP_ENUMERATION_ENTRY
|
||||
#endif
|
||||
|
||||
@@ -1,29 +1,23 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief onlp Configuration Header
|
||||
@@ -31,7 +25,7 @@
|
||||
* @addtogroup onlp-config
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_CONFIG_H__
|
||||
#define __ONLP_CONFIG_H__
|
||||
|
||||
@@ -135,23 +129,13 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_CONFIG_INCLUDE_PLATFORM_STATIC
|
||||
* ONLP_CONFIG_PLATFORM_NAME
|
||||
*
|
||||
* Specify the platform name directly as a compile-time option. */
|
||||
* Static platform configuration. */
|
||||
|
||||
|
||||
#ifndef ONLP_CONFIG_INCLUDE_PLATFORM_STATIC
|
||||
#define ONLP_CONFIG_INCLUDE_PLATFORM_STATIC 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_CONFIG_PLATFORM_STATIC
|
||||
*
|
||||
* The name of the static platform if configured. */
|
||||
|
||||
|
||||
#ifndef ONLP_CONFIG_PLATFORM_STATIC
|
||||
#define ONLP_CONFIG_PLATFORM_STATIC "unknown"
|
||||
#ifndef ONLP_CONFIG_PLATFORM_NAME
|
||||
#define ONLP_CONFIG_PLATFORM_NAME NULL
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -26,20 +26,60 @@
|
||||
#define __ONLP_DOX_H__
|
||||
|
||||
/**
|
||||
* @defgroup onlp onlp - onlp Description
|
||||
*
|
||||
|
||||
The documentation overview for this module should go here.
|
||||
@mainpage This is the main page.
|
||||
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @defgroup onlp-onlp Public Interface
|
||||
* @defgroup onlp-config Compile Time Configuration
|
||||
* @defgroup onlp-porting Porting Macros
|
||||
*
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
This is text.
|
||||
@section s1 Section1
|
||||
Foobar
|
||||
@section s2 Section2
|
||||
Foobar2
|
||||
|
||||
@defgroup onlp-main ONLP
|
||||
@{
|
||||
|
||||
@defgroup onlp-appication ONLP Application Interfaces
|
||||
@{
|
||||
|
||||
@defgroup oid-interfaces General OID Interfaces
|
||||
These interfaces are available on all OIDs.
|
||||
@{
|
||||
@defgroup attributes Attribute Interface
|
||||
@defgroup assets Asset Interface
|
||||
@defgroup onie ONIE Interface
|
||||
@}
|
||||
|
||||
@defgroup oid-types OID Types
|
||||
Software interfaces by OID Type.
|
||||
@{
|
||||
@defgroup oid-chassis Chassis
|
||||
@defgroup oid-module Modules
|
||||
@defgroup oid-thermal Thermals
|
||||
@defgroup oid-fan Fans
|
||||
@defgroup oid-psu PSUs
|
||||
@defgroup oid-sfp SFPs
|
||||
@defgroup oid-generic Generics
|
||||
@}
|
||||
@}
|
||||
|
||||
@defgroup onlp-platform Platform Implementation Interfaces
|
||||
These document the requires for implementing the platform interfaces.
|
||||
@{
|
||||
@defgroup chassisi Chassis
|
||||
@defgroup modulei Modules
|
||||
@defgroup thermali Thermals
|
||||
@defgroup fani Fans
|
||||
@defgroup psui PSUs
|
||||
@defgroup sfpi SFPs
|
||||
@}
|
||||
|
||||
@defgroup module-interfaces Module Documentation
|
||||
@{
|
||||
@defgroup onlp-config Compile Time Configuration
|
||||
@defgroup onlp-porting Porting Macros
|
||||
@}
|
||||
@}
|
||||
|
||||
*/
|
||||
|
||||
#endif /* __ONLP_DOX_H__ */
|
||||
|
||||
74
packages/base/any/onlp/src/onlp/module/inc/onlp/platform.h
Normal file
74
packages/base/any/onlp/src/onlp/module/inc/onlp/platform.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* Platform.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __ONLP_PLATFORM_H__
|
||||
#define __ONLP_PLATFORM_H__
|
||||
|
||||
#include <onlp/onlp_config.h>
|
||||
#include <onlp/onlp.h>
|
||||
|
||||
#include <AIM/aim_pvs.h>
|
||||
|
||||
/**
|
||||
* @brief Get the current ONL platform name.
|
||||
*/
|
||||
char* onlp_platform_name_get(void);
|
||||
|
||||
/**
|
||||
* @brief Platform software init.
|
||||
*/
|
||||
int onlp_platform_sw_init(const char* platform);
|
||||
|
||||
/**
|
||||
* @brief Platform Hardware init.
|
||||
* @param flags The init flags.
|
||||
*/
|
||||
int onlp_platform_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the chassis software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_platform_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Start the platform management thread.
|
||||
* @param block Whether the call should block on completion.
|
||||
*/
|
||||
int onlp_platform_manager_start(int block);
|
||||
|
||||
/**
|
||||
* @brief Stop the platform management thread.
|
||||
* @param block Block on termination.
|
||||
*/
|
||||
int onlp_platform_manager_stop(int block);
|
||||
|
||||
/**
|
||||
* @brief Join the platform management thread.
|
||||
*/
|
||||
int onlp_platform_manager_join(void);
|
||||
|
||||
/**
|
||||
* @brief Perform any pending platform management activities.
|
||||
* @note A call to this function will perform any pending
|
||||
* platform management activities. It is not intended to block
|
||||
* for an extended period of time.
|
||||
*/
|
||||
void onlp_platform_manager_manage(void);
|
||||
|
||||
/**
|
||||
* @brief Run in platform manager dameon mode.
|
||||
*/
|
||||
void
|
||||
onlp_platform_manager_daemon(const char* name, const char* logfile,
|
||||
const char* pidfile, char** argv);
|
||||
/**
|
||||
* @brief Call the platform debug hook.
|
||||
*/
|
||||
int onlp_platform_debug(aim_pvs_t* pvs, int argc, char** argv);
|
||||
|
||||
#endif /* __ONLP_PLATFORM_H__ */
|
||||
@@ -0,0 +1,74 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2017 v=onl>
|
||||
*
|
||||
* Copyright 2017 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Attribute Platform Implementation.
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_ATTRIBUTEI_H__
|
||||
#define __ONLP_ATTRIBUTEI_H__
|
||||
|
||||
#include <onlp/attribute.h>
|
||||
#include <onlp/onlp.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the attribute subsystem.
|
||||
*/
|
||||
int onlp_attributei_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize the attribute subsystem.
|
||||
*/
|
||||
int onlp_attributei_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Determine whether the OID supports the given attributei.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute name.
|
||||
*/
|
||||
int onlp_attributei_supported(onlp_oid_t id, const char* attribute);
|
||||
|
||||
/**
|
||||
* @brief Set an attribute on the given OID.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute name.
|
||||
* @param value A pointer to the value.
|
||||
*/
|
||||
int onlp_attributei_set(onlp_oid_t oid, const char* attribute, void* value);
|
||||
|
||||
/**
|
||||
* @brief Get an attribute from the given OID.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute to retrieve.
|
||||
* @param[out] value Receives the attributei's value.
|
||||
*/
|
||||
int onlp_attributei_get(onlp_oid_t id, const char* attribute,
|
||||
void** value);
|
||||
|
||||
/**
|
||||
* @brief Free an attribute value returned from onlp_attributei_get().
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute.
|
||||
* @param value The value.
|
||||
*/
|
||||
int onlp_attributei_free(onlp_oid_t id, const char* attribute, void* value);
|
||||
|
||||
|
||||
#endif /* __ONLP_ATTRIBUTEI_H__ */
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef __ONLP_PLATFORMI_COMMON_H__
|
||||
#define __ONLP_PLATFORMI_COMMON_H__
|
||||
|
||||
/*
|
||||
* Interchange includes between subsystems
|
||||
*/
|
||||
#include <onlp/platformi/chassisi.h>
|
||||
#include <onlp/platformi/attributei.h>
|
||||
#include <onlp/platformi/fani.h>
|
||||
#include <onlp/platformi/psui.h>
|
||||
#include <onlp/platformi/thermali.h>
|
||||
#include <onlp/platformi/sfpi.h>
|
||||
#include <onlp/platformi/ledi.h>
|
||||
#include <onlp/platformi/platformi.h>
|
||||
#include <onlp/platformi/debugi.h>
|
||||
|
||||
/*
|
||||
* Common includes needed for subsystem implementations.
|
||||
*/
|
||||
#include <onlplib/i2c.h>
|
||||
#include <onlplib/file.h>
|
||||
#include <onlplib/mmap.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#endif /* __ONLP_PLATFORMI_COMMON_H__ */
|
||||
@@ -0,0 +1,68 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Chassis Platform Interface.
|
||||
* @addtogroup chassisi
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_CHASSISI_H__
|
||||
#define __ONLP_CHASSISI_H__
|
||||
|
||||
#include <onlp/chassis.h>
|
||||
|
||||
/**
|
||||
* @brief Software initializaiton of the Chassis module.
|
||||
*/
|
||||
int onlp_chassisi_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Hardware initializaiton of the Chassis module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_chassisi_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the chassis software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_chassisi_sw_denit(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the chassis hdr structure.
|
||||
* @param oid The Chassis OID.
|
||||
* @param[out] hdr Receives the header.
|
||||
*/
|
||||
int onlp_chassisi_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
|
||||
/**
|
||||
* @brief Get the chassis info structure.
|
||||
* @param oid The Chassis OID.
|
||||
* @param[out] info Receives the chassis information.
|
||||
*/
|
||||
int onlp_chassisi_info_get(onlp_oid_t oid, onlp_chassis_info_t* info);
|
||||
|
||||
#endif /* __ONLP_CHASSISI_H__ */
|
||||
/* @} */
|
||||
@@ -0,0 +1,18 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __ONLP_DEBUGI_H__
|
||||
#define __ONLP_DEBUGI_H__
|
||||
|
||||
#include <onlp/debug.h>
|
||||
|
||||
/**
|
||||
* @brief Generic debug tool entry point.
|
||||
* @note This does not hold the API lock.
|
||||
*/
|
||||
int onlp_debugi(aim_pvs_t* pvs, int argc, char* argv[]);
|
||||
|
||||
#endif /* __ONLP_DEBUGI_H__ */
|
||||
@@ -1,25 +1,28 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Fan Platform Implementation.
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Fan Platform Implementation.
|
||||
* @addtogroup fani
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_FANI_H__
|
||||
@@ -28,33 +31,38 @@
|
||||
#include <onlp/fan.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the fan platform subsystem.
|
||||
* @brief Software initialization of the Fan module.
|
||||
*/
|
||||
int onlp_fani_init(void);
|
||||
int onlp_fani_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get the information structure for the given fan OID.
|
||||
* @param id The fan OID
|
||||
* @param rv [out] Receives the fan information.
|
||||
* @brief Hardware initialization of the Fan module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* rv);
|
||||
int onlp_fani_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the fan's operational status.
|
||||
* @param id The fan OID.
|
||||
* @param rv [out] Receives the fan's operations status flags.
|
||||
* @notes Only operational state needs to be returned -
|
||||
* PRESENT/FAILED
|
||||
* @brief Deinitialize the fan software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_fani_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_fani_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the fan's OID hdr.
|
||||
* @param id The fan OID.
|
||||
* @param rv [out] Receives the OID header.
|
||||
* @param[out] hdr Receives the OID header.
|
||||
*/
|
||||
int onlp_fani_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* hdr);
|
||||
|
||||
/**
|
||||
* @brief Get the information structure for the given fan OID.
|
||||
* @param id The fan OID
|
||||
* @param[out] rv Receives the fan information.
|
||||
*/
|
||||
int onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Set the fan speed in RPM.
|
||||
* @param id The fan OID
|
||||
@@ -72,14 +80,6 @@ int onlp_fani_rpm_set(onlp_oid_t id, int rpm);
|
||||
*/
|
||||
int onlp_fani_percentage_set(onlp_oid_t id, int p);
|
||||
|
||||
/**
|
||||
* @brief Set the fan mode.
|
||||
* @param id The fan OID.
|
||||
* @param mode The new fan mode.
|
||||
*/
|
||||
int onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the fan direction (if supported).
|
||||
* @param id The fan OID
|
||||
@@ -87,13 +87,6 @@ int onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode);
|
||||
*/
|
||||
int onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir);
|
||||
|
||||
/**
|
||||
* @brief Generic fan ioctl
|
||||
* @param id The fan OID
|
||||
* @param vargs The variable argument list for the ioctl call.
|
||||
* @param Optional
|
||||
*/
|
||||
int onlp_fani_ioctl(onlp_oid_t fid, va_list vargs);
|
||||
|
||||
#endif /* __ONLP_FANI_H__ */
|
||||
|
||||
/* @} */
|
||||
|
||||
@@ -28,46 +28,37 @@
|
||||
#include <onlp/led.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the LED subsystem.
|
||||
* @brief Software initialization of the LED module.
|
||||
*/
|
||||
int onlp_ledi_init(void);
|
||||
int onlp_ledi_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get the information for the given LED
|
||||
* @param id The LED OID
|
||||
* @param rv [out] Receives the LED information.
|
||||
* @brief Hardware initialization of the LED module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* rv);
|
||||
int onlp_ledi_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Get the LED operational status.
|
||||
* @param id The LED OID
|
||||
* @param rv [out] Receives the operational status.
|
||||
* @brief Deinitialize the led software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_ledi_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_ledi_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the LED header.
|
||||
* @param id The LED OID
|
||||
* @param rv [out] Receives the header.
|
||||
* @param[out] rv Receives the header.
|
||||
*/
|
||||
int onlp_ledi_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Turn an LED on or off
|
||||
* @brief Get the information for the given LED
|
||||
* @param id The LED OID
|
||||
* @param on_or_off (boolean) on if 1 off if 0
|
||||
* @param This function is only relevant if the ONOFF capability is set.
|
||||
* @notes See onlp_led_set() for a description of the default behavior.
|
||||
* @param[out] rv Receives the LED information.
|
||||
*/
|
||||
int onlp_ledi_set(onlp_oid_t id, int on_or_off);
|
||||
|
||||
/**
|
||||
* @brief LED ioctl
|
||||
* @param id The LED OID
|
||||
* @param vargs The variable argument list for the ioctl call.
|
||||
*/
|
||||
int onlp_ledi_ioctl(onlp_oid_t id, va_list vargs);
|
||||
int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Set the LED mode.
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Platform Interface.
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_PLATFORMI_H__
|
||||
#define __ONLP_PLATFORMI_H__
|
||||
|
||||
#include <onlp/platform.h>
|
||||
|
||||
/**
|
||||
* @brief Return the name of the the platform implementation.
|
||||
* @notes This will be called prior to any other calls into the
|
||||
* platform driver, including the onlp_platformi_sw_init() function below.
|
||||
*
|
||||
* The platform implementation name should match the current
|
||||
* ONLP platform name.
|
||||
*
|
||||
* IF the platform implementation name equals the current platform name,
|
||||
* initialization will continue.
|
||||
*
|
||||
* If the platform implementation name does not match, the following will be
|
||||
* attempted:
|
||||
*
|
||||
* onlp_platformi_set(current_platform_name);
|
||||
* If this call is successful, initialization will continue.
|
||||
* If this call fails, platform initialization will abort().
|
||||
*
|
||||
* The onlp_platformi_set() function is optional.
|
||||
* The onlp_platformi_get() is not optional.
|
||||
*/
|
||||
const char* onlp_platformi_get(void);
|
||||
|
||||
int onlp_platformi_set(const char* platform);
|
||||
|
||||
/**
|
||||
* @brief Initialize the platform software module.
|
||||
* @param This should not touch the hardware.
|
||||
*/
|
||||
int onlp_platformi_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Platform module hardware initialization.
|
||||
* @param flags The initialization flags.
|
||||
*/
|
||||
int onlp_platformi_hw_init(uint32_t flags);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the platform manager features.
|
||||
*/
|
||||
int onlp_platformi_manage_init(void);
|
||||
|
||||
/**
|
||||
* @brief Perform necessary platform fan management.
|
||||
* @note This function should automatically adjust the FAN speeds
|
||||
* according to the platform conditions.
|
||||
*/
|
||||
int onlp_platformi_manage_fans(void);
|
||||
|
||||
/**
|
||||
* @brief Perform necessary platform LED management.
|
||||
* @note This function should automatically adjust the LED indicators
|
||||
* according to the platform conditions.
|
||||
*/
|
||||
int onlp_platformi_manage_leds(void);
|
||||
|
||||
#endif /* __ONLP_PLATFORMI_H__ */
|
||||
@@ -1,25 +1,28 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Power Supply Management Implementation.
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Power Supply Management Implementation.
|
||||
* @addtogroup psui
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_PSUI_H__
|
||||
@@ -28,37 +31,38 @@
|
||||
#include <onlp/psu.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the PSU subsystem.
|
||||
* @brief Software initialization of the PSU module.
|
||||
*/
|
||||
int onlp_psui_init(void);
|
||||
int onlp_psui_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get the information structure for the given PSU
|
||||
* @param id The PSU OID
|
||||
* @param rv [out] Receives the PSU information.
|
||||
* @brief Hardware initialization of the PSU module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* rv);
|
||||
int onlp_psui_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Get the PSU's operational status.
|
||||
* @param id The PSU OID.
|
||||
* @param rv [out] Receives the operational status.
|
||||
* @brief Deinitialize the psu software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_psui_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_psui_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the PSU's oid header.
|
||||
* @param id The PSU OID.
|
||||
* @param rv [out] Receives the header.
|
||||
* @param[out] rv Receives the header.
|
||||
*/
|
||||
int onlp_psui_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Generic PSU ioctl
|
||||
* @brief Get the information structure for the given PSU
|
||||
* @param id The PSU OID
|
||||
* @param vargs The variable argument list for the ioctl call.
|
||||
* @param[out] rv Receives the PSU information.
|
||||
*/
|
||||
int onlp_psui_ioctl(onlp_oid_t pid, va_list vargs);
|
||||
int onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* rv);
|
||||
|
||||
|
||||
#endif /* __ONLP_PSUI_H__ */
|
||||
/* @} */
|
||||
|
||||
@@ -17,13 +17,16 @@
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* SFP Platform Implementation Interface.
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief SFP Platform Implementation Interface.
|
||||
* This interface must be implemented and available for all
|
||||
* platforms that support SFP interfaces.
|
||||
*
|
||||
* @addtogroup sfpi
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_SFPI_H__
|
||||
#define __ONLP_SFPI_H__
|
||||
@@ -33,19 +36,41 @@
|
||||
#include <sff/sff.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the SFPI subsystem.
|
||||
* @brief Software initialization of the SFP module.
|
||||
*/
|
||||
int onlp_sfpi_init(void);
|
||||
int onlp_sfpi_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Hardware initialization of the SFP module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_sfpi_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the chassis software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_sfpi_sw_denit(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the bitmap of SFP-capable port numbers.
|
||||
* @param bmap [out] Receives the bitmap.
|
||||
* @param[out] bmap Receives the bitmap.
|
||||
*/
|
||||
int onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap);
|
||||
|
||||
/**
|
||||
* @brief Determine the SFP connector type.
|
||||
* @param port The SFP Port ID.
|
||||
* @param[out] Receives the connector type.
|
||||
*/
|
||||
int onlp_sfpi_type_get(int port, onlp_sfp_type_t* rtype);
|
||||
|
||||
/**
|
||||
* @brief Determine if an SFP is present.
|
||||
* @param port The port number.
|
||||
* @param port The SFP Port ID.
|
||||
* @returns 1 if present
|
||||
* @returns 0 if absent
|
||||
* @returns An error condition.
|
||||
@@ -54,97 +79,123 @@ int onlp_sfpi_is_present(int port);
|
||||
|
||||
/**
|
||||
* @brief Return the presence bitmap for all SFP ports.
|
||||
* @param dst Receives the presence bitmap.
|
||||
* @param[out] dst Receives the presence bitmap.
|
||||
*/
|
||||
int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst);
|
||||
|
||||
/**
|
||||
* @brief Return the RX_LOS bitmap for all SFP ports.
|
||||
* @param dst Receives the RX_LOS bitmap.
|
||||
* @param[out] dst Receives the RX_LOS bitmap.
|
||||
*/
|
||||
int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst);
|
||||
|
||||
/**
|
||||
* @brief Read the SFP EEPROM.
|
||||
* @param port The port number.
|
||||
* @param data Receives the SFP data.
|
||||
*/
|
||||
int onlp_sfpi_eeprom_read(int port, uint8_t data[256]);
|
||||
|
||||
/**
|
||||
* @brief Read a byte from an address on the given SFP port's bus.
|
||||
* @param port The port number.
|
||||
* @brief Read bytes from the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The address.
|
||||
* @param addr Read offset.
|
||||
* @param[out] dst Receives the data.
|
||||
* @param len Read length.
|
||||
* @returns The number of bytes read or ONLP_STATUS_E_* no error.
|
||||
*/
|
||||
int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr);
|
||||
int onlp_sfpi_dev_read(int port, int devaddr, int addr,
|
||||
uint8_t* dst, int len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write a byte to an address on the given SFP port's bus.
|
||||
*/
|
||||
int onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Read a byte from an address on the given SFP port's bus.
|
||||
* @param port The port number.
|
||||
* @brief Write bytes to the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The address.
|
||||
* @returns The word if successful, error otherwise.
|
||||
* @param src The bytes to write.
|
||||
* @param offset Write offset.
|
||||
* @param len Write length.
|
||||
*/
|
||||
int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr);
|
||||
int onlp_sfpi_dev_write(int port, int devaddr, int addr,
|
||||
uint8_t* src, int len);
|
||||
|
||||
/**
|
||||
* @brief Write a byte to an address on the given SFP port's bus.
|
||||
* @brief Read a byte from the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The read address.
|
||||
* @returns The byte on success or ONLP_STATUS_E* on error.
|
||||
*/
|
||||
int onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value);
|
||||
|
||||
int onlp_sfpi_dev_readb(int port, int devaddr, int addr);
|
||||
|
||||
/**
|
||||
* @brief Read the SFP DOM EEPROM.
|
||||
* @param port The port number.
|
||||
* @param data Receives the SFP data.
|
||||
* @brief Write a byte to the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The write address.
|
||||
* @param value The write value.
|
||||
*/
|
||||
int onlp_sfpi_dom_read(int port, uint8_t data[256]);
|
||||
int onlp_sfpi_dev_writeb(int port, int devaddr, int addr,
|
||||
uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Read a word from the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The read address.
|
||||
* @returns The word if successful, ONLP_STATUS_E* on error.
|
||||
*/
|
||||
int onlp_sfpi_dev_readw(int port, int devaddr, int addr);
|
||||
|
||||
/**
|
||||
* @brief Write a word to the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The write address.
|
||||
* @param value The write value.
|
||||
*/
|
||||
int onlp_sfpi_dev_writew(int port, int devaddr, int addr,
|
||||
uint16_t value);
|
||||
|
||||
/**
|
||||
* @brief Perform any actions required after an SFP is inserted.
|
||||
* @param port The port number.
|
||||
* @param port The SFP Port ID.
|
||||
* @param info The SFF Module information structure.
|
||||
* @notes Optional
|
||||
* @note This function is optional. If your platform must
|
||||
* adjust equalizer or preemphasis settings internally then
|
||||
* this function should be implemented as the trigger.
|
||||
*/
|
||||
int onlp_sfpi_post_insert(int port, sff_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Returns whether or not the given control is suppport on the given port.
|
||||
* @param port The port number.
|
||||
* @brief Returns whether or not the given control is supported on the given port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param control The control.
|
||||
* @param rv [out] Receives 1 if supported, 0 if not supported.
|
||||
* @param[out] rv Receives 1 if supported, 0 if not supported.
|
||||
* @note This provided for convenience and is optional.
|
||||
* If you implement this function your control_set and control_get APIs
|
||||
* will not be called on unsupported ports.
|
||||
*/
|
||||
int onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv);
|
||||
int onlp_sfpi_control_supported(int port,
|
||||
onlp_sfp_control_t control, int* rv);
|
||||
|
||||
/**
|
||||
* @brief Set an SFP control.
|
||||
* @param port The port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param control The control.
|
||||
* @param value The value.
|
||||
*/
|
||||
int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value);
|
||||
int onlp_sfpi_control_set(int port, onlp_sfp_control_t control,
|
||||
int value);
|
||||
|
||||
/**
|
||||
* @brief Get an SFP control.
|
||||
* @param port The port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param control The control
|
||||
* @param [out] value Receives the current value.
|
||||
* @param[out] value Receives the current value.
|
||||
*/
|
||||
int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value);
|
||||
int onlp_sfpi_control_get(int port, onlp_sfp_control_t control,
|
||||
int* value);
|
||||
|
||||
/**
|
||||
* @brief Remap SFP user SFP port numbers before calling the SFPI interface.
|
||||
* @param port The user SFP port number.
|
||||
* @param [out] rport Receives the new port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param[out] rport Receives the new port.
|
||||
* @note This function will be called to remap the user SFP port number
|
||||
* to the number returned in rport before the SFPI functions are called.
|
||||
* This is an optional convenience for platforms with dynamic or
|
||||
@@ -152,39 +203,23 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value);
|
||||
*/
|
||||
int onlp_sfpi_port_map(int port, int* rport);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the SFP driver.
|
||||
*/
|
||||
int onlp_sfpi_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Generic debug status information.
|
||||
* @param port The port number.
|
||||
* @param pvs The output pvs.
|
||||
* @notes The purpose of this vector is to allow reporting of internal debug
|
||||
* status and information from the platform driver that might be used to debug
|
||||
* SFP runtime issues.
|
||||
* For example, internal equalizer settings, tuning status information, status
|
||||
* of additional signals useful for system debug but not exposed in this interface.
|
||||
*
|
||||
* @notes This is function is optional.
|
||||
* @brief Get the SFP's OID header.
|
||||
* @param oid The SFP oid.
|
||||
* @param hdr Receives the header.
|
||||
*/
|
||||
void onlp_sfpi_debug(int port, aim_pvs_t* pvs);
|
||||
int onlp_sfpi_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* rhdr);
|
||||
|
||||
/**
|
||||
* @brief Generic ioctl
|
||||
* @param port The port number
|
||||
* @param The variable argument list of parameters.
|
||||
*
|
||||
* @notes This generic ioctl interface can be used
|
||||
* for platform-specific or driver specific features
|
||||
* that cannot or have not yet been defined in this
|
||||
* interface. It is intended as a future feature expansion
|
||||
* support mechanism.
|
||||
*
|
||||
* @notes Optional
|
||||
* @brief GEt the SFP's info structure.
|
||||
* @param oid The SFP oid.
|
||||
* @param info Receives the SFP information.
|
||||
* @note It is not normally necessary to implement this function.
|
||||
* The upper layer implements this on behalf of the platform
|
||||
* using the existing SFP primitives.
|
||||
*/
|
||||
int onlp_sfpi_ioctl(int port, va_list vargs);
|
||||
|
||||
int onlp_sfpi_info_get(onlp_oid_t oid, onlp_sfp_info_t* info);
|
||||
|
||||
#endif /* __ONLP_SFPI_H__ */
|
||||
/* @} */
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* ONLP System Platform Interface.
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_SYSI_H__
|
||||
#define __ONLP_SYSI_H__
|
||||
|
||||
#include <onlp/sys.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the name of the the platform implementation.
|
||||
* @notes This will be called PRIOR to any other calls into the
|
||||
* platform driver, including the sysi_init() function below.
|
||||
*
|
||||
* The platform implementation name should match the current
|
||||
* ONLP platform name.
|
||||
*
|
||||
* IF the platform implementation name equals the current platform name,
|
||||
* initialization will continue.
|
||||
*
|
||||
* If the platform implementation name does not match, the following will be
|
||||
* attempted:
|
||||
*
|
||||
* onlp_sysi_platform_set(current_platform_name);
|
||||
* If this call is successful, initialization will continue.
|
||||
* If this call fails, platform initialization will abort().
|
||||
*
|
||||
* The onlp_sysi_platform_set() function is optional.
|
||||
* The onlp_sysi_platform_get() is not optional.
|
||||
*/
|
||||
const char* onlp_sysi_platform_get(void);
|
||||
|
||||
/**
|
||||
* @brief Attempt to set the platform personality
|
||||
* in the event that the current platform does not match the
|
||||
* reported platform.
|
||||
* @note Optional
|
||||
*/
|
||||
int onlp_sysi_platform_set(const char* platform);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the system platform subsystem.
|
||||
*/
|
||||
int onlp_sysi_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Provide the physical base address for the ONIE eeprom.
|
||||
* @param param [out] physaddr Receives the physical address.
|
||||
* @notes If your platform provides a memory-mappable base
|
||||
* address for the ONIE eeprom data you can return it here.
|
||||
* The ONLP common code will then use this address and decode
|
||||
* the ONIE TLV specification data. If you cannot return a mappable
|
||||
* address due to the platform organization see onlp_sysi_onie_data_get()
|
||||
* instead.
|
||||
*/
|
||||
int onlp_sysi_onie_data_phys_addr_get(void** physaddr);
|
||||
|
||||
/**
|
||||
* @brief Return the raw contents of the ONIE system eeprom.
|
||||
* @param data [out] Receives the data pointer to the ONIE data.
|
||||
* @param size [out] Receives the size of the data (if available).
|
||||
* @notes This function is only necessary if you cannot provide
|
||||
* the physical base address as per onlp_sysi_onie_data_phys_addr_get().
|
||||
*/
|
||||
int onlp_sysi_onie_data_get(uint8_t** data, int* size);
|
||||
|
||||
/**
|
||||
* @brief Free the data returned by onlp_sys_onie_data_get()
|
||||
* @param data The data pointer.
|
||||
* @notes If onlp_sysi_onie_data_get() is called to retreive the
|
||||
* contents of the ONIE system eeprom then this function
|
||||
* will be called to perform any cleanup that may be necessary
|
||||
* after the data has been used.
|
||||
*/
|
||||
void onlp_sysi_onie_data_free(uint8_t* data);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the ONIE system information for this platform.
|
||||
* @param onie The onie information structure.
|
||||
* @notes If all previous attempts to get the eeprom data fail
|
||||
* then this routine will be called. Used as a translation option
|
||||
* for platforms without access to an ONIE-formatted eeprom.
|
||||
*/
|
||||
int onlp_sysi_onie_info_get(onlp_onie_info_t* onie);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function returns the root oid list for the platform.
|
||||
* @param table [out] Receives the table.
|
||||
* @param max The maximum number of entries you can fill.
|
||||
*/
|
||||
int onlp_sysi_oids_get(onlp_oid_t* table, int max);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function provides a generic ioctl interface.
|
||||
* @param code context dependent.
|
||||
* @param vargs The variable argument list for the ioctl call.
|
||||
* @notes This is provided as a generic expansion and
|
||||
* and custom programming mechanism for future and non-standard
|
||||
* functionality.
|
||||
* @notes Optional
|
||||
*/
|
||||
int onlp_sysi_ioctl(int code, va_list vargs);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Platform management initialization.
|
||||
*/
|
||||
int onlp_sysi_platform_manage_init(void);
|
||||
|
||||
/**
|
||||
* @brief Perform necessary platform fan management.
|
||||
* @note This function should automatically adjust the FAN speeds
|
||||
* according to the platform conditions.
|
||||
*/
|
||||
int onlp_sysi_platform_manage_fans(void);
|
||||
|
||||
/**
|
||||
* @brief Perform necessary platform LED management.
|
||||
* @note This function should automatically adjust the LED indicators
|
||||
* according to the platform conditions.
|
||||
*/
|
||||
int onlp_sysi_platform_manage_leds(void);
|
||||
|
||||
/**
|
||||
* @brief Return custom platform information.
|
||||
*/
|
||||
int onlp_sysi_platform_info_get(onlp_platform_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Friee a custom platform information structure.
|
||||
*/
|
||||
void onlp_sysi_platform_info_free(onlp_platform_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Builtin platform debug tool.
|
||||
*/
|
||||
int onlp_sysi_debug(aim_pvs_t* pvs, int argc, char** argv);
|
||||
|
||||
#endif /* __ONLP_SYSI_H__ */
|
||||
@@ -1,25 +1,28 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Thermal Sensor Platform Implementation.
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Thermal Sensor Platform Implementation.
|
||||
* @addtogroup thermali
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_THERMALI_H__
|
||||
@@ -28,35 +31,37 @@
|
||||
#include <onlp/thermal.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the thermal subsystem.
|
||||
* @brief Software initialization of the Thermal module.
|
||||
*/
|
||||
int onlp_thermali_init(void);
|
||||
|
||||
int onlp_thermali_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get the information for the given thermal OID.
|
||||
* @param id The Thermal OID
|
||||
* @param rv [out] Receives the thermal information.
|
||||
* @brief Hardware initialization of the Thermal module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* rv);
|
||||
int onlp_thermali_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the thermal's operational status.
|
||||
* @param id The thermal oid.
|
||||
* @param rv [out] Receives the operational status.
|
||||
* @brief Deinitialize the thermal software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_thermali_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_thermali_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the thermal's oid header.
|
||||
* @param id The thermal oid.
|
||||
* @param rv [out] Receives the header.
|
||||
* @param[out] rv Receives the header.
|
||||
*/
|
||||
int onlp_thermali_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Generic ioctl.
|
||||
* @brief Get the information for the given thermal OID.
|
||||
* @param id The Thermal OID
|
||||
* @param[out] rv Receives the thermal information.
|
||||
*/
|
||||
int onlp_thermali_ioctl(int id, va_list vargs);
|
||||
int onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* rv);
|
||||
|
||||
#endif /* __ONLP_THERMALI_H__ */
|
||||
/* @} */
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Power Supply Management.
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Power Supply Management.
|
||||
* @addtogroup oid-psu
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_PSU_H__
|
||||
@@ -31,23 +34,24 @@
|
||||
/* <auto.start.enum(tag:psu).define> */
|
||||
/** onlp_psu_caps */
|
||||
typedef enum onlp_psu_caps_e {
|
||||
ONLP_PSU_CAPS_AC = (1 << 0),
|
||||
ONLP_PSU_CAPS_DC12 = (1 << 1),
|
||||
ONLP_PSU_CAPS_DC48 = (1 << 2),
|
||||
ONLP_PSU_CAPS_VIN = (1 << 3),
|
||||
ONLP_PSU_CAPS_VOUT = (1 << 4),
|
||||
ONLP_PSU_CAPS_IIN = (1 << 5),
|
||||
ONLP_PSU_CAPS_IOUT = (1 << 6),
|
||||
ONLP_PSU_CAPS_PIN = (1 << 7),
|
||||
ONLP_PSU_CAPS_POUT = (1 << 8),
|
||||
ONLP_PSU_CAPS_GET_TYPE = (1 << 0),
|
||||
ONLP_PSU_CAPS_GET_VIN = (1 << 1),
|
||||
ONLP_PSU_CAPS_GET_VOUT = (1 << 2),
|
||||
ONLP_PSU_CAPS_GET_IIN = (1 << 3),
|
||||
ONLP_PSU_CAPS_GET_IOUT = (1 << 4),
|
||||
ONLP_PSU_CAPS_GET_PIN = (1 << 5),
|
||||
ONLP_PSU_CAPS_GET_POUT = (1 << 6),
|
||||
} onlp_psu_caps_t;
|
||||
|
||||
/** onlp_psu_status */
|
||||
typedef enum onlp_psu_status_e {
|
||||
ONLP_PSU_STATUS_PRESENT = (1 << 0),
|
||||
ONLP_PSU_STATUS_FAILED = (1 << 1),
|
||||
ONLP_PSU_STATUS_UNPLUGGED = (1 << 2),
|
||||
} onlp_psu_status_t;
|
||||
/** onlp_psu_type */
|
||||
typedef enum onlp_psu_type_e {
|
||||
ONLP_PSU_TYPE_AC,
|
||||
ONLP_PSU_TYPE_DC12,
|
||||
ONLP_PSU_TYPE_DC48,
|
||||
ONLP_PSU_TYPE_LAST = ONLP_PSU_TYPE_DC48,
|
||||
ONLP_PSU_TYPE_COUNT,
|
||||
ONLP_PSU_TYPE_INVALID = -1,
|
||||
} onlp_psu_type_t;
|
||||
/* <auto.end.enum(tag:psu).define> */
|
||||
|
||||
|
||||
@@ -58,94 +62,109 @@ typedef struct onlp_psu_info_t {
|
||||
/** OID Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/* Model */
|
||||
/** Model */
|
||||
char model[ONLP_CONFIG_INFO_STR_MAX];
|
||||
|
||||
/* Serial Number */
|
||||
/** Serial Number */
|
||||
char serial[ONLP_CONFIG_INFO_STR_MAX];
|
||||
|
||||
/* Status */
|
||||
uint32_t status;
|
||||
|
||||
/* Capabilities */
|
||||
/** Capabilities */
|
||||
uint32_t caps;
|
||||
|
||||
/* millivolts */
|
||||
/** Type */
|
||||
onlp_psu_type_t type;
|
||||
|
||||
/** millivolts in */
|
||||
int mvin;
|
||||
|
||||
/** millivolts out */
|
||||
int mvout;
|
||||
|
||||
/* milliamps */
|
||||
/** milliamps in */
|
||||
int miin;
|
||||
|
||||
/** milliamps out */
|
||||
int miout;
|
||||
|
||||
/* milliwatts */
|
||||
/** milliwatts in */
|
||||
int mpin;
|
||||
|
||||
/** milliwatts out */
|
||||
int mpout;
|
||||
|
||||
} onlp_psu_info_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the PSU subsystem.
|
||||
*/
|
||||
int onlp_psu_init(void);
|
||||
|
||||
#define ONLP_PSU_INFO_CAP_IS_SET(_pinfo, _name) \
|
||||
((_pinfo)->caps & ONLP_PSU_CAPS_##_name)
|
||||
|
||||
/**
|
||||
* @brief Get the PSU information.
|
||||
* @param id The PSU OID.
|
||||
* @param rv [out] Receives the information structure.
|
||||
* @brief Software initialization of the PSU module.
|
||||
*/
|
||||
int onlp_psu_info_get(onlp_oid_t id, onlp_psu_info_t* rv);
|
||||
int onlp_psu_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get the PSU's operational status.
|
||||
* @param id The PSU OID.
|
||||
* @param rv [out] Receives the operational status.
|
||||
* @brief Hardware initialization of the PSU module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_psu_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_psu_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the psu software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_psu_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the PSU's oid header.
|
||||
* @param id The PSU OID.
|
||||
* @param rv [out] Receives the header.
|
||||
* @param[out] rv Receives the header.
|
||||
*/
|
||||
int onlp_psu_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Issue a PSU ioctl.
|
||||
* @param id The PSU OID
|
||||
* @param ... Ioctl arguments.
|
||||
* @brief Get the PSU information.
|
||||
* @param id The PSU OID.
|
||||
* @param[out] rv Receives the information structure.
|
||||
*/
|
||||
int onlp_psu_ioctl(onlp_oid_t id, ...);
|
||||
int onlp_psu_info_get(onlp_oid_t id, onlp_psu_info_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Issue a PSU ioctl.
|
||||
* @param id The PSU OID
|
||||
* @param vargs Ioctl arguments.
|
||||
*/
|
||||
int onlp_psu_vioctl(onlp_oid_t id, va_list vargs);
|
||||
|
||||
/**
|
||||
* @brief PSU OID debug dump
|
||||
* @brief Format the given PSU OID.
|
||||
* @param id The PSU OID
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs
|
||||
* @param flags The output flags
|
||||
*/
|
||||
void onlp_psu_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_psu_format(onlp_oid_t id, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Show the given PSU OID.
|
||||
* @param id The PSU OID
|
||||
* @param pvs The output pvs
|
||||
* @param flags The output flags
|
||||
* @brief Format the given PSU information structure.
|
||||
* @param info The information structure.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The output flags.
|
||||
*/
|
||||
void onlp_psu_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags);
|
||||
int onlp_psu_info_format(onlp_psu_info_t* info,
|
||||
onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Convenience macros for processing PSU status.
|
||||
*/
|
||||
|
||||
int onlp_psu_info_to_user_json(onlp_psu_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_psu_info_to_json(onlp_psu_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_psu_info_from_json(cJSON* cj, onlp_psu_info_t* info);
|
||||
|
||||
|
||||
/** PSU is present. */
|
||||
#define ONLP_PSU_STATUS_PRESENT(_pi) ( (_pi).status & ONLP_PSU_STATUS_PRESENT )
|
||||
|
||||
/** PSU is missing. */
|
||||
#define ONLP_PSU_STATUS_MISSING(_pi) (!ONLP_PSU_STATUS_PRESENT(_pi))
|
||||
|
||||
/** PSU has failed. */
|
||||
#define ONLP_PSU_STATUS_FAILED(_pi) ( (_pi).status & ONLP_PSU_STATUS_FAILED)
|
||||
|
||||
|
||||
@@ -179,26 +198,31 @@ extern aim_map_si_t onlp_psu_caps_map[];
|
||||
/** onlp_psu_caps_desc_map table. */
|
||||
extern aim_map_si_t onlp_psu_caps_desc_map[];
|
||||
|
||||
/** Strings macro. */
|
||||
#define ONLP_PSU_TYPE_STRINGS \
|
||||
{\
|
||||
"AC", \
|
||||
"DC12", \
|
||||
"DC48", \
|
||||
}
|
||||
/** Enum names. */
|
||||
const char* onlp_psu_status_name(onlp_psu_status_t e);
|
||||
const char* onlp_psu_type_name(onlp_psu_type_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_psu_status_value(const char* str, onlp_psu_status_t* e, int substr);
|
||||
int onlp_psu_type_value(const char* str, onlp_psu_type_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_psu_status_desc(onlp_psu_status_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_psu_status_valid(onlp_psu_status_t e);
|
||||
const char* onlp_psu_type_desc(onlp_psu_type_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_PSU_STATUS_VALID(_e) \
|
||||
(onlp_psu_status_valid((_e)))
|
||||
#define ONLP_PSU_TYPE_VALID(_e) \
|
||||
( (0 <= (_e)) && ((_e) <= ONLP_PSU_TYPE_DC48))
|
||||
|
||||
/** onlp_psu_status_map table. */
|
||||
extern aim_map_si_t onlp_psu_status_map[];
|
||||
/** onlp_psu_status_desc_map table. */
|
||||
extern aim_map_si_t onlp_psu_status_desc_map[];
|
||||
/** onlp_psu_type_map table. */
|
||||
extern aim_map_si_t onlp_psu_type_map[];
|
||||
/** onlp_psu_type_desc_map table. */
|
||||
extern aim_map_si_t onlp_psu_type_desc_map[];
|
||||
/* <auto.end.enum(tag:psu).supportheader> */
|
||||
|
||||
#endif /* __ONLP_PSU_H__ */
|
||||
/* @} */
|
||||
|
||||
@@ -17,9 +17,12 @@
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
*************************************************************
|
||||
*********************************************************//**
|
||||
*
|
||||
* SFP Management Interface.
|
||||
* @file
|
||||
* @brief SFP Management Interface.
|
||||
* @addtogroup oid-sfp
|
||||
* @{
|
||||
*
|
||||
************************************************************/
|
||||
#ifndef __ONLP_SFP_H__
|
||||
@@ -27,9 +30,11 @@
|
||||
|
||||
#include <onlp/onlp_config.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlp/oids.h>
|
||||
#include <AIM/aim_bitmap.h>
|
||||
#include <AIM/aim_pvs.h>
|
||||
#include <sff/sff.h>
|
||||
#include <sff/dom.h>
|
||||
|
||||
/* <auto.start.enum(tag:sfp1).define> */
|
||||
/** onlp_sfp_control */
|
||||
@@ -60,18 +65,98 @@ typedef enum onlp_sfp_control_flag_e {
|
||||
ONLP_SFP_CONTROL_FLAG_LP_MODE = (1 << 6),
|
||||
ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE = (1 << 7),
|
||||
} onlp_sfp_control_flag_t;
|
||||
|
||||
/** onlp_sfp_type */
|
||||
typedef enum onlp_sfp_type_e {
|
||||
ONLP_SFP_TYPE_SFP,
|
||||
ONLP_SFP_TYPE_QSFP,
|
||||
ONLP_SFP_TYPE_SFP28,
|
||||
ONLP_SFP_TYPE_QSFP28,
|
||||
ONLP_SFP_TYPE_LAST = ONLP_SFP_TYPE_QSFP28,
|
||||
ONLP_SFP_TYPE_COUNT,
|
||||
ONLP_SFP_TYPE_INVALID = -1,
|
||||
} onlp_sfp_type_t;
|
||||
/* <auto.end.enum(tag:sfp2).define> */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the SFP subsystem.
|
||||
* SFP Block Data Size
|
||||
*/
|
||||
int onlp_sfp_init(void);
|
||||
#define ONLP_SFP_BLOCK_DATA_SIZE 256
|
||||
|
||||
|
||||
/**
|
||||
* SFP Information Structure.
|
||||
*/
|
||||
typedef struct onlp_sfp_info_t {
|
||||
/** OID Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/** SFP Connector Type */
|
||||
onlp_sfp_type_t type;
|
||||
|
||||
/** The SFP Control Status */
|
||||
uint32_t controls;
|
||||
|
||||
|
||||
/*
|
||||
* The following fields are only relevant
|
||||
* if the SFP is present.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The SFF Parse of the idprom.
|
||||
* The parse is valid if sff.sfp_type != INVALID.
|
||||
*
|
||||
* Note that the vendor, model, and serial will likely
|
||||
* be populated correctly event if the rest of the
|
||||
* data could not be parsed correctly.
|
||||
*/
|
||||
sff_info_t sff;
|
||||
|
||||
/**
|
||||
* The SFF Diagnostics information.
|
||||
*/
|
||||
sff_dom_info_t dom;
|
||||
|
||||
/** The raw data upon which the meta info is based. */
|
||||
struct {
|
||||
/** The last A0 data */
|
||||
uint8_t a0[ONLP_SFP_BLOCK_DATA_SIZE];
|
||||
|
||||
/** The last A2 data (for SFP+ only) */
|
||||
uint8_t a2[ONLP_SFP_BLOCK_DATA_SIZE];
|
||||
} bytes;
|
||||
|
||||
} onlp_sfp_info_t;
|
||||
|
||||
/**
|
||||
* Valid SFP Port bitmaps are communicated using this type.
|
||||
*/
|
||||
typedef aim_bitmap256_t onlp_sfp_bitmap_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Software initialization of the SFP module.
|
||||
*/
|
||||
int onlp_sfp_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Hardware initialization of the SFP module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_sfp_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the sfp software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_sfp_sw_denit(void);
|
||||
|
||||
/**
|
||||
* Convenience function for initializing SFP bitmaps.
|
||||
* @param bmap The address of the bitmap to initialize.
|
||||
@@ -79,16 +164,44 @@ typedef aim_bitmap256_t onlp_sfp_bitmap_t;
|
||||
void onlp_sfp_bitmap_t_init(onlp_sfp_bitmap_t* bmap);
|
||||
|
||||
/**
|
||||
* @brief Get the set of valid {Q}SFP ports.
|
||||
* @brief Get the set of valid SFP ports.
|
||||
* @param bmap Returns the valid set of SFP-capable port numbers.
|
||||
*/
|
||||
int onlp_sfp_bitmap_get(onlp_sfp_bitmap_t* bmap);
|
||||
|
||||
/**
|
||||
* @brief Get the SFP information structure.
|
||||
* @param port The SFP OID or Port ID.
|
||||
* @param[out] info Receives the information structure.
|
||||
*/
|
||||
int onlp_sfp_info_get(onlp_oid_t port, onlp_sfp_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Get the SFP information structure (including DOM)
|
||||
* @param port The SFP OID or Port ID.
|
||||
* @param[out] info Receives the information structure.
|
||||
*/
|
||||
int onlp_sfp_info_dom_get(onlp_oid_t port, onlp_sfp_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Get the SFP's oid header.
|
||||
* @param port The SFP OID.
|
||||
* @param[out] rv Receives the header.
|
||||
*/
|
||||
int onlp_sfp_hdr_get(onlp_oid_t port, onlp_oid_hdr_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Determine if a given port number is a valid SFP port.
|
||||
* @param port The port number.
|
||||
*/
|
||||
int onlp_sfp_port_valid(int port);
|
||||
int onlp_sfp_port_valid(onlp_oid_t port);
|
||||
|
||||
/**
|
||||
* @brief Determine the SFP Connector type.
|
||||
* @param port The port number.
|
||||
* @param[out] rtype Receives the type.
|
||||
*/
|
||||
int onlp_sfp_type_get(onlp_oid_t port, onlp_sfp_type_t* rtype);
|
||||
|
||||
/**
|
||||
* @brief Determine if an SFP is currently plugged in.
|
||||
@@ -97,7 +210,7 @@ int onlp_sfp_port_valid(int port);
|
||||
* @returns 0 if an SFP is not present.
|
||||
* @returns <0 on error.
|
||||
*/
|
||||
int onlp_sfp_is_present(int port);
|
||||
int onlp_sfp_is_present(onlp_oid_t port);
|
||||
|
||||
/**
|
||||
* @brief Return the presence bitmap for all ports.
|
||||
@@ -108,33 +221,6 @@ int onlp_sfp_is_present(int port);
|
||||
*/
|
||||
int onlp_sfp_presence_bitmap_get(onlp_sfp_bitmap_t* dst);
|
||||
|
||||
/**
|
||||
* @brief Read IEEE standard EEPROM data from the given port.
|
||||
* @param port The SFP Port
|
||||
* @param rv Receives a buffer containing the EEPROM data.
|
||||
* @notes The buffer must be freed after use.
|
||||
* @returns The size of the eeprom data, if successful
|
||||
* @returns -1 on error.
|
||||
*/
|
||||
int onlp_sfp_eeprom_read(int port, uint8_t** rv);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read the DOM data from the given port.
|
||||
* @param port The SFP Port
|
||||
* @param rv Receives a buffer containing the DOM data.
|
||||
* @notes The buffer must be freed after use.
|
||||
* @returns The size of the eeprom data, if successful
|
||||
* @returns -1 on error.
|
||||
* @note This should only be called if the SFP
|
||||
* has advertised DOM support.
|
||||
*/
|
||||
int onlp_sfp_dom_read(int port, uint8_t** rv);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the SFP subsystem.
|
||||
*/
|
||||
int onlp_sfp_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Get the RX_LOS bitmap for all ports.
|
||||
@@ -145,84 +231,130 @@ int onlp_sfp_denit(void);
|
||||
*/
|
||||
int onlp_sfp_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read a byte from an address on the given SFP port's bus.
|
||||
* @param port The port number.
|
||||
* @brief Read bytes from the target device on the given SFP port.
|
||||
* @param port The SFP OID or Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The address.
|
||||
* @param addr The address to read.
|
||||
* @param dst Receives the data.
|
||||
* @param count The read length.
|
||||
* @returns The number of bytes read or ONLP_STATUS_E_* no error.
|
||||
*/
|
||||
int onlp_sfp_dev_readb(int port, uint8_t devaddr, uint8_t addr);
|
||||
int onlp_sfp_dev_read(onlp_oid_t port, int devaddr, int addr,
|
||||
uint8_t* dst, int count);
|
||||
|
||||
/**
|
||||
* @brief Write a byte to an address on the given SFP port's bus.
|
||||
*/
|
||||
int onlp_sfp_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Read a byte from an address on the given SFP port's bus.
|
||||
* @param port The port number.
|
||||
* @brief Write bytes to the target device on the given SFP port.
|
||||
* @param port The SFP OID or Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The address.
|
||||
* @param addr The address to write.
|
||||
* @param src The source data.
|
||||
* @param count The write length.
|
||||
*/
|
||||
int onlp_sfp_dev_readw(int port, uint8_t devaddr, uint8_t addr);
|
||||
int onlp_sfp_dev_write(onlp_oid_t port, int devaddr, int addr,
|
||||
uint8_t* src, int count);
|
||||
|
||||
/**
|
||||
* @brief Write a byte to an address on the given SFP port's bus.
|
||||
* @brief Read a byte from the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The read address.
|
||||
* @returns The byte on success or ONLP_STATUS_E* on error.
|
||||
*/
|
||||
int onlp_sfp_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value);
|
||||
int onlp_sfp_dev_readb(onlp_oid_t port, int devaddr, int addr);
|
||||
|
||||
/**
|
||||
* @brief Write a byte to the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The write address.
|
||||
* @param value The write value.
|
||||
*/
|
||||
int onlp_sfp_dev_writeb(onlp_oid_t port, int devaddr, int addr,
|
||||
uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Read a word from the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The read address.
|
||||
* @returns The word if successful, ONLP_STATUS_E* on error.
|
||||
*/
|
||||
int onlp_sfp_dev_readw(onlp_oid_t port, int devaddr, int addr);
|
||||
|
||||
/**
|
||||
* @brief Write a word to the target device on the given SFP port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param devaddr The device address.
|
||||
* @param addr The write address.
|
||||
* @param value The write value.
|
||||
*/
|
||||
int onlp_sfp_dev_writew(onlp_oid_t port, int devaddr, int addr,
|
||||
uint16_t value);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Dump the status of all SFPs
|
||||
* @param pvs The output pvs.
|
||||
* @brief Perform any actions required after an SFP is inserted.
|
||||
* @param port The SFP Port ID.
|
||||
* @param info The SFF Module information structure.
|
||||
* @note This function is optional. If your platform must
|
||||
* adjust equalizer or preemphasis settings internally then
|
||||
* this function should be implemented as the trigger.
|
||||
*/
|
||||
void onlp_sfp_dump(aim_pvs_t* pvs);
|
||||
|
||||
/**
|
||||
* @brief Issue an ioctl to the SFP interface.
|
||||
* @param port The port.
|
||||
* @param ... Ioctl arguments.
|
||||
*/
|
||||
int onlp_sfp_ioctl(int port, ...);
|
||||
|
||||
/**
|
||||
* @brief Issue an ioctl to the SFP interface.
|
||||
* @param port The port.
|
||||
* @param vargs Ioctl arguments.
|
||||
*/
|
||||
int onlp_sfp_vioctl(int port, va_list vargs);
|
||||
|
||||
/**
|
||||
* @brief Call the SFP post-insertion handler.
|
||||
*
|
||||
*/
|
||||
int onlp_sfp_post_insert(int port, sff_info_t* info);
|
||||
int onlp_sfp_post_insert(onlp_oid_t port, sff_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Set an SFP control.
|
||||
* @param port The port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param control The control.
|
||||
* @param value The value.
|
||||
*/
|
||||
int onlp_sfp_control_set(int port, onlp_sfp_control_t control, int value);
|
||||
int onlp_sfp_control_set(onlp_oid_t port, onlp_sfp_control_t control, int value);
|
||||
|
||||
/**
|
||||
* @brief Get an SFP control.
|
||||
* @param port The port.
|
||||
* @param port The SFP Port ID.
|
||||
* @param control The control
|
||||
* @param [out] value Receives the current value.
|
||||
* @param[out] value Receives the current value.
|
||||
*/
|
||||
int onlp_sfp_control_get(int port, onlp_sfp_control_t control, int* value);
|
||||
int onlp_sfp_control_get(onlp_oid_t port, onlp_sfp_control_t control,
|
||||
int* value);
|
||||
|
||||
/**
|
||||
* @brief Get the value of all SFP controls.
|
||||
* @param port The port.
|
||||
* @param flags Receives the control flag values. See onlp_sfp_control_flags_t
|
||||
*/
|
||||
int onlp_sfp_control_flags_get(int port, uint32_t* flags);
|
||||
int onlp_sfp_control_flags_get(onlp_oid_t port, uint32_t* flags);
|
||||
|
||||
|
||||
int onlp_sfp_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_sfp_info_format(onlp_sfp_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_sfp_info_to_user_json(onlp_sfp_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_sfp_info_to_json(onlp_sfp_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_sfp_info_from_json(cJSON* cj, onlp_sfp_info_t* info);
|
||||
|
||||
/**
|
||||
* @brief Software deinitialize the SFP subsystem.
|
||||
*/
|
||||
int onlp_sfp_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Hardware deinitialize the SFP subsystem.
|
||||
*/
|
||||
int onlp_sfp_hw_denit(void);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Show the current SFP inventory.
|
||||
*/
|
||||
int onlp_sfp_inventory_show(aim_pvs_t* pvs);
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
@@ -284,6 +416,33 @@ int onlp_sfp_control_flag_valid(onlp_sfp_control_flag_t e);
|
||||
extern aim_map_si_t onlp_sfp_control_flag_map[];
|
||||
/** onlp_sfp_control_flag_desc_map table. */
|
||||
extern aim_map_si_t onlp_sfp_control_flag_desc_map[];
|
||||
|
||||
/** Strings macro. */
|
||||
#define ONLP_SFP_TYPE_STRINGS \
|
||||
{\
|
||||
"SFP", \
|
||||
"QSFP", \
|
||||
"SFP28", \
|
||||
"QSFP28", \
|
||||
}
|
||||
/** Enum names. */
|
||||
const char* onlp_sfp_type_name(onlp_sfp_type_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_sfp_type_value(const char* str, onlp_sfp_type_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_sfp_type_desc(onlp_sfp_type_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_SFP_TYPE_VALID(_e) \
|
||||
( (0 <= (_e)) && ((_e) <= ONLP_SFP_TYPE_QSFP28))
|
||||
|
||||
/** onlp_sfp_type_map table. */
|
||||
extern aim_map_si_t onlp_sfp_type_map[];
|
||||
/** onlp_sfp_type_desc_map table. */
|
||||
extern aim_map_si_t onlp_sfp_type_desc_map[];
|
||||
/* <auto.end.enum(tag:sfp2).supportheader> */
|
||||
|
||||
#endif /* __ONLP_SFP_H__ */
|
||||
/* @} */
|
||||
|
||||
119
packages/base/any/onlp/src/onlp/module/inc/onlp/stdattrs.h
Normal file
119
packages/base/any/onlp/src/onlp/module/inc/onlp/stdattrs.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2017 v=onl>
|
||||
*
|
||||
* Copyright 2017 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
********************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief Standard OID Attributes
|
||||
* @addtogroup stdattrs
|
||||
* @{
|
||||
*
|
||||
***********************************************************/
|
||||
#ifndef __ONLP_STDATTRS_H__
|
||||
#define __ONLP_STDATTRS_H__
|
||||
|
||||
#include <onlp/oids.h>
|
||||
#include <onlplib/onie.h>
|
||||
|
||||
#include <AIM/aim_pvs.h>
|
||||
|
||||
/**
|
||||
* @brief This structure describes general asset information
|
||||
* that may be associated with a particular OID.
|
||||
*/
|
||||
typedef struct onlp_asset_info_s {
|
||||
/** The OID to which this asset info belongs */
|
||||
onlp_oid_t oid;
|
||||
|
||||
/** Manufacturer */
|
||||
char* manufacturer;
|
||||
|
||||
/** Date */
|
||||
char* date;
|
||||
|
||||
/** Part Number */
|
||||
char* part_number;
|
||||
|
||||
/** Serial Number */
|
||||
char* serial_number;
|
||||
|
||||
/** Hardware Revision */
|
||||
char* hardware_revision;
|
||||
|
||||
/** Firmware Revision */
|
||||
char* firmware_revision;
|
||||
|
||||
/** CPLD Revision */
|
||||
char* cpld_revision;
|
||||
|
||||
/** Manufacture Date */
|
||||
char* manufacture_date;
|
||||
|
||||
/** Description */
|
||||
char* description;
|
||||
|
||||
/** Additional Information */
|
||||
char* additional;
|
||||
|
||||
} onlp_asset_info_t;
|
||||
|
||||
/**
|
||||
* @brief This is the attribute used when referring to the
|
||||
* standard asset information structure.
|
||||
*/
|
||||
|
||||
#define ONLP_ATTRIBUTE_ASSET_INFO "onlp.asset_info"
|
||||
|
||||
/**
|
||||
* @brief Show an asset structure.
|
||||
*/
|
||||
int onlp_asset_info_show(onlp_asset_info_t* aip, aim_pvs_t* pvs);
|
||||
|
||||
/**
|
||||
* @brief Free an asset structure.
|
||||
*/
|
||||
int onlp_asset_info_free(onlp_asset_info_t* aip);
|
||||
|
||||
/**
|
||||
* @brief Asset info to JSON.
|
||||
*/
|
||||
int onlp_asset_info_to_json(onlp_asset_info_t* aip, cJSON** rv);
|
||||
|
||||
/**
|
||||
* You can also request the JSON version representation.
|
||||
*/
|
||||
#define ONLP_ATTRIBUTE_ASSET_INFO_JSON "onlp.asset_info_json"
|
||||
|
||||
|
||||
/**
|
||||
* @brief The ONIE Information Structure can be queried
|
||||
* using this attribute.
|
||||
*
|
||||
* This attribute returns an onlp_onie_info_t structure.
|
||||
* See onlplib/onie.h
|
||||
*/
|
||||
#define ONLP_ATTRIBUTE_ONIE_INFO "onlp.attr.onie_info"
|
||||
|
||||
/**
|
||||
* You can also request the JSON representation.
|
||||
*/
|
||||
#define ONLP_ATTRIBUTE_ONIE_INFO_JSON "onlp.attr.onie_info_json"
|
||||
|
||||
#endif /* __ONLP_STDATTRS_H__ */
|
||||
/* @} */
|
||||
@@ -17,9 +17,12 @@
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
********************************************************//**
|
||||
*
|
||||
* Thermal Sensor Management.
|
||||
* @file
|
||||
* @brief Thermal Sensor Management.
|
||||
* @addtogroup oid-thermal
|
||||
* @{
|
||||
*
|
||||
************************************************************/
|
||||
#ifndef __ONLP_THERMAL_H__
|
||||
@@ -38,12 +41,6 @@ typedef enum onlp_thermal_caps_e {
|
||||
ONLP_THERMAL_CAPS_GET_SHUTDOWN_THRESHOLD = (1 << 3),
|
||||
} onlp_thermal_caps_t;
|
||||
|
||||
/** onlp_thermal_status */
|
||||
typedef enum onlp_thermal_status_e {
|
||||
ONLP_THERMAL_STATUS_PRESENT = (1 << 0),
|
||||
ONLP_THERMAL_STATUS_FAILED = (1 << 1),
|
||||
} onlp_thermal_status_t;
|
||||
|
||||
/** onlp_thermal_threshold */
|
||||
typedef enum onlp_thermal_threshold_e {
|
||||
ONLP_THERMAL_THRESHOLD_WARNING_DEFAULT = 45000,
|
||||
@@ -81,86 +78,87 @@ typedef struct onlp_thermal_info_s {
|
||||
/** OID Header */
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
/** Status */
|
||||
uint32_t status;
|
||||
|
||||
/** Capabilities */
|
||||
uint32_t caps;
|
||||
|
||||
/* Current temperature in milli-celsius */
|
||||
/** Current temperature in milli-celsius */
|
||||
int mcelsius;
|
||||
|
||||
/** Thermal Thresholds */
|
||||
struct {
|
||||
/* Warning temperature threshold in milli-celsius */
|
||||
/** Warning temperature threshold in milli-celsius */
|
||||
int warning;
|
||||
|
||||
/* Error temperature threshold in milli-celsius */
|
||||
/** Error temperature threshold in milli-celsius */
|
||||
int error;
|
||||
|
||||
/* System shutdown temperature threshold in milli-celsius */
|
||||
/** System shutdown temperature threshold in milli-celsius */
|
||||
int shutdown;
|
||||
} thresholds;
|
||||
|
||||
} onlp_thermal_info_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the thermal subsystem.
|
||||
*/
|
||||
int onlp_thermal_init(void);
|
||||
#define ONLP_THERMAL_INFO_CAP_IS_SET(_pinfo, _name) \
|
||||
((_pinfo)->caps & ONLP_THERMAL_CAPS_##_name)
|
||||
|
||||
/**
|
||||
* @brief Retrieve information about the given thermal id.
|
||||
* @param id The thermal oid.
|
||||
* @param rv [out] Receives the thermal information.
|
||||
* @brief Software initialization of the thermal module.
|
||||
*/
|
||||
int onlp_thermal_info_get(onlp_oid_t id, onlp_thermal_info_t* rv);
|
||||
int onlp_thermal_sw_init(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the thermal's operational status.
|
||||
* @param id The thermal oid.
|
||||
* @param rv [out] Receives the operational status.
|
||||
* @brief Hardware initialization of the thermal module.
|
||||
* @param flags The hardware initialization flags.
|
||||
*/
|
||||
int onlp_thermal_status_get(onlp_oid_t id, uint32_t* rv);
|
||||
int onlp_thermal_hw_init(uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the thermal software module.
|
||||
* @note The primary purpose of this API is to properly
|
||||
* deallocate any resources used by the module in order
|
||||
* faciliate detection of real resouce leaks.
|
||||
*/
|
||||
int onlp_thermal_sw_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the thermal's oid header.
|
||||
* @param id The thermal oid.
|
||||
* @param rv [out] Receives the header.
|
||||
* @param[out] rv Receives the header.
|
||||
*/
|
||||
int onlp_thermal_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv);
|
||||
int onlp_thermal_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Thermal driver ioctl.
|
||||
* @param code Thermal ioctl code.
|
||||
* @param ... Arguments
|
||||
* @brief Retrieve information about the given thermal id.
|
||||
* @param id The thermal oid.
|
||||
* @param[out] rv Receives the thermal information.
|
||||
*/
|
||||
int onlp_thermal_ioctl(int code, ...);
|
||||
int onlp_thermal_info_get(onlp_oid_t oid, onlp_thermal_info_t* rv);
|
||||
|
||||
/**
|
||||
* @brief Thermal driver ioctl.
|
||||
* @param code The thermal ioctl code.
|
||||
* @param vargs The arguments.
|
||||
*/
|
||||
int onlp_thermal_vioctl(int code, va_list vargs);
|
||||
|
||||
/**
|
||||
* @brief Thermal OID debug dump.
|
||||
* @param id The thermal id.
|
||||
* @brief Format a thermal oid.
|
||||
* @param oid The oid.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The dump flags.
|
||||
* @param flags The format flags.
|
||||
*/
|
||||
void onlp_thermal_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags);
|
||||
int onlp_thermal_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
/**
|
||||
* @brief Show the given thermal OID.
|
||||
* @param id The Thermal OID
|
||||
* @param pvs The output pvs
|
||||
* @param flags The output flags
|
||||
* @brief Format a thermal info structure.
|
||||
* @param info The info structure.
|
||||
* @param format The output format.
|
||||
* @param pvs The output pvs.
|
||||
* @param flags The format flags.
|
||||
*/
|
||||
void onlp_thermal_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
int onlp_thermal_info_format(onlp_thermal_info_t* info,
|
||||
onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags);
|
||||
|
||||
|
||||
int onlp_thermal_info_to_user_json(onlp_thermal_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_thermal_info_to_json(onlp_thermal_info_t* info, cJSON** rv, uint32_t flags);
|
||||
int onlp_thermal_info_from_json(cJSON* cj, onlp_thermal_info_t* info);
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
@@ -191,27 +189,6 @@ extern aim_map_si_t onlp_thermal_caps_map[];
|
||||
/** onlp_thermal_caps_desc_map table. */
|
||||
extern aim_map_si_t onlp_thermal_caps_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_thermal_status_name(onlp_thermal_status_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_thermal_status_value(const char* str, onlp_thermal_status_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_thermal_status_desc(onlp_thermal_status_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_thermal_status_valid(onlp_thermal_status_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_THERMAL_STATUS_VALID(_e) \
|
||||
(onlp_thermal_status_valid((_e)))
|
||||
|
||||
/** onlp_thermal_status_map table. */
|
||||
extern aim_map_si_t onlp_thermal_status_map[];
|
||||
/** onlp_thermal_status_desc_map table. */
|
||||
extern aim_map_si_t onlp_thermal_status_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_thermal_threshold_name(onlp_thermal_threshold_t e);
|
||||
|
||||
@@ -235,3 +212,4 @@ extern aim_map_si_t onlp_thermal_threshold_desc_map[];
|
||||
/* <auto.end.enum(tag:thermal).supportheader> */
|
||||
|
||||
#endif /* __ONLP_THERMAL_H__ */
|
||||
/* @} */
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
"""__init__.py
|
||||
|
||||
Module init for aim.
|
||||
"""
|
||||
211
packages/base/any/onlp/src/onlp/module/python/AIM/aim.py
Normal file
211
packages/base/any/onlp/src/onlp/module/python/AIM/aim.py
Normal file
@@ -0,0 +1,211 @@
|
||||
"""aim.py
|
||||
|
||||
Roll-up of structs in AIM that we need.
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
|
||||
from AIM import aim_weakref
|
||||
|
||||
libonlp = None
|
||||
libc = None
|
||||
|
||||
# AIM/aim_memory.h
|
||||
|
||||
class aim_void_p(aim_weakref.AimPointer):
|
||||
|
||||
@classmethod
|
||||
def deletePointer(cls, aimPtr):
|
||||
libonlp.aim_free(aimPtr)
|
||||
|
||||
class aim_char_p(aim_void_p):
|
||||
"""AIM data that is a printable string."""
|
||||
|
||||
def __init__(self, stringOrAddress):
|
||||
|
||||
if stringOrAddress is None:
|
||||
aim_void_p.__init__(self, stringOrAddress)
|
||||
return
|
||||
|
||||
if isinstance(stringOrAddress, aim_void_p):
|
||||
aim_void_p.__init__(self, stringOrAddress)
|
||||
return
|
||||
|
||||
if isinstance(stringOrAddress, basestring):
|
||||
cs = ctypes.c_char_p(stringOrAddress)
|
||||
ptr = libonlp.aim_malloc(len(stringOrAddress)+1)
|
||||
libc.strcpy(ptr, ctypes.addressof(cs))
|
||||
aim_void_p.__init__(self, ptr)
|
||||
return
|
||||
|
||||
if type(stringOrAddress) == int:
|
||||
aim_void_p.__init__(self, stringOrAddress)
|
||||
return
|
||||
|
||||
raise ValueError("invalid initializer for aim_char_p: %s"
|
||||
% repr(stringOrAddress))
|
||||
|
||||
def string_at(self):
|
||||
if self.value:
|
||||
return ctypes.string_at(self.value)
|
||||
else:
|
||||
return None
|
||||
|
||||
def __eq__(self, other):
|
||||
return (isinstance(other, aim_char_p)
|
||||
and (self.string_at()==other.string_at()))
|
||||
|
||||
def __neq__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.string_at())
|
||||
|
||||
def aim_memory_init_prototypes(dll):
|
||||
|
||||
dll.aim_malloc.restype = aim_void_p
|
||||
dll.aim_malloc.argtypes = (ctypes.c_size_t,)
|
||||
|
||||
dll.aim_free.restype = None
|
||||
dll.aim_free.argtypes = (aim_void_p,)
|
||||
|
||||
# AIM/aim_object.h
|
||||
|
||||
aim_object_dtor = ctypes.CFUNCTYPE(None, ctypes.c_void_p)
|
||||
|
||||
class aim_object(ctypes.Structure):
|
||||
_fields_ = [("_id", ctypes.c_char_p,),
|
||||
("subtype", ctypes.c_int,),
|
||||
("cookie", ctypes.c_void_p,),
|
||||
("destructor", aim_object_dtor,),]
|
||||
|
||||
# AIM/aim_pvs.h
|
||||
# AIM/aim_pvs_*.h
|
||||
|
||||
aim_vprintf_f = ctypes.CFUNCTYPE(ctypes.c_int)
|
||||
|
||||
class aim_pvs(ctypes.Structure):
|
||||
_fields_ = [("object", aim_object,),
|
||||
("description", ctypes.c_char_p,),
|
||||
("vprintf", aim_vprintf_f,),
|
||||
("enabled", ctypes.c_int,),
|
||||
("counter", ctypes.c_uint32,),
|
||||
("isatty", aim_vprintf_f,),]
|
||||
|
||||
def aim_pvs_init_prototypes(dll):
|
||||
|
||||
dll.aim_pvs_buffer_create.restype = ctypes.POINTER(aim_pvs)
|
||||
|
||||
dll.aim_pvs_destroy.restype = None
|
||||
dll.aim_pvs_destroy.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
dll.aim_pvs_buffer_size.restype = ctypes.c_int
|
||||
dll.aim_pvs_buffer_size.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
dll.aim_pvs_buffer_get.restype = aim_char_p
|
||||
dll.aim_pvs_buffer_get.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
dll.aim_pvs_buffer_reset.restype = None
|
||||
dll.aim_pvs_buffer_reset.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
# AIM/aim_bitmap.h
|
||||
|
||||
aim_bitmap_word = ctypes.c_uint32
|
||||
AIM_BITMAP_BITS_PER_WORD = 32
|
||||
|
||||
def AIM_BITMAP_WORD_COUNT(bitcount):
|
||||
return ((bitcount // AIM_BITMAP_BITS_PER_WORD)
|
||||
+ (1 if (bitcount % AIM_BITMAP_BITS_PER_WORD) else 0))
|
||||
|
||||
# ugh, most of aim_bitmap.h is inline C
|
||||
|
||||
def AIM_BITMAP_HDR_WORD_GET(hdr, word):
|
||||
"""Return a specific ctypes word."""
|
||||
return hdr.words[word]
|
||||
|
||||
def AIM_BITMAP_HDR_BIT_WORD_GET(hdr, bit):
|
||||
"""Return the ctypes word holding this bit."""
|
||||
return hdr.words[bit/AIM_BITMAP_BITS_PER_WORD]
|
||||
|
||||
def AIM_BITMAP_HDR_BIT_WORD_SET(hdr, bit, word):
|
||||
"""Return the ctypes word holding this bit."""
|
||||
hdr.words[bit/AIM_BITMAP_BITS_PER_WORD] = word
|
||||
|
||||
def AIM_BITMAP_BIT_POS(bit):
|
||||
return (1<<(bit % AIM_BITMAP_BITS_PER_WORD))
|
||||
|
||||
def AIM_BITMAP_INIT(bitmap, count):
|
||||
"""Initialize a static bitmap."""
|
||||
libc.memset(ctypes.byref(bitmap), 0, ctypes.sizeof(bitmap))
|
||||
bitmap.hdr.maxbit = count
|
||||
bitmap.hdr.words = ctypes.cast(ctypes.byref(bitmap.words), ctypes.POINTER(ctypes.c_uint))
|
||||
bitmap.hdr.wordcount = AIM_BITMAP_WORD_COUNT(count)
|
||||
|
||||
class aim_bitmap_hdr(ctypes.Structure):
|
||||
_fields_ = [("wordcount", ctypes.c_int,),
|
||||
("words", ctypes.POINTER(aim_bitmap_word),),
|
||||
("maxbit", ctypes.c_int,),
|
||||
("allocated", ctypes.c_int,),]
|
||||
|
||||
class aim_bitmap(ctypes.Structure):
|
||||
_fields_ = [("hdr", aim_bitmap_hdr,),]
|
||||
|
||||
class aim_bitmap_ref(aim_weakref.AimReference):
|
||||
"""Dynamically allocated aim_bitmap."""
|
||||
|
||||
_fields_ = aim_bitmap._fields_
|
||||
|
||||
def __init__(self, bitcount):
|
||||
ptr = libonlp.aim_bitmap_alloc(None, bitcount)
|
||||
super(aim_bitmap_ref, self).__init__(ptr)
|
||||
|
||||
@classmethod
|
||||
def deleteReference(self, aimPtr):
|
||||
libonlp.aim_free(aimPtr)
|
||||
|
||||
class aim_bitmap256(aim_bitmap):
|
||||
"""Statically-allocated AIM bitmap."""
|
||||
_fields_ = [("words", aim_bitmap_word * AIM_BITMAP_WORD_COUNT(256),),]
|
||||
|
||||
def __init__(self):
|
||||
super(aim_bitmap256, self).__init__()
|
||||
AIM_BITMAP_INIT(self, 255)
|
||||
|
||||
def aim_bitmap_set(hdr, bit):
|
||||
word = AIM_BITMAP_HDR_BIT_WORD_GET(hdr, bit)
|
||||
word |= AIM_BITMAP_BIT_POS(bit)
|
||||
AIM_BITMAP_HDR_BIT_WORD_SET(hdr, bit, word)
|
||||
|
||||
def aim_bitmap_clr(hdr, bit):
|
||||
word = AIM_BITMAP_HDR_BIT_WORD_GET(hdr, bit)
|
||||
word &= ~(AIM_BITMAP_BIT_POS(bit))
|
||||
AIM_BITMAP_HDR_BIT_WORD_SET(hdr, bit, word)
|
||||
|
||||
def aim_bitmap_mod(hdr, bit, value):
|
||||
if value:
|
||||
aim_bitmap_set(hdr, bit)
|
||||
else:
|
||||
aim_bitmap_clr(hdr, bit)
|
||||
|
||||
def aim_bitmap_get(hdr, bit):
|
||||
val = AIM_BITMAP_HDR_BIT_WORD_GET(hdr,bit) & AIM_BITMAP_BIT_POS(bit)
|
||||
return 1 if val else 0
|
||||
|
||||
# Huh, these is inline too, but calls into glibc memset
|
||||
|
||||
def aim_bitmap_set_all(hdr):
|
||||
libc.memset(ctypes.byref(hdr.words), 0xFF, hdr.wordcount*ctypes.sizeof(aim_bitmap_word))
|
||||
|
||||
def aim_bitmap_clr_all(hdr):
|
||||
libc.memset(ctypes.byref(hdr.words), 0x00, hdr.wordcount*ctypes.sizeof(aim_bitmap_word))
|
||||
|
||||
# XXX aim_bitmap_count is left out
|
||||
|
||||
def aim_bitmap_init_prototypes(dll):
|
||||
|
||||
dll.aim_bitmap_alloc.restype = ctypes.POINTER(aim_bitmap)
|
||||
dll.aim_bitmap_alloc.argtypes = (ctypes.POINTER(aim_bitmap), ctypes.c_int,)
|
||||
|
||||
dll.aim_bitmap_free.restype = None
|
||||
dll.aim_bitmap_free.argtypes = (ctypes.POINTER(aim_bitmap),)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
"""__init__.py
|
||||
|
||||
Module init for BigList.
|
||||
"""
|
||||
@@ -0,0 +1,86 @@
|
||||
"""biglist.py
|
||||
|
||||
Subset of BigList/biglist.h.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import ctypes
|
||||
|
||||
libonlp = None
|
||||
|
||||
# BigList/biglist.h (see BigCode .. BigData .. BigList)
|
||||
|
||||
biglist_iter_f = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p)
|
||||
biglist_free_f = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p)
|
||||
|
||||
class BigListVisitor(object):
|
||||
|
||||
def __init__(self, log=None):
|
||||
self.log = log or logging.getLogger("visit")
|
||||
|
||||
def visit(self, data, cookie):
|
||||
return ONLP_STATUS.OK
|
||||
|
||||
def cvisit(self):
|
||||
def _v(data, cookie):
|
||||
try:
|
||||
return self.visit(data, cookie)
|
||||
except:
|
||||
self.log.exception("visitor failed")
|
||||
return ONLP_STATUS.E_GENERIC
|
||||
return biglist_iter_f(_v)
|
||||
|
||||
def foreach(self, blp, cookie):
|
||||
return libonlp.biglist_foreach(blp, self.cvisit(), cookie)
|
||||
|
||||
class BigListIterator(object):
|
||||
|
||||
data_klass = None
|
||||
|
||||
def __init__(self, blp, castType=None):
|
||||
self.blp = blp
|
||||
self.castType = castType or self.data_klass
|
||||
|
||||
def next(self):
|
||||
|
||||
# Hurr, pointer()/POINTER() types are not directly comparable
|
||||
p = ctypes.cast(self.blp, ctypes.c_void_p)
|
||||
if p.value is None:
|
||||
raise StopIteration
|
||||
|
||||
blp, self.blp = self.blp, libonlp.biglist_next(self.blp)
|
||||
cur = blp.contents.data
|
||||
if self.castType is not None:
|
||||
cur = ctypes.cast(cur, ctypes.POINTER(self.castType))
|
||||
return cur.contents
|
||||
else:
|
||||
return cur
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
class biglist(ctypes.Structure):
|
||||
pass
|
||||
|
||||
biglist._fields_ = [("data", ctypes.c_void_p,),
|
||||
("next", ctypes.POINTER(biglist),),
|
||||
("previous", ctypes.POINTER(biglist),),]
|
||||
|
||||
biglist_handle = ctypes.POINTER(ctypes.POINTER(biglist))
|
||||
|
||||
def biglist_init_prototypes(dll):
|
||||
|
||||
##dll.biglist_alloc.restype = ctypes.POINTER(biglist)
|
||||
##dll.biglist_alloc.argtypes = (ctypes.c_void_p, ctypes.POINTER(biglist), ctypes.POINTER(biglist),)
|
||||
|
||||
dll.biglist_next.restype = ctypes.POINTER(biglist)
|
||||
dll.biglist_next.argtypes = (ctypes.POINTER(biglist),)
|
||||
|
||||
dll.biglist_foreach.restype = ctypes.c_int
|
||||
dll.biglist_foreach.argtypes = (ctypes.POINTER(biglist), biglist_iter_f, ctypes.c_void_p,)
|
||||
|
||||
dll.biglist_length.restype = ctypes.c_int
|
||||
dll.biglist_length.argtypes = (ctypes.POINTER(biglist),)
|
||||
|
||||
##dll.biglist_free_all.restype = ctypes.c_int
|
||||
##dll.biglist_free_all.argtypes = (ctypes.POINTER(biglist), biglist_free_f,)
|
||||
@@ -0,0 +1,4 @@
|
||||
"""__init__.py
|
||||
|
||||
Module init for cjson_util
|
||||
"""
|
||||
@@ -0,0 +1,64 @@
|
||||
"""cjson_util.py
|
||||
|
||||
Bindings for a subset of bigcode's cjson_util.
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
import json
|
||||
|
||||
libonlp = None
|
||||
libjson_c = None
|
||||
|
||||
from AIM import aim, aim_weakref
|
||||
|
||||
class cJSON(ctypes.Structure):
|
||||
"""Opaque structure for cJSON data."""
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
"""Coerce into Python data."""
|
||||
cjStr = libonlp.cjson_util_json_str(ctypes.byref(self))
|
||||
cjBuf = ctypes.cast(cjStr, ctypes.c_char_p).value
|
||||
cjData = json.loads(cjBuf)
|
||||
libonlp.aim_free(cjStr)
|
||||
return cjData
|
||||
|
||||
class cJSONHandle(aim_weakref.AimPointer):
|
||||
"""Maintain a handle to a cJSON object allocated from memory."""
|
||||
|
||||
def __init__(self, aimPtr=None):
|
||||
super(cJSONHandle, self).__init__(aimPtr)
|
||||
|
||||
@classmethod
|
||||
def deletePointer(cls, aimPtr):
|
||||
"""Override this with the proper delete semantics."""
|
||||
if aimPtr is not None and aimPtr != 0:
|
||||
libonlp.cJSON_Delete(aimPtr)
|
||||
|
||||
@property
|
||||
def hnd(self):
|
||||
hnd = ctypes.byref(self)
|
||||
return ctypes.cast(hnd, ctypes.POINTER(ctypes.POINTER(cJSON)))
|
||||
|
||||
@property
|
||||
def contents(self):
|
||||
if self.value is None or self.value == 0:
|
||||
raise ValueError("NULL pointer")
|
||||
ptr = ctypes.cast(self.value, ctypes.POINTER(cJSON))
|
||||
return ptr.contents
|
||||
|
||||
def cjson_util_init_prototypes(dll, jsondll):
|
||||
|
||||
dll.cJSON_Delete.argtypes = (ctypes.POINTER(cJSON),)
|
||||
|
||||
dll.cjson_util_yaml_pvs.restype = ctypes.c_int
|
||||
dll.cjson_util_yaml_pvs.argtypes = (ctypes.POINTER(aim.aim_pvs), ctypes.POINTER(cJSON),)
|
||||
|
||||
dll.cjson_util_yaml_str.restype = ctypes.POINTER(ctypes.c_char)
|
||||
dll.cjson_util_yaml_str.argtypes = (ctypes.POINTER(cJSON),)
|
||||
|
||||
dll.cjson_util_json_pvs.restype = ctypes.c_int
|
||||
dll.cjson_util_json_pvs.argtypes = (ctypes.POINTER(aim.aim_pvs), ctypes.POINTER(cJSON),)
|
||||
|
||||
dll.cjson_util_json_str.restype = ctypes.POINTER(ctypes.c_char)
|
||||
dll.cjson_util_json_str.argtypes = (ctypes.POINTER(cJSON),)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,8 +15,8 @@ class Enumeration(object):
|
||||
|
||||
# <auto.start.pyenum(ALL).define>
|
||||
class ONLP_FAN_CAPS(Enumeration):
|
||||
B2F = (1 << 0)
|
||||
F2B = (1 << 1)
|
||||
SET_DIR = (1 << 0)
|
||||
GET_DIR = (1 << 1)
|
||||
SET_RPM = (1 << 2)
|
||||
SET_PERCENTAGE = (1 << 3)
|
||||
GET_RPM = (1 << 4)
|
||||
@@ -24,73 +24,73 @@ class ONLP_FAN_CAPS(Enumeration):
|
||||
|
||||
|
||||
class ONLP_FAN_DIR(Enumeration):
|
||||
B2F = 0
|
||||
F2B = 1
|
||||
|
||||
|
||||
class ONLP_FAN_MODE(Enumeration):
|
||||
OFF = 0
|
||||
SLOW = 1
|
||||
NORMAL = 2
|
||||
FAST = 3
|
||||
MAX = 4
|
||||
|
||||
|
||||
class ONLP_FAN_STATUS(Enumeration):
|
||||
PRESENT = (1 << 0)
|
||||
FAILED = (1 << 1)
|
||||
B2F = (1 << 2)
|
||||
F2B = (1 << 3)
|
||||
UNKNOWN = 0
|
||||
B2F = 1
|
||||
F2B = 2
|
||||
|
||||
|
||||
class ONLP_LED_CAPS(Enumeration):
|
||||
ON_OFF = (1 << 0)
|
||||
CHAR = (1 << 1)
|
||||
RED = (1 << 10)
|
||||
RED_BLINKING = (1 << 11)
|
||||
ORANGE = (1 << 12)
|
||||
ORANGE_BLINKING = (1 << 13)
|
||||
YELLOW = (1 << 14)
|
||||
YELLOW_BLINKING = (1 << 15)
|
||||
GREEN = (1 << 16)
|
||||
GREEN_BLINKING = (1 << 17)
|
||||
BLUE = (1 << 18)
|
||||
BLUE_BLINKING = (1 << 19)
|
||||
PURPLE = (1 << 20)
|
||||
PURPLE_BLINKING = (1 << 21)
|
||||
AUTO = (1 << 22)
|
||||
AUTO_BLINKING = (1 << 23)
|
||||
OFF = (1 << 0)
|
||||
AUTO = (1 << 1)
|
||||
AUTO_BLINKING = (1 << 2)
|
||||
CHAR = (1 << 3)
|
||||
RED = (1 << 4)
|
||||
RED_BLINKING = (1 << 5)
|
||||
ORANGE = (1 << 6)
|
||||
ORANGE_BLINKING = (1 << 7)
|
||||
YELLOW = (1 << 8)
|
||||
YELLOW_BLINKING = (1 << 9)
|
||||
GREEN = (1 << 10)
|
||||
GREEN_BLINKING = (1 << 11)
|
||||
BLUE = (1 << 12)
|
||||
BLUE_BLINKING = (1 << 13)
|
||||
PURPLE = (1 << 14)
|
||||
PURPLE_BLINKING = (1 << 15)
|
||||
|
||||
|
||||
class ONLP_LED_MODE(Enumeration):
|
||||
OFF = 0
|
||||
ON = 1
|
||||
BLINKING = 2
|
||||
RED = 10
|
||||
RED_BLINKING = 11
|
||||
ORANGE = 12
|
||||
ORANGE_BLINKING = 13
|
||||
YELLOW = 14
|
||||
YELLOW_BLINKING = 15
|
||||
GREEN = 16
|
||||
GREEN_BLINKING = 17
|
||||
BLUE = 18
|
||||
BLUE_BLINKING = 19
|
||||
PURPLE = 20
|
||||
PURPLE_BLINKING = 21
|
||||
AUTO = 22
|
||||
AUTO_BLINKING = 23
|
||||
AUTO = 1
|
||||
AUTO_BLINKING = 2
|
||||
CHAR = 3
|
||||
RED = 4
|
||||
RED_BLINKING = 5
|
||||
ORANGE = 6
|
||||
ORANGE_BLINKING = 7
|
||||
YELLOW = 8
|
||||
YELLOW_BLINKING = 9
|
||||
GREEN = 10
|
||||
GREEN_BLINKING = 11
|
||||
BLUE = 12
|
||||
BLUE_BLINKING = 13
|
||||
PURPLE = 14
|
||||
PURPLE_BLINKING = 15
|
||||
|
||||
|
||||
class ONLP_LED_STATUS(Enumeration):
|
||||
PRESENT = (1 << 0)
|
||||
FAILED = (1 << 1)
|
||||
ON = (1 << 2)
|
||||
class ONLP_LOG_FLAG(Enumeration):
|
||||
JSON = 0
|
||||
|
||||
|
||||
class ONLP_OID_DUMP(Enumeration):
|
||||
RECURSE = (1 << 0)
|
||||
EVEN_IF_ABSENT = (1 << 1)
|
||||
RECURSE = 0
|
||||
EVEN_IF_ABSENT = 1
|
||||
|
||||
|
||||
class ONLP_OID_FORMAT(Enumeration):
|
||||
JSON = 0
|
||||
YAML = 1
|
||||
USER = 2
|
||||
DEBUG = 3
|
||||
|
||||
|
||||
class ONLP_OID_FORMAT_FLAGS(Enumeration):
|
||||
RECURSIVE = (1 << 0)
|
||||
MISSING = (1 << 1)
|
||||
|
||||
|
||||
class ONLP_OID_JSON_FLAG(Enumeration):
|
||||
RECURSIVE = (1 << 0)
|
||||
UNSUPPORTED_FIELDS = (1 << 1)
|
||||
|
||||
|
||||
class ONLP_OID_SHOW(Enumeration):
|
||||
@@ -99,32 +99,49 @@ class ONLP_OID_SHOW(Enumeration):
|
||||
YAML = (1 << 2)
|
||||
|
||||
|
||||
class ONLP_OID_STATUS_FLAG(Enumeration):
|
||||
PRESENT = (1 << 0)
|
||||
FAILED = (1 << 1)
|
||||
OPERATIONAL = (1 << 2)
|
||||
UNPLUGGED = (1 << 3)
|
||||
|
||||
|
||||
class ONLP_OID_TYPE(Enumeration):
|
||||
SYS = 1
|
||||
THERMAL = 2
|
||||
FAN = 3
|
||||
PSU = 4
|
||||
LED = 5
|
||||
MODULE = 6
|
||||
RTC = 7
|
||||
CHASSIS = 1
|
||||
MODULE = 2
|
||||
THERMAL = 3
|
||||
FAN = 4
|
||||
PSU = 5
|
||||
LED = 6
|
||||
SFP = 7
|
||||
GENERIC = 8
|
||||
|
||||
|
||||
class ONLP_OID_TYPE_FLAG(Enumeration):
|
||||
CHASSIS = (1 << 1)
|
||||
MODULE = (1 << 2)
|
||||
THERMAL = (1 << 3)
|
||||
FAN = (1 << 4)
|
||||
PSU = (1 << 5)
|
||||
LED = (1 << 6)
|
||||
SFP = (1 << 7)
|
||||
GENERIC = (1 << 8)
|
||||
|
||||
|
||||
class ONLP_PSU_CAPS(Enumeration):
|
||||
AC = (1 << 0)
|
||||
DC12 = (1 << 1)
|
||||
DC48 = (1 << 2)
|
||||
VIN = (1 << 3)
|
||||
VOUT = (1 << 4)
|
||||
IIN = (1 << 5)
|
||||
IOUT = (1 << 6)
|
||||
PIN = (1 << 7)
|
||||
POUT = (1 << 8)
|
||||
GET_TYPE = (1 << 0)
|
||||
GET_VIN = (1 << 1)
|
||||
GET_VOUT = (1 << 2)
|
||||
GET_IIN = (1 << 3)
|
||||
GET_IOUT = (1 << 4)
|
||||
GET_PIN = (1 << 5)
|
||||
GET_POUT = (1 << 6)
|
||||
|
||||
|
||||
class ONLP_PSU_STATUS(Enumeration):
|
||||
PRESENT = (1 << 0)
|
||||
FAILED = (1 << 1)
|
||||
UNPLUGGED = (1 << 2)
|
||||
class ONLP_PSU_TYPE(Enumeration):
|
||||
AC = 0
|
||||
DC12 = 1
|
||||
DC48 = 2
|
||||
|
||||
|
||||
class ONLP_SFP_CONTROL(Enumeration):
|
||||
@@ -149,6 +166,13 @@ class ONLP_SFP_CONTROL_FLAG(Enumeration):
|
||||
POWER_OVERRIDE = (1 << 7)
|
||||
|
||||
|
||||
class ONLP_SFP_TYPE(Enumeration):
|
||||
SFP = 0
|
||||
QSFP = 1
|
||||
SFP28 = 2
|
||||
QSFP28 = 3
|
||||
|
||||
|
||||
class ONLP_STATUS(Enumeration):
|
||||
OK = 0
|
||||
E_GENERIC = -1
|
||||
@@ -167,11 +191,6 @@ class ONLP_THERMAL_CAPS(Enumeration):
|
||||
GET_SHUTDOWN_THRESHOLD = (1 << 3)
|
||||
|
||||
|
||||
class ONLP_THERMAL_STATUS(Enumeration):
|
||||
PRESENT = (1 << 0)
|
||||
FAILED = (1 << 1)
|
||||
|
||||
|
||||
class ONLP_THERMAL_THRESHOLD(Enumeration):
|
||||
WARNING_DEFAULT = 45000
|
||||
ERROR_DEFAULT = 55000
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,4 @@
|
||||
include $(ONL)/make/config.mk
|
||||
|
||||
ucli:
|
||||
$(SUBMODULE_BIGCODE)/tools/uclihandlers.py onlp_ucli.c
|
||||
|
||||
|
||||
$(SUBMODULE_BIGCODE)/tools/uclihandlers2.py onlp_ucli.c
|
||||
|
||||
143
packages/base/any/onlp/src/onlp/module/src/attribute.c
Normal file
143
packages/base/any/onlp/src/onlp/module/src/attribute.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2017 v=onl>
|
||||
*
|
||||
* Copyright 2017 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Attribute Implementation.
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/attribute.h>
|
||||
#include <onlp/platformi/attributei.h>
|
||||
#include <onlp/stdattrs.h>
|
||||
#include <onlp/oids.h>
|
||||
#include "onlp_int.h"
|
||||
#include "onlp_locks.h"
|
||||
#include "onlp_log.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize the attribute subsystem.
|
||||
*/
|
||||
static int
|
||||
onlp_attribute_sw_init_locked__(void)
|
||||
{
|
||||
return onlp_attributei_sw_init();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_attribute_sw_init)
|
||||
|
||||
static int
|
||||
onlp_attribute_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
return onlp_attributei_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_attribute_hw_init, uint32_t, flags)
|
||||
|
||||
/**
|
||||
* @brief Determine whether the OID supports the given attribute.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute name.
|
||||
*/
|
||||
static int
|
||||
onlp_attribute_supported_locked__(onlp_oid_t oid, const char* attribute)
|
||||
{
|
||||
if(ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ONIE_INFO_JSON)) {
|
||||
attribute = ONLP_ATTRIBUTE_ONIE_INFO;
|
||||
}
|
||||
if(ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ASSET_INFO_JSON)) {
|
||||
attribute = ONLP_ATTRIBUTE_ASSET_INFO;
|
||||
}
|
||||
return onlp_attributei_supported(oid, attribute);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_attribute_supported, onlp_oid_t, oid, const char*, attribute)
|
||||
|
||||
/**
|
||||
* @brief Set an attribute on the given OID.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute name.
|
||||
* @param value A pointer to the value.
|
||||
*/
|
||||
static int
|
||||
onlp_attribute_set_locked__(onlp_oid_t oid, const char* attribute, void* value)
|
||||
{
|
||||
return onlp_attributei_set(oid, attribute, value);
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_attribute_set, onlp_oid_t, oid, const char*, attribute, void*, value)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Free an attribute value returned from onlp_attribute_get().
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute.
|
||||
* @param value The value.
|
||||
*/
|
||||
static int
|
||||
onlp_attribute_free_locked__(onlp_oid_t oid, const char* attribute, void* value)
|
||||
{
|
||||
if(ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ONIE_INFO_JSON) ||
|
||||
ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ASSET_INFO_JSON)) {
|
||||
cJSON_Delete(value);
|
||||
return 0;
|
||||
}
|
||||
return onlp_attributei_free(oid, attribute, value);
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_attribute_free,onlp_oid_t, oid, const char*, attribute, void*, value)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get an attribute from the given OID.
|
||||
* @param oid The OID.
|
||||
* @param attribute The attribute to retrieve.
|
||||
* @param[out] value Receives the attribute's value.
|
||||
*/
|
||||
static int
|
||||
onlp_attribute_get_locked__(onlp_oid_t oid, const char* attribute,
|
||||
void** value)
|
||||
{
|
||||
int rv;
|
||||
const char* rattr = attribute;
|
||||
|
||||
if(ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ONIE_INFO_JSON)) {
|
||||
rattr = ONLP_ATTRIBUTE_ONIE_INFO;
|
||||
}
|
||||
if(ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ASSET_INFO_JSON)) {
|
||||
rattr = ONLP_ATTRIBUTE_ASSET_INFO;
|
||||
}
|
||||
|
||||
rv = onlp_attributei_get(oid, rattr, value);
|
||||
|
||||
if(ONLP_FAILURE(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if(ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ONIE_INFO_JSON)) {
|
||||
cJSON* cj;
|
||||
onlp_onie_info_to_json(*(onlp_onie_info_t**)value, &cj);
|
||||
onlp_attribute_free_locked__(oid, rattr, *value);
|
||||
*value = cj;
|
||||
}
|
||||
|
||||
if(ONLP_ATTRIBUTE_EQUALS(attribute, ONLP_ATTRIBUTE_ASSET_INFO_JSON)) {
|
||||
cJSON* cj;
|
||||
onlp_asset_info_to_json(*(onlp_asset_info_t**)value, &cj);
|
||||
onlp_attribute_free_locked__(oid, rattr, *value);
|
||||
*value = cj;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_attribute_get, onlp_oid_t, oid, const char*, attribute, void**, value)
|
||||
117
packages/base/any/onlp/src/onlp/module/src/chassis.c
Normal file
117
packages/base/any/onlp/src/onlp/module/src/chassis.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/chassis.h>
|
||||
#include <onlp/platformi/chassisi.h>
|
||||
#include <AIM/aim.h>
|
||||
#include "onlp_log.h"
|
||||
#include "onlp_int.h"
|
||||
#include "onlp_locks.h"
|
||||
|
||||
|
||||
static int
|
||||
onlp_chassis_sw_init_locked__(void)
|
||||
{
|
||||
return onlp_chassisi_sw_init();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_chassis_sw_init);
|
||||
|
||||
static int
|
||||
onlp_chassis_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
return onlp_chassisi_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_chassis_hw_init, uint32_t, flags);
|
||||
|
||||
static int
|
||||
onlp_chassis_sw_denit_locked__(void)
|
||||
{
|
||||
return onlp_chassisi_sw_denit();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_chassis_sw_denit);
|
||||
|
||||
static int
|
||||
onlp_chassis_hdr_get_locked__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
ONLP_OID_CHASSIS_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(hdr);
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
int rv = onlp_chassisi_hdr_get(oid, hdr);
|
||||
onlp_oid_hdr_sort(hdr);
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_chassis_hdr_get, onlp_oid_t, oid, onlp_oid_hdr_t*, hdr);
|
||||
|
||||
|
||||
static int
|
||||
onlp_chassis_info_get_locked__(onlp_oid_t oid, onlp_chassis_info_t* cip)
|
||||
{
|
||||
ONLP_OID_CHASSIS_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(cip);
|
||||
int rv = onlp_chassisi_info_get(oid, cip);
|
||||
onlp_oid_hdr_sort(&cip->hdr);
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_chassis_info_get,onlp_oid_t, oid,
|
||||
onlp_chassis_info_t*, rv);
|
||||
|
||||
int
|
||||
onlp_chassis_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_chassis_info_format(onlp_chassis_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_chassis_info_to_user_json(onlp_chassis_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
cJSON* object = NULL;
|
||||
if(ONLP_SUCCESS(rv = onlp_info_to_user_json_create(&info->hdr, &object, flags))) {
|
||||
rv = onlp_info_to_user_json_finish(&info->hdr, object, cjp, flags);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_chassis_info_to_json(onlp_chassis_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
cJSON* cj = NULL;
|
||||
ONLP_IF_ERROR_RETURN(onlp_info_to_json_create(&info->hdr, &cj, flags));
|
||||
return onlp_info_to_json_finish(&info->hdr, cj, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_chassis_info_from_json(cJSON* cj, onlp_chassis_info_t* info)
|
||||
{
|
||||
memset(info, 0, sizeof(*info));
|
||||
return onlp_oid_hdr_from_json(cj, &info->hdr);
|
||||
}
|
||||
@@ -29,159 +29,71 @@
|
||||
#include "onlp_locks.h"
|
||||
#include "onlp_log.h"
|
||||
#include "onlp_json.h"
|
||||
#include <cjson_util/cjson_util_format.h>
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_FAN(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define VALIDATENR(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_FAN(_id)) { \
|
||||
return; \
|
||||
} \
|
||||
} while(0)
|
||||
/**
|
||||
* Fan Software Init
|
||||
*/
|
||||
static int
|
||||
onlp_fan_sw_init_locked__(void)
|
||||
{
|
||||
return onlp_fani_sw_init();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_fan_sw_init)
|
||||
|
||||
/**
|
||||
* Fan Hardware Init
|
||||
*/
|
||||
static int
|
||||
onlp_fan_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
return onlp_fani_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_fan_hw_init, uint32_t, flags);
|
||||
|
||||
static int
|
||||
onlp_fan_init_locked__(void)
|
||||
onlp_fan_sw_denit_locked__(void)
|
||||
{
|
||||
return onlp_fani_init();
|
||||
return onlp_fani_sw_denit();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_fan_init)
|
||||
|
||||
|
||||
#if ONLP_CONFIG_INCLUDE_PLATFORM_OVERRIDES == 1
|
||||
|
||||
static int
|
||||
onlp_fani_info_from_json__(cJSON* data, onlp_fan_info_t* fip, int errorcheck)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if(data == NULL) {
|
||||
return (errorcheck) ? ONLP_STATUS_E_PARAM : 0;
|
||||
}
|
||||
|
||||
rv = cjson_util_lookup_int(data, (int*) &fip->status, "status");
|
||||
if(rv < 0 && errorcheck) return rv;
|
||||
|
||||
rv = cjson_util_lookup_int(data, (int*) &fip->caps, "caps");
|
||||
if(rv < 0 && errorcheck) return rv;
|
||||
|
||||
rv = cjson_util_lookup_int(data, (int*) &fip->rpm, "rpm");
|
||||
if(rv < 0 && errorcheck) return rv;
|
||||
|
||||
rv = cjson_util_lookup_int(data, (int*) &fip->percentage, "percentage");
|
||||
if(rv < 0 && errorcheck) return rv;
|
||||
|
||||
rv = cjson_util_lookup_int(data, (int*) &fip->mode, "mode");
|
||||
if(rv < 0 && errorcheck) return rv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int
|
||||
onlp_fan_info_get_locked__(onlp_oid_t oid, onlp_fan_info_t* fip)
|
||||
{
|
||||
int rv;
|
||||
|
||||
VALIDATE(oid);
|
||||
|
||||
/* Get the information struct from the platform */
|
||||
rv = onlp_fani_info_get(oid, fip);
|
||||
|
||||
if(rv >= 0) {
|
||||
|
||||
#if ONLP_CONFIG_INCLUDE_PLATFORM_OVERRIDES == 1
|
||||
/*
|
||||
* Optional override from the config file.
|
||||
* This is usually just for testing.
|
||||
*/
|
||||
int id = ONLP_OID_ID_GET(oid);
|
||||
cJSON* entry = NULL;
|
||||
|
||||
|
||||
cjson_util_lookup(onlp_json_get(0), &entry, "overrides.fan.%d", id);
|
||||
onlp_fani_info_from_json__(entry, fip, 0);
|
||||
#endif
|
||||
|
||||
if(fip->percentage && fip->rpm == 0) {
|
||||
/* Approximate RPM based on a 10,000 RPM Maximum */
|
||||
fip->rpm = fip->percentage * 100;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_fan_info_get, onlp_oid_t, oid, onlp_fan_info_t*, fip);
|
||||
|
||||
static int
|
||||
onlp_fan_status_get_locked__(onlp_oid_t oid, uint32_t* status)
|
||||
{
|
||||
int rv = onlp_fani_status_get(oid, status);
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_fan_info_t fi;
|
||||
rv = onlp_fani_info_get(oid, &fi);
|
||||
*status = fi.status;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_fan_status_get, onlp_oid_t, oid, uint32_t*, status);
|
||||
ONLP_LOCKED_API0(onlp_fan_sw_denit);
|
||||
|
||||
/**
|
||||
* Fan Header Get
|
||||
*/
|
||||
static int
|
||||
onlp_fan_hdr_get_locked__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
int rv = onlp_fani_hdr_get(oid, hdr);
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_fan_info_t fi;
|
||||
rv = onlp_fani_info_get(oid, &fi);
|
||||
memcpy(hdr, &fi.hdr, sizeof(fi.hdr));
|
||||
}
|
||||
return rv;
|
||||
ONLP_OID_FAN_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(hdr);
|
||||
return onlp_log_error(0,
|
||||
onlp_fani_hdr_get(oid, hdr),
|
||||
"fani hdr get %{onlp_oid}", oid);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_fan_hdr_get, onlp_oid_t, oid, onlp_oid_hdr_t*, hdr);
|
||||
|
||||
/**
|
||||
* Fan Info Get
|
||||
*/
|
||||
static int
|
||||
onlp_fan_present__(onlp_oid_t id, onlp_fan_info_t* info)
|
||||
onlp_fan_info_get_locked__(onlp_oid_t oid, onlp_fan_info_t* fip)
|
||||
{
|
||||
int rv;
|
||||
VALIDATE(id);
|
||||
|
||||
/* Info retrieval required. */
|
||||
rv = onlp_fani_info_get(id, info);
|
||||
if(rv < 0) {
|
||||
return rv;
|
||||
}
|
||||
/* The fan must be present. */
|
||||
if((info->status & 0x1) == 0) {
|
||||
return ONLP_STATUS_E_MISSING;
|
||||
}
|
||||
return ONLP_STATUS_OK;
|
||||
ONLP_OID_FAN_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(fip);
|
||||
return onlp_log_error(0,
|
||||
onlp_fani_info_get(oid, fip),
|
||||
"fani info get %{onlp_oid}", oid);
|
||||
}
|
||||
#define ONLP_FAN_PRESENT_OR_RETURN(_id, _info) \
|
||||
do { \
|
||||
int _rv = onlp_fan_present__(_id, _info); \
|
||||
if(_rv < 0) { \
|
||||
return _rv; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
ONLP_LOCKED_API2(onlp_fan_info_get, onlp_oid_t, oid, onlp_fan_info_t*, fip);
|
||||
|
||||
static int
|
||||
onlp_fan_rpm_set_locked__(onlp_oid_t id, int rpm)
|
||||
{
|
||||
onlp_fan_info_t info;
|
||||
ONLP_FAN_PRESENT_OR_RETURN(id, &info);
|
||||
|
||||
ONLP_OID_FAN_VALIDATE(id);
|
||||
ONLP_TRY(onlp_fani_info_get(id, &info));
|
||||
|
||||
if(info.caps & ONLP_FAN_CAPS_SET_RPM) {
|
||||
return onlp_fani_rpm_set(id, rpm);
|
||||
}
|
||||
@@ -195,7 +107,8 @@ static int
|
||||
onlp_fan_percentage_set_locked__(onlp_oid_t id, int p)
|
||||
{
|
||||
onlp_fan_info_t info;
|
||||
ONLP_FAN_PRESENT_OR_RETURN(id, &info);
|
||||
ONLP_OID_FAN_VALIDATE(id);
|
||||
ONLP_TRY(onlp_fani_info_get(id, &info));
|
||||
if(info.caps & ONLP_FAN_CAPS_SET_PERCENTAGE) {
|
||||
return onlp_fani_percentage_set(id, p);
|
||||
}
|
||||
@@ -205,22 +118,13 @@ onlp_fan_percentage_set_locked__(onlp_oid_t id, int p)
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_fan_percentage_set, onlp_oid_t, id, int, p);
|
||||
|
||||
static int
|
||||
onlp_fan_mode_set_locked__(onlp_oid_t id, onlp_fan_mode_t mode)
|
||||
{
|
||||
onlp_fan_info_t info;
|
||||
ONLP_FAN_PRESENT_OR_RETURN(id, &info);
|
||||
return onlp_fani_mode_set(id, mode);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_fan_mode_set, onlp_oid_t, id, onlp_fan_mode_t, mode);
|
||||
|
||||
static int
|
||||
onlp_fan_dir_set_locked__(onlp_oid_t id, onlp_fan_dir_t dir)
|
||||
{
|
||||
onlp_fan_info_t info;
|
||||
ONLP_FAN_PRESENT_OR_RETURN(id, &info);
|
||||
if( (info.caps & ONLP_FAN_CAPS_B2F) &&
|
||||
(info.caps & ONLP_FAN_CAPS_F2B) ) {
|
||||
ONLP_OID_FAN_VALIDATE(id);
|
||||
ONLP_TRY(onlp_fani_info_get(id, &info));
|
||||
if(info.caps & ONLP_FAN_CAPS_SET_DIR) {
|
||||
return onlp_fani_dir_set(id, dir);
|
||||
}
|
||||
else {
|
||||
@@ -230,110 +134,118 @@ onlp_fan_dir_set_locked__(onlp_oid_t id, onlp_fan_dir_t dir)
|
||||
ONLP_LOCKED_API2(onlp_fan_dir_set, onlp_oid_t, id, onlp_fan_dir_t, dir);
|
||||
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* Debug and Show Functions
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
void
|
||||
onlp_fan_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
int
|
||||
onlp_fan_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_fan_info_t info;
|
||||
|
||||
VALIDATENR(id);
|
||||
|
||||
onlp_oid_dump_iof_init_default(&iof, pvs);
|
||||
iof_push(&iof, "fan @ %d", ONLP_OID_ID_GET(id));
|
||||
rv = onlp_fan_info_get(id, &info);
|
||||
if(rv < 0) {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_description(&iof, &info.hdr);
|
||||
if(info.status & 1) {
|
||||
/* Present */
|
||||
iof_iprintf(&iof, "Status: %{onlp_fan_status_flags}", info.status);
|
||||
iof_iprintf(&iof, "Caps: %{onlp_fan_caps_flags}", info.caps);
|
||||
iof_iprintf(&iof, "RPM: %d", info.rpm);
|
||||
iof_iprintf(&iof, "Per: %d", info.percentage);
|
||||
iof_iprintf(&iof, "Model: %s", info.model[0] ? info.model : "NULL");
|
||||
iof_iprintf(&iof, "SN: %s", info.serial[0] ? info.serial : "NULL");
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Not present.");
|
||||
}
|
||||
}
|
||||
iof_pop(&iof);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
onlp_fan_show(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags)
|
||||
int
|
||||
onlp_fan_info_format(onlp_fan_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_fan_info_t fi;
|
||||
int yaml;
|
||||
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
|
||||
rv = onlp_fan_info_get(oid, &fi);
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "- ");
|
||||
iof_iprintf(&iof, "Name: Fan %d", ONLP_OID_ID_GET(oid));
|
||||
}
|
||||
else {
|
||||
iof_push(&iof, "Fan %d", ONLP_OID_ID_GET(oid));
|
||||
}
|
||||
|
||||
if(rv < 0) {
|
||||
if(yaml) {
|
||||
iof_iprintf(&iof, "State: Error");
|
||||
iof_iprintf(&iof, "Error: %{onlp_status}", rv);
|
||||
} else {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
}
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_description(&iof, &fi.hdr);
|
||||
if(fi.status & 0x1) {
|
||||
/* Present */
|
||||
iof_iprintf(&iof, "State: Present");
|
||||
if(fi.status & ONLP_FAN_STATUS_FAILED) {
|
||||
iof_iprintf(&iof, "Status: Failed");
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Status: Running");
|
||||
if(fi.model[0]) {
|
||||
iof_iprintf(&iof, "Model: %s", fi.model);
|
||||
}
|
||||
if(fi.serial[0]) {
|
||||
iof_iprintf(&iof, "SN: %s", fi.serial);
|
||||
}
|
||||
if(fi.caps & ONLP_FAN_CAPS_GET_RPM) {
|
||||
iof_iprintf(&iof, "RPM: %d", fi.rpm);
|
||||
}
|
||||
if(fi.caps & ONLP_FAN_CAPS_GET_PERCENTAGE) {
|
||||
iof_iprintf(&iof, "Speed: %d%%", fi.percentage);
|
||||
}
|
||||
if(fi.status & ONLP_FAN_STATUS_B2F) {
|
||||
iof_iprintf(&iof, "Airflow: Back-to-Front");
|
||||
}
|
||||
if(fi.status & ONLP_FAN_STATUS_F2B) {
|
||||
iof_iprintf(&iof, "Airflow: Front-to-Back");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Not present */
|
||||
onlp_oid_show_state_missing(&iof);
|
||||
}
|
||||
}
|
||||
iof_pop(&iof);
|
||||
aim_printf(pvs, "%{onlp_oid_hdr} dir=%{onlp_fan_dir} caps=%{onlp_fan_caps_flags} rpm=%d p=%d] model='%s' serial='%s'\n",
|
||||
info, info->dir, info->caps, info->rpm, info->percentage, info->model, info->serial);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_fan_info_to_user_json(onlp_fan_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
cJSON* object;
|
||||
|
||||
rv = onlp_info_to_user_json_create(&info->hdr, &object, flags);
|
||||
|
||||
if(rv > 0) {
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_RPM)) {
|
||||
cjson_util_add_string_to_object(object, "RPM", "%d", info->rpm);
|
||||
}
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_PERCENTAGE)) {
|
||||
cjson_util_add_string_to_object(object, "Speed", "%d%%", info->percentage);
|
||||
}
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_DIR)) {
|
||||
switch(info->dir)
|
||||
{
|
||||
case ONLP_FAN_DIR_F2B: cjson_util_add_string_to_object(object, "Airflow", "Front-To-Back"); break;
|
||||
case ONLP_FAN_DIR_B2F: cjson_util_add_string_to_object(object, "Airflow", "Back-To-Front"); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return onlp_info_to_user_json_finish(&info->hdr, object, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_fan_info_to_json(onlp_fan_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
cJSON* cj;
|
||||
int unsupported = (flags & ONLP_OID_JSON_FLAG_UNSUPPORTED_FIELDS);
|
||||
|
||||
ONLP_IF_ERROR_RETURN(onlp_info_to_json_create(&info->hdr, &cj, flags));
|
||||
|
||||
cJSON_AddItemToObject(cj, "caps", cjson_util_flag_array(info->caps,
|
||||
onlp_fan_caps_map));
|
||||
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_DIR) || unsupported) {
|
||||
cjson_util_add_string_to_object(cj, "dir", "%{onlp_fan_dir}",
|
||||
info->dir);
|
||||
}
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_RPM) || unsupported) {
|
||||
cJSON_AddNumberToObject(cj, "rpm", info->rpm);
|
||||
}
|
||||
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_PERCENTAGE) || unsupported) {
|
||||
cJSON_AddNumberToObject(cj, "percentage", info->percentage);
|
||||
}
|
||||
if(info->model[0] || unsupported) {
|
||||
cJSON_AddStringToObject(cj, "model", info->model);
|
||||
}
|
||||
if(info->serial[0] || unsupported) {
|
||||
cJSON_AddStringToObject(cj, "serial", info->serial);
|
||||
}
|
||||
|
||||
return onlp_info_to_json_finish(&info->hdr, cj, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_fan_info_from_json(cJSON* cj, onlp_fan_info_t* info)
|
||||
{
|
||||
cJSON* j;
|
||||
|
||||
ONLP_IF_ERROR_RETURN(onlp_oid_hdr_from_json(cj, &info->hdr));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup(cj, &j, "caps"));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_array_to_flags(j, &info->caps,
|
||||
onlp_fan_caps_map));
|
||||
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_RPM)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->rpm, "rpm"));
|
||||
}
|
||||
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_PERCENTAGE)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->percentage,
|
||||
"percentage"));
|
||||
}
|
||||
|
||||
if(ONLP_FAN_INFO_CAP_IS_SET(info, GET_DIR)) {
|
||||
char* dir = NULL;
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_string(cj, &dir, "dir"));
|
||||
if(ONLP_FAILURE(onlp_fan_dir_value(dir, &info->dir, 1))) {
|
||||
ONLP_LOG_JSON("%s: '%s' is not a valid fan direction.",
|
||||
__FUNCTION__, dir);
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
char* s;
|
||||
if((s = cjson_util_lookup_string_default(cj, NULL, "model"))) {
|
||||
aim_strlcpy(info->model, s, sizeof(info->model));
|
||||
}
|
||||
if((s = cjson_util_lookup_string_default(cj, NULL, "serial"))) {
|
||||
aim_strlcpy(info->serial, s, sizeof(info->model));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
64
packages/base/any/onlp/src/onlp/module/src/generic.c
Normal file
64
packages/base/any/onlp/src/onlp/module/src/generic.c
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <onlp/generic.h>
|
||||
|
||||
int
|
||||
onlp_generic_sw_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_hw_init(uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_sw_denit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_info_get(onlp_oid_t id, onlp_generic_info_t* info)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_info_format(onlp_generic_info_t* info,
|
||||
onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_info_to_user_json(onlp_generic_info_t* info, cJSON** rv, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_info_to_json(onlp_generic_info_t* info, cJSON** rv, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_generic_info_from_json(cJSON* cj, onlp_generic_info_t* info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -29,26 +29,10 @@
|
||||
#include "onlp_int.h"
|
||||
#include "onlp_locks.h"
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_LED(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define VALIDATENR(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_LED(_id)) { \
|
||||
return; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
static int
|
||||
onlp_led_present__(onlp_oid_t id, onlp_led_info_t* info)
|
||||
{
|
||||
int rv;
|
||||
VALIDATE(id);
|
||||
|
||||
/* Info retrieval required. */
|
||||
rv = onlp_ledi_info_get(id, info);
|
||||
@@ -56,7 +40,7 @@ onlp_led_present__(onlp_oid_t id, onlp_led_info_t* info)
|
||||
return rv;
|
||||
}
|
||||
/* The led must be present. */
|
||||
if((info->status & 0x1) == 0) {
|
||||
if((info->hdr.status & 0x1) == 0) {
|
||||
return ONLP_STATUS_E_MISSING;
|
||||
}
|
||||
return ONLP_STATUS_OK;
|
||||
@@ -69,66 +53,53 @@ onlp_led_present__(onlp_oid_t id, onlp_led_info_t* info)
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static int
|
||||
onlp_led_init_locked__(void)
|
||||
{
|
||||
return onlp_ledi_init();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_led_init);
|
||||
|
||||
static int
|
||||
onlp_led_info_get_locked__(onlp_oid_t id, onlp_led_info_t* info)
|
||||
onlp_led_sw_init_locked__(void)
|
||||
{
|
||||
VALIDATE(id);
|
||||
return onlp_ledi_info_get(id, info);
|
||||
return onlp_ledi_sw_init();
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_led_info_get, onlp_oid_t, id, onlp_led_info_t*, info);
|
||||
ONLP_LOCKED_API0(onlp_led_sw_init);
|
||||
|
||||
|
||||
static int
|
||||
onlp_led_status_get_locked__(onlp_oid_t id, uint32_t* status)
|
||||
onlp_led_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
int rv = onlp_ledi_status_get(id, status);
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_led_info_t li;
|
||||
rv = onlp_ledi_info_get(id, &li);
|
||||
*status = li.status;
|
||||
}
|
||||
return rv;
|
||||
return onlp_ledi_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_led_status_get, onlp_oid_t, id, uint32_t*, status);
|
||||
ONLP_LOCKED_API1(onlp_led_hw_init, uint32_t, flags);
|
||||
|
||||
static int
|
||||
onlp_led_hdr_get_locked__(onlp_oid_t id, onlp_oid_hdr_t* hdr)
|
||||
onlp_led_sw_denit_locked__(void)
|
||||
{
|
||||
int rv = onlp_ledi_hdr_get(id, hdr);
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_led_info_t li;
|
||||
rv = onlp_ledi_info_get(id, &li);
|
||||
memcpy(hdr, &li.hdr, sizeof(li.hdr));
|
||||
}
|
||||
return rv;
|
||||
return onlp_ledi_sw_denit();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_led_sw_denit);
|
||||
|
||||
|
||||
static int
|
||||
onlp_led_hdr_get_locked__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
ONLP_OID_LED_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(hdr);
|
||||
return onlp_log_error(0x0,
|
||||
onlp_ledi_hdr_get(oid, hdr),
|
||||
"ledi hdr get %{onlp_oid}", oid);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_led_hdr_get, onlp_oid_t, id, onlp_oid_hdr_t*, hdr);
|
||||
|
||||
|
||||
static int
|
||||
onlp_led_set_locked__(onlp_oid_t id, int on_or_off)
|
||||
onlp_led_info_get_locked__(onlp_oid_t oid, onlp_led_info_t* info)
|
||||
{
|
||||
onlp_led_info_t info;
|
||||
ONLP_LED_PRESENT_OR_RETURN(id, &info);
|
||||
if(info.caps & ONLP_LED_CAPS_ON_OFF) {
|
||||
return onlp_ledi_set(id, on_or_off);
|
||||
}
|
||||
else {
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
ONLP_OID_LED_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(info);
|
||||
return onlp_log_error(0x0,
|
||||
onlp_ledi_info_get(oid, info),
|
||||
"ledi info get %{onlp_oid}", oid);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_led_set, onlp_oid_t, id, int, on_or_off);
|
||||
ONLP_LOCKED_API2(onlp_led_info_get, onlp_oid_t, id, onlp_led_info_t*, info);
|
||||
|
||||
|
||||
static int
|
||||
onlp_led_mode_set_locked__(onlp_oid_t id, onlp_led_mode_t mode)
|
||||
@@ -174,82 +145,82 @@ ONLP_LOCKED_API2(onlp_led_char_set, onlp_oid_t, id, char, c);
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
void
|
||||
onlp_led_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
int
|
||||
onlp_led_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_led_info_t info;
|
||||
|
||||
VALIDATENR(id);
|
||||
onlp_oid_dump_iof_init_default(&iof, pvs);
|
||||
iof_push(&iof, "led @ %d", ONLP_OID_ID_GET(id));
|
||||
rv = onlp_led_info_get(id, &info);
|
||||
if(rv < 0) {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
ONLP_OID_LED_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE(pvs);
|
||||
|
||||
if(ONLP_SUCCESS(rv = onlp_led_info_get(oid, &info))) {
|
||||
rv = onlp_led_info_format(&info, format, pvs, flags);
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_description(&iof, &info.hdr);
|
||||
if(info.status & 1) {
|
||||
/* Present */
|
||||
iof_iprintf(&iof, "Status: %{onlp_led_status_flags}", info.status);
|
||||
iof_iprintf(&iof, "Caps: %{onlp_led_caps_flags}", info.caps);
|
||||
iof_iprintf(&iof, "Mode: %{onlp_led_mode}", info.mode);
|
||||
iof_iprintf(&iof, "Char: %c", info.character);
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Not present.");
|
||||
}
|
||||
}
|
||||
iof_pop(&iof);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
onlp_led_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
int
|
||||
onlp_led_info_format(onlp_led_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_led_info_t info;
|
||||
int yaml;
|
||||
|
||||
VALIDATENR(id);
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, " -");
|
||||
iof_iprintf(&iof, "Name: LED %d", ONLP_OID_ID_GET(id));
|
||||
}
|
||||
else {
|
||||
iof_push(&iof, "LED %d", ONLP_OID_ID_GET(id));
|
||||
}
|
||||
|
||||
rv = onlp_led_info_get(id, &info);
|
||||
if(rv < 0) {
|
||||
if(yaml) {
|
||||
iof_iprintf(&iof, "State: Error");
|
||||
iof_iprintf(&iof, "Error: %{onlp_status}", rv);
|
||||
}
|
||||
else {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
}
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_description(&iof, &info.hdr);
|
||||
if(info.status & 1) {
|
||||
/* Present */
|
||||
iof_iprintf(&iof, "State: Present");
|
||||
iof_iprintf(&iof, "Mode: %{onlp_led_mode}", info.mode);
|
||||
if(info.caps & ONLP_LED_CAPS_CHAR) {
|
||||
iof_iprintf(&iof, "Char: %c", info.character);
|
||||
}
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_state_missing(&iof);
|
||||
}
|
||||
}
|
||||
iof_pop(&iof);
|
||||
|
||||
aim_printf(pvs, "%{onlp_oid_hdr} caps=%{onlp_led_caps_flags} mode=%{onlp_led_mode}\n",
|
||||
info, info->caps, info->mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_led_info_to_user_json(onlp_led_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
|
||||
int rv;
|
||||
cJSON* cj;
|
||||
rv = onlp_info_to_user_json_create(&info->hdr, &cj, flags);
|
||||
if(rv > 0) {
|
||||
cjson_util_add_string_to_object(cj, "Mode", "%{onlp_led_mode}", info->mode);
|
||||
if(info->mode == ONLP_LED_MODE_CHAR) {
|
||||
cjson_util_add_string_to_object(cj, "Character", "%c", info->character);
|
||||
}
|
||||
}
|
||||
return onlp_info_to_user_json_finish(&info->hdr, cj, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_led_info_to_json(onlp_led_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
cJSON* cj;
|
||||
|
||||
ONLP_IF_ERROR_RETURN(onlp_info_to_json_create(&info->hdr, &cj, flags));
|
||||
cJSON_AddItemToObject(cj, "caps", cjson_util_flag_array(info->caps,
|
||||
onlp_led_caps_map));
|
||||
cjson_util_add_string_to_object(cj, "mode",
|
||||
"%{onlp_led_mode}", info->mode);
|
||||
|
||||
if(info->mode == ONLP_LED_MODE_CHAR) {
|
||||
cjson_util_add_string_to_object(cj, "character", "%c", info->character);
|
||||
}
|
||||
|
||||
return onlp_info_to_json_finish(&info->hdr, cj, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_led_info_from_json(cJSON* cj, onlp_led_info_t* info)
|
||||
{
|
||||
cJSON* j;
|
||||
ONLP_IF_ERROR_RETURN(onlp_oid_hdr_from_json(cj, &info->hdr));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup(cj, &j, "caps"));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_array_to_flags(j, &info->caps,
|
||||
onlp_led_caps_map));
|
||||
char* s;
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_string(cj, &s, "mode"));
|
||||
ONLP_IF_ERROR_RETURN(onlp_led_mode_value(s, &info->mode, 1));
|
||||
|
||||
if(info->mode == ONLP_LED_MODE_CHAR) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_string(cj, &s, "character"));
|
||||
info->character = s[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
############################################################
|
||||
# <bsn.cl fy=2014 v=onl>
|
||||
#
|
||||
# Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
#
|
||||
#
|
||||
# Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
#
|
||||
# Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
# either express or implied. See the License for the specific
|
||||
# language governing permissions and limitations under the
|
||||
# License.
|
||||
#
|
||||
#
|
||||
# </bsn.cl>
|
||||
############################################################
|
||||
#
|
||||
@@ -25,3 +25,6 @@
|
||||
LIBRARY := onlp
|
||||
$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
include $(BUILDER)/lib.mk
|
||||
|
||||
$(onlp_SUBDIR)onlp_ucli.c: FORCE
|
||||
@$(UCLIHANDLERS2) $@
|
||||
|
||||
62
packages/base/any/onlp/src/onlp/module/src/module.c
Normal file
62
packages/base/any/onlp/src/onlp/module/src/module.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <onlp/module.h>
|
||||
|
||||
int
|
||||
onlp_module_sw_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_hw_init(uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_sw_denit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_info_get(onlp_oid_t id, onlp_module_info_t* info)
|
||||
{
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_format(onlp_oid_t id, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_info_format(onlp_module_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_info_to_user_json(onlp_module_info_t* info, cJSON** rv, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
onlp_module_info_to_json(onlp_module_info_t* info, cJSON** rv, uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_module_info_from_json(cJSON* cj, onlp_module_info_t* info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -29,177 +29,158 @@
|
||||
#include <AIM/aim.h>
|
||||
#include <AIM/aim_printf.h>
|
||||
|
||||
#include <onlp/chassis.h>
|
||||
#include <onlp/module.h>
|
||||
#include <onlp/thermal.h>
|
||||
#include <onlp/fan.h>
|
||||
#include <onlp/led.h>
|
||||
#include <onlp/psu.h>
|
||||
#include <onlp/sys.h>
|
||||
#include <onlp/sfp.h>
|
||||
#include <onlp/generic.h>
|
||||
|
||||
#define OID_TYPE_SHOWDUMP_DEFINE(_TYPE, _type) \
|
||||
static void \
|
||||
oid_type_##_TYPE##_dump__(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags) \
|
||||
{ \
|
||||
onlp_##_type##_dump(oid, pvs, flags); \
|
||||
} \
|
||||
static void \
|
||||
oid_type_##_TYPE##_show__(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags) \
|
||||
{ \
|
||||
onlp_##_type##_show(oid, pvs, flags); \
|
||||
}
|
||||
#include <cjson_util/cjson_util_format.h>
|
||||
|
||||
#define OID_TYPE_SHOWDUMP_DEFINE_EMPTY(_TYPE, _type) \
|
||||
static void \
|
||||
oid_type_##_TYPE##_dump__(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags) \
|
||||
{ \
|
||||
} \
|
||||
static void \
|
||||
oid_type_##_TYPE##_show__(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags) \
|
||||
{ \
|
||||
}
|
||||
|
||||
|
||||
OID_TYPE_SHOWDUMP_DEFINE(SYS, sys);
|
||||
OID_TYPE_SHOWDUMP_DEFINE(THERMAL, thermal);
|
||||
OID_TYPE_SHOWDUMP_DEFINE(FAN, fan);
|
||||
OID_TYPE_SHOWDUMP_DEFINE(PSU, psu);
|
||||
OID_TYPE_SHOWDUMP_DEFINE(LED, led);
|
||||
OID_TYPE_SHOWDUMP_DEFINE_EMPTY(MODULE, module);
|
||||
OID_TYPE_SHOWDUMP_DEFINE_EMPTY(RTC, rtc);
|
||||
|
||||
static void
|
||||
oid_type_unknown_dump__(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
iof_t iof;
|
||||
onlp_oid_dump_iof_init_default(&iof, pvs);
|
||||
iof_push(&iof, "invalid oid @ 0x%x", oid);
|
||||
iof_iprintf(&iof, "type = %d", ONLP_OID_TYPE_GET(oid));
|
||||
iof_iprintf(&iof, " id = %d", ONLP_OID_ID_GET(oid));
|
||||
iof_pop(&iof);
|
||||
}
|
||||
|
||||
static int
|
||||
oid_type_SYS_hdr_get__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
return onlp_sys_hdr_get(hdr);
|
||||
}
|
||||
|
||||
static int
|
||||
oid_type_THERMAL_hdr_get__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
return onlp_thermal_hdr_get(oid, hdr);
|
||||
}
|
||||
|
||||
static int
|
||||
oid_type_FAN_hdr_get__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
return onlp_fan_hdr_get(oid, hdr);
|
||||
}
|
||||
|
||||
static int
|
||||
oid_type_LED_hdr_get__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
return onlp_led_hdr_get(oid, hdr);
|
||||
}
|
||||
|
||||
static int
|
||||
oid_type_PSU_hdr_get__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
return onlp_psu_hdr_get(oid, hdr);
|
||||
}
|
||||
|
||||
static int
|
||||
oid_type_RTC_hdr_get__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
/* Not implemented yet */
|
||||
AIM_LOG_MSG("RTC_coids_get: 0x%x", oid);
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
oid_type_MODULE_hdr_get__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
/* Not implemented yet */
|
||||
AIM_LOG_MSG("MODULE_coids_get: 0x%x", oid);
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
}
|
||||
|
||||
static void
|
||||
onlp_oid_showdump__(onlp_oid_t oid,
|
||||
/* show=1, dump=0 */
|
||||
int show,
|
||||
aim_pvs_t* pvs,
|
||||
uint32_t flags)
|
||||
{
|
||||
if(oid == 0) {
|
||||
oid = ONLP_OID_SYS;
|
||||
}
|
||||
|
||||
switch(ONLP_OID_TYPE_GET(oid)) {
|
||||
/* {dump || show} */
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
if(show) { \
|
||||
oid_type_##_name##_show__(oid, pvs, flags); \
|
||||
} \
|
||||
else { \
|
||||
oid_type_##_name##_dump__(oid, pvs, flags); \
|
||||
} \
|
||||
return;
|
||||
|
||||
#include <onlp/onlp.x>
|
||||
|
||||
/* Intentional compile time error if an OID decode is missing. */
|
||||
}
|
||||
oid_type_unknown_dump__(oid, pvs, flags);
|
||||
}
|
||||
|
||||
void
|
||||
onlp_oid_dump(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
onlp_oid_showdump__(oid, 0, pvs, flags);
|
||||
}
|
||||
|
||||
void
|
||||
onlp_oid_table_dump(onlp_oid_table_t table, aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
onlp_oid_t* oidp;
|
||||
ONLP_OID_TABLE_ITER(table, oidp) {
|
||||
onlp_oid_dump(*oidp, pvs, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
onlp_oid_show(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
onlp_oid_showdump__(oid, 1, pvs, flags);
|
||||
}
|
||||
|
||||
void
|
||||
onlp_oid_table_show(onlp_oid_table_t table, aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
onlp_oid_t* oidp;
|
||||
ONLP_OID_TABLE_ITER(table, oidp) {
|
||||
onlp_oid_show(*oidp, pvs, flags);
|
||||
}
|
||||
}
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
int
|
||||
onlp_oid_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value) \
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
return oid_type_##_name##_hdr_get__(oid, hdr);
|
||||
return onlp_##_lower##_hdr_get(oid, hdr);
|
||||
|
||||
#include <onlp/onlp.x>
|
||||
/* Intentional compile time error if an OID handler is missing. */
|
||||
}
|
||||
return ONLP_STATUS_E_INVALID;
|
||||
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_iterate(onlp_oid_t oid, onlp_oid_type_t type,
|
||||
onlp_oid_info_get(onlp_oid_t oid, onlp_oid_hdr_t** info)
|
||||
{
|
||||
int rv;
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
{ \
|
||||
onlp_##_lower##_info_t* ip = aim_zmalloc(sizeof(*ip)); \
|
||||
if(ONLP_SUCCESS(rv = onlp_##_lower##_info_get(oid, (onlp_##_lower##_info_t*)ip))) { \
|
||||
*info = (onlp_oid_hdr_t*)ip; \
|
||||
} \
|
||||
else { \
|
||||
aim_free(ip); \
|
||||
} \
|
||||
return rv; \
|
||||
}
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
return onlp_##_lower##_format(oid, format, pvs, flags);
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_info_format(onlp_oid_hdr_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(info->id))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
return onlp_##_lower##_info_format((onlp_##_lower##_info_t*)info, \
|
||||
format, pvs, flags);
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_info_to_json(onlp_oid_hdr_t* info, cJSON** cj, uint32_t flags)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(info->id))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
return onlp_##_lower##_info_to_json((onlp_##_lower##_info_t*)info, cj, flags);
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_to_user_json(onlp_oid_t oid, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
{ \
|
||||
int rv; \
|
||||
onlp_##_lower##_info_t info; \
|
||||
if(ONLP_SUCCESS(rv = onlp_##_lower##_info_get(oid, &info))) { \
|
||||
return onlp_##_lower##_info_to_user_json(&info, cjp, flags); \
|
||||
} \
|
||||
return rv; \
|
||||
}
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_to_json(onlp_oid_t oid, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
{ \
|
||||
int rv; \
|
||||
onlp_##_lower##_info_t info; \
|
||||
if(ONLP_SUCCESS(rv = onlp_##_lower##_info_get(oid, &info))) { \
|
||||
return onlp_##_lower##_info_to_json(&info, cjp, flags); \
|
||||
} \
|
||||
return rv; \
|
||||
}
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_oid_table_format(onlp_oid_table_t table, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
onlp_oid_t* oidp;
|
||||
ONLP_OID_TABLE_ITER(table, oidp) {
|
||||
onlp_oid_format(*oidp, format, pvs, flags);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_iterate(onlp_oid_t oid, onlp_oid_type_flags_t types,
|
||||
onlp_oid_iterate_f itf, void* cookie)
|
||||
{
|
||||
int rv;
|
||||
@@ -207,7 +188,7 @@ onlp_oid_iterate(onlp_oid_t oid, onlp_oid_type_t type,
|
||||
onlp_oid_t* oidp;
|
||||
|
||||
if(oid == 0) {
|
||||
oid = ONLP_OID_SYS;
|
||||
oid = ONLP_OID_CHASSIS;
|
||||
}
|
||||
|
||||
rv = onlp_oid_hdr_get(oid, &hdr);
|
||||
@@ -215,17 +196,502 @@ onlp_oid_iterate(onlp_oid_t oid, onlp_oid_type_t type,
|
||||
return rv;
|
||||
}
|
||||
|
||||
/** Iterate over all top level ids */
|
||||
ONLP_OID_TABLE_ITER(hdr.coids, oidp) {
|
||||
if(type == 0 || ONLP_OID_IS_TYPE(type, *oidp)) {
|
||||
if(ONLP_OID_IS_TYPE_FLAGSZ(types, *oidp)) {
|
||||
int rv = itf(*oidp, cookie);
|
||||
if(rv < 0) {
|
||||
return rv;
|
||||
}
|
||||
rv = onlp_oid_iterate(*oidp, type, itf, cookie);
|
||||
if(rv < 0) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
ONLP_OID_TABLE_ITER(hdr.coids, oidp) {
|
||||
rv = onlp_oid_iterate(*oidp, types, itf, cookie);
|
||||
if(rv < 0) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
typedef struct onlp_oid_get_all_ctrl_s {
|
||||
biglist_t* list;
|
||||
uint32_t flags;
|
||||
int rv;
|
||||
} onlp_oid_get_all_ctrl_t;
|
||||
|
||||
static int
|
||||
onlp_oid_info_get_all_iterate__(onlp_oid_t oid, void* cookie)
|
||||
{
|
||||
int rv;
|
||||
onlp_oid_get_all_ctrl_t* ctrl = (onlp_oid_get_all_ctrl_t*)cookie;
|
||||
onlp_oid_hdr_t* obj;
|
||||
|
||||
if(ONLP_SUCCESS(rv = onlp_oid_info_get(oid, &obj))) {
|
||||
ctrl->list = biglist_append(ctrl->list, obj);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
ctrl->rv = rv;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_info_get_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t flags, biglist_t** list)
|
||||
{
|
||||
onlp_oid_get_all_ctrl_t ctrl;
|
||||
|
||||
ctrl.list = NULL;
|
||||
ctrl.flags = flags;
|
||||
ctrl.rv = 0;
|
||||
|
||||
onlp_oid_iterate(root, types, onlp_oid_info_get_all_iterate__,
|
||||
&ctrl);
|
||||
if(ONLP_SUCCESS(ctrl.rv)) {
|
||||
*list = ctrl.list;
|
||||
}
|
||||
else {
|
||||
onlp_oid_get_all_free(ctrl.list);
|
||||
}
|
||||
|
||||
return ctrl.rv;
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_oid_hdr_get_all_iterate__(onlp_oid_t oid, void* cookie)
|
||||
{
|
||||
int rv;
|
||||
onlp_oid_get_all_ctrl_t* ctrl = (onlp_oid_get_all_ctrl_t*)cookie;
|
||||
onlp_oid_hdr_t* obj = aim_zmalloc(sizeof(*obj));
|
||||
if(ONLP_SUCCESS(rv = onlp_oid_hdr_get(oid, obj))) {
|
||||
ctrl->list = biglist_append(ctrl->list, obj);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
ctrl->rv = rv;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_oid_hdr_get_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t flags, biglist_t** list)
|
||||
{
|
||||
onlp_oid_get_all_ctrl_t ctrl;
|
||||
|
||||
ctrl.list = NULL;
|
||||
ctrl.flags = flags;
|
||||
ctrl.rv = 0;
|
||||
|
||||
onlp_oid_iterate(root, types, onlp_oid_hdr_get_all_iterate__,
|
||||
&ctrl);
|
||||
if(ONLP_SUCCESS(ctrl.rv)) {
|
||||
*list = ctrl.list;
|
||||
}
|
||||
else {
|
||||
onlp_oid_get_all_free(ctrl.list);
|
||||
}
|
||||
|
||||
return ctrl.rv;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_get_all_free(biglist_t* list)
|
||||
{
|
||||
biglist_free_all(list, aim_free);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_info_format_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t get_flags,
|
||||
onlp_oid_format_t format, aim_pvs_t* pvs,
|
||||
uint32_t format_flags)
|
||||
{
|
||||
int rv;
|
||||
biglist_t* list;
|
||||
if(ONLP_SUCCESS(onlp_oid_info_get_all(root, types, get_flags, &list))) {
|
||||
biglist_t* ble;
|
||||
onlp_oid_hdr_t* hdr;
|
||||
BIGLIST_FOREACH_DATA(ble, list, onlp_oid_hdr_t*, hdr) {
|
||||
if(ONLP_FAILURE(rv = onlp_oid_info_format(hdr, ONLP_OID_TYPE_GET(hdr->id), pvs, format_flags))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
onlp_oid_get_all_free(list);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_oid_hdr_format_all(onlp_oid_t root, onlp_oid_type_flags_t types,
|
||||
uint32_t get_flags,
|
||||
onlp_oid_format_t format, aim_pvs_t* pvs,
|
||||
uint32_t format_flags)
|
||||
{
|
||||
biglist_t* list;
|
||||
if(ONLP_SUCCESS(onlp_oid_hdr_get_all(root, types, get_flags, &list))) {
|
||||
biglist_t* ble;
|
||||
onlp_oid_hdr_t* hdr;
|
||||
BIGLIST_FOREACH_DATA(ble, list, onlp_oid_hdr_t*, hdr) {
|
||||
aim_printf(pvs, "%{onlp_oid_hdr}\n", hdr);
|
||||
}
|
||||
onlp_oid_get_all_free(list);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_to_str(onlp_oid_t oid, char* rstr)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_upper, _id, _desc, _lower) \
|
||||
case _id: \
|
||||
{ \
|
||||
sprintf(rstr, "%s-%d", #_lower, ONLP_OID_ID_GET(oid)); \
|
||||
return ONLP_STATUS_OK; \
|
||||
}
|
||||
#include <onlp/onlp.x>
|
||||
|
||||
default:
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_to_user_str(onlp_oid_t oid, char* rstr)
|
||||
{
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _id, _upper, _lower) \
|
||||
case _id: \
|
||||
{ \
|
||||
if(_id == ONLP_OID_TYPE_PSU) { \
|
||||
sprintf(rstr, "%s %d", #_upper, ONLP_OID_ID_GET(oid)); \
|
||||
} \
|
||||
else{ \
|
||||
sprintf(rstr, "%s %d", #_lower, ONLP_OID_ID_GET(oid)); \
|
||||
rstr[0] = toupper(rstr[0]); \
|
||||
} \
|
||||
return ONLP_STATUS_OK; \
|
||||
}
|
||||
#include <onlp/onlp.x>
|
||||
default:
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_oid_from_str(char* str, onlp_oid_t* oid)
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_upper, _tid, _desc, _lower) \
|
||||
do { \
|
||||
int id; \
|
||||
if((sscanf(str, #_lower "-%d", &id) == 1) || \
|
||||
(sscanf(str, #_upper "-%d", &id) == 1)) { \
|
||||
*oid = ONLP_OID_TYPE_CREATE(_tid, id); \
|
||||
return ONLP_STATUS_OK; \
|
||||
} \
|
||||
} while(0);
|
||||
#include <onlp/onlp.x>
|
||||
ONLP_LOG_JSON("%s : could not convert 'str' to an oid.",
|
||||
__FUNCTION__, str);
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_table_to_json(onlp_oid_table_t table, cJSON** cjp)
|
||||
{
|
||||
int rv;
|
||||
cJSON* cj = cJSON_CreateArray();
|
||||
onlp_oid_t* oidp;
|
||||
ONLP_OID_TABLE_ITER(table, oidp) {
|
||||
char str[32];
|
||||
if(ONLP_FAILURE(rv = onlp_oid_to_str(*oidp, str))) {
|
||||
cJSON_Delete(cj);
|
||||
return rv;
|
||||
}
|
||||
cJSON_AddItemToArray(cj, cJSON_CreateString(str));
|
||||
}
|
||||
*cjp = cj;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_table_from_json(cJSON* cj, onlp_oid_table_t table)
|
||||
{
|
||||
int i, rv;
|
||||
|
||||
int s = cJSON_GetArraySize(cj);
|
||||
if(s < 0 || s > ONLP_OID_TABLE_SIZE) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
for(i = 0; i < ONLP_OID_TABLE_SIZE; i++) {
|
||||
cJSON* item = cJSON_GetArrayItem(cj, i);
|
||||
if(!item) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(item->type != cJSON_String) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_oid_from_str(item->valuestring, table+i))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_hdr_to_json(onlp_oid_hdr_t* hdr, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
char str[32];
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_oid_to_str(hdr->id, str))) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
cJSON* cj = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(cj, "id", str);
|
||||
|
||||
if(hdr->description[0]) {
|
||||
cJSON_AddStringToObject(cj, "description", hdr->description);
|
||||
}
|
||||
else {
|
||||
cJSON_AddNullToObject(cj, "description");
|
||||
}
|
||||
if(hdr->poid) {
|
||||
if(ONLP_FAILURE(rv = onlp_oid_to_str(hdr->poid, str))) {
|
||||
goto error;
|
||||
}
|
||||
cJSON_AddStringToObject(cj, "poid", str);
|
||||
}
|
||||
else {
|
||||
cJSON_AddNullToObject(cj, "poid");
|
||||
}
|
||||
|
||||
cJSON* coids = NULL;
|
||||
if(ONLP_FAILURE(rv = onlp_oid_table_to_json(hdr->coids, &coids))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(cj, "coids", coids);
|
||||
cJSON* status = cjson_util_flag_array(hdr->status, onlp_oid_status_flag_map);
|
||||
cJSON_AddItemToObject(cj, "status", status);
|
||||
|
||||
*cjp = cj;
|
||||
return ONLP_STATUS_OK;
|
||||
|
||||
error:
|
||||
cJSON_Delete(cj);
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_hdr_from_json(cJSON* cj, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
int rv;
|
||||
char* str;
|
||||
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
|
||||
cJSON* jhdr = NULL;
|
||||
if(ONLP_SUCCESS(cjson_util_lookup(cj, &jhdr, "hdr")) && jhdr) {
|
||||
cj = jhdr;
|
||||
}
|
||||
|
||||
if(cjson_util_lookup_string(cj, &str, "id") < 0) {
|
||||
ONLP_LOG_JSON("%s: 'id' entry not found.", __FUNCTION__);
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
if(ONLP_FAILURE(rv = onlp_oid_from_str(str, &hdr->id))) {
|
||||
ONLP_LOG_JSON("%s: onlp_oid_from_str failed: %{onlp_status}",
|
||||
__FUNCTION__, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if(ONLP_SUCCESS(cjson_util_lookup_string(cj, &str, "description"))) {
|
||||
aim_strlcpy(hdr->description, str, sizeof(hdr->description));
|
||||
}
|
||||
|
||||
if(ONLP_SUCCESS(cjson_util_lookup_string(cj, &str, "poid"))) {
|
||||
if(ONLP_FAILURE(rv = onlp_oid_from_str(str, &hdr->poid))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
cJSON* coids = cJSON_GetObjectItem(cj, "coids");
|
||||
if(coids) {
|
||||
if(ONLP_FAILURE(rv = onlp_oid_table_from_json(coids, hdr->coids))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
cJSON* status = cJSON_GetObjectItem(cj, "status");
|
||||
if(status) {
|
||||
if(ONLP_FAILURE(rv = cjson_util_array_to_flags(status,
|
||||
&hdr->status,
|
||||
onlp_oid_status_flag_map))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_from_json(cJSON* cj, onlp_oid_hdr_t** rhdr,
|
||||
biglist_t** all_oids_list, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
onlp_oid_hdr_t hdr;
|
||||
|
||||
if(cj == NULL) {
|
||||
ONLP_LOG_JSON("%s : JSON pointer is null.", __FUNCTION__);
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_JSON_FLAG_RECURSIVE) {
|
||||
if(all_oids_list == NULL) {
|
||||
ONLP_LOG_JSON("%s : recursive selected but the return list is null.",
|
||||
__FUNCTION__);
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(rhdr == NULL) {
|
||||
ONLP_LOG_JSON("%s : rhdr pointer is null.", __FUNCTION__);
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_oid_hdr_from_json(cj, &hdr))) {
|
||||
ONLP_LOG_JSON("%s: onlp_oid_hdr_from_json failed: %{onlp_status}",
|
||||
__FUNCTION__, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
switch(ONLP_OID_TYPE_GET(hdr.id))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
{ \
|
||||
onlp_##_lower##_info_t* pinfo = aim_zmalloc(sizeof(*pinfo)); \
|
||||
if(ONLP_FAILURE(rv = onlp_##_lower##_info_from_json(cj, pinfo))) { \
|
||||
ONLP_LOG_JSON("%s: onlp_%s_info_from_json failed: %{onlp_status}", \
|
||||
__FUNCTION__, #_lower, rv); \
|
||||
aim_free(pinfo); \
|
||||
return rv; \
|
||||
} \
|
||||
if(flags & ONLP_OID_JSON_FLAG_RECURSIVE) { \
|
||||
cJSON* children; \
|
||||
if(ONLP_SUCCESS(cjson_util_lookup(cj, &children, "coids"))) { \
|
||||
int i; \
|
||||
for(i = 0; i < cJSON_GetArraySize(children); i++) { \
|
||||
cJSON* child = cJSON_GetArrayItem(children, i); \
|
||||
rv = onlp_oid_from_json(child, NULL, all_oids_list, flags); \
|
||||
if(ONLP_FAILURE(rv)) { \
|
||||
aim_free(pinfo); \
|
||||
return rv; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
if(rhdr) { \
|
||||
*rhdr = (onlp_oid_hdr_t*)pinfo; \
|
||||
} \
|
||||
if(all_oids_list) { \
|
||||
*all_oids_list = biglist_prepend(*all_oids_list, pinfo); \
|
||||
} \
|
||||
return 0; \
|
||||
}
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_oid_json_verify(onlp_oid_t oid)
|
||||
{
|
||||
int rv;
|
||||
cJSON* cj;
|
||||
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
{
|
||||
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
{ \
|
||||
onlp_##_lower##_info_t info1, info2; \
|
||||
memset(&info1, 0, sizeof(info1)); \
|
||||
memset(&info2, 0, sizeof(info2)); \
|
||||
if(ONLP_FAILURE(rv = onlp_##_lower##_info_get(oid, &info1))) { \
|
||||
AIM_LOG_ERROR("onlp_%s_info_get)(%{onlp_oid}) failed: %{onlp_status}", \
|
||||
#_lower, oid, rv); \
|
||||
return rv; \
|
||||
} \
|
||||
if(ONLP_FAILURE(rv = onlp_##_lower##_info_to_json(&info1, &cj, 0))) { \
|
||||
AIM_LOG_ERROR("onlp_%s_info_to_json(%{onlp_oid}) failed: %{onlp_status}", \
|
||||
#_lower, oid); \
|
||||
return rv; \
|
||||
} \
|
||||
if(ONLP_FAILURE(rv = onlp_##_lower##_info_from_json(cj, &info2))) { \
|
||||
AIM_LOG_ERROR("onlp_%s_info_from_json(%{onlp_oid}) failed: %{onlp_status}", \
|
||||
#_lower, oid, rv); \
|
||||
return rv; \
|
||||
} \
|
||||
if(memcmp(&info1, &info2, sizeof(info1))) { \
|
||||
AIM_LOG_ERROR("info1/info2 mismatch for %{onlp_oid}", \
|
||||
oid); \
|
||||
cJSON* cj2; \
|
||||
onlp_##_lower##_info_to_json(&info2, &cj2, 0); \
|
||||
AIM_LOG_ERROR("cj1: %s", cJSON_Print(cj)); \
|
||||
AIM_LOG_ERROR("cj2: %s", cJSON_Print(cj2)); \
|
||||
return -1; \
|
||||
} \
|
||||
return 0; \
|
||||
}
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int oid_compare__(const void* a, const void* b)
|
||||
{
|
||||
onlp_oid_t A = *((onlp_oid_t*) a);
|
||||
onlp_oid_t B = *((onlp_oid_t*) b);
|
||||
|
||||
if(A == 0) A = UINT_MAX;
|
||||
if(B == 0) B = UINT_MAX;
|
||||
|
||||
if(A < B) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(A > B) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
onlp_oid_hdr_sort(onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
qsort(hdr->coids, sizeof(onlp_oid_t), AIM_ARRAYSIZE(hdr->coids),
|
||||
oid_compare__);
|
||||
}
|
||||
|
||||
/* Local variables: */
|
||||
/* c-file-style: "cc-mode" */
|
||||
/* End: */
|
||||
|
||||
@@ -25,11 +25,15 @@
|
||||
#include <onlp/onlp_config.h>
|
||||
#include <onlp/onlp.h>
|
||||
|
||||
#include <onlp/sys.h>
|
||||
#include <onlp/sfp.h>
|
||||
#include <onlp/led.h>
|
||||
#include <onlp/psu.h>
|
||||
#include <onlp/platform.h>
|
||||
|
||||
#include <onlp/chassis.h>
|
||||
#include <onlp/fan.h>
|
||||
#include <onlp/generic.h>
|
||||
#include <onlp/led.h>
|
||||
#include <onlp/module.h>
|
||||
#include <onlp/psu.h>
|
||||
#include <onlp/sfp.h>
|
||||
#include <onlp/thermal.h>
|
||||
|
||||
#include "onlp_int.h"
|
||||
@@ -37,40 +41,44 @@
|
||||
#include "onlp_locks.h"
|
||||
|
||||
int
|
||||
onlp_init(void)
|
||||
onlp_sw_init(const char* platform)
|
||||
{
|
||||
extern void __onlp_module_init__(void);
|
||||
__onlp_module_init__();
|
||||
|
||||
char* cfile;
|
||||
|
||||
if( (cfile=getenv(ONLP_CONFIG_CONFIGURATION_ENV)) == NULL) {
|
||||
cfile = ONLP_CONFIG_CONFIGURATION_FILENAME;
|
||||
}
|
||||
|
||||
#if ONLP_CONFIG_INCLUDE_API_LOCK == 1
|
||||
onlp_api_lock_init();
|
||||
#endif
|
||||
|
||||
ONLP_TRY(onlp_platform_sw_init(platform));
|
||||
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _id, _upper, _lower) \
|
||||
ONLP_TRY(onlp_##_lower##_sw_init());
|
||||
#include <onlp/onlp.x>
|
||||
|
||||
onlp_json_init(cfile);
|
||||
onlp_sys_init();
|
||||
onlp_sfp_init();
|
||||
onlp_led_init();
|
||||
onlp_psu_init();
|
||||
onlp_fan_init();
|
||||
onlp_thermal_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_denit(void)
|
||||
onlp_hw_init(uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sw_denit(void)
|
||||
{
|
||||
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _id, _upper, _lower) \
|
||||
ONLP_TRY(onlp_##_lower##_sw_denit());
|
||||
#include <onlp/onlp.x>
|
||||
|
||||
ONLP_TRY(onlp_platform_sw_denit());
|
||||
|
||||
#if ONLP_CONFIG_INCLUDE_API_LOCK == 1
|
||||
onlp_api_lock_denit();
|
||||
#endif
|
||||
|
||||
onlp_json_denit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -75,15 +75,10 @@ onlp_config_settings_t onlp_config_settings[] =
|
||||
#else
|
||||
{ ONLP_CONFIG_INCLUDE_SHLOCK_GLOBAL_INIT(__onlp_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef ONLP_CONFIG_INCLUDE_PLATFORM_STATIC
|
||||
{ __onlp_config_STRINGIFY_NAME(ONLP_CONFIG_INCLUDE_PLATFORM_STATIC), __onlp_config_STRINGIFY_VALUE(ONLP_CONFIG_INCLUDE_PLATFORM_STATIC) },
|
||||
#ifdef ONLP_CONFIG_PLATFORM_NAME
|
||||
{ __onlp_config_STRINGIFY_NAME(ONLP_CONFIG_PLATFORM_NAME), __onlp_config_STRINGIFY_VALUE(ONLP_CONFIG_PLATFORM_NAME) },
|
||||
#else
|
||||
{ ONLP_CONFIG_INCLUDE_PLATFORM_STATIC(__onlp_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef ONLP_CONFIG_PLATFORM_STATIC
|
||||
{ __onlp_config_STRINGIFY_NAME(ONLP_CONFIG_PLATFORM_STATIC), __onlp_config_STRINGIFY_VALUE(ONLP_CONFIG_PLATFORM_STATIC) },
|
||||
#else
|
||||
{ ONLP_CONFIG_PLATFORM_STATIC(__onlp_config_STRINGIFY_NAME), "__undefined__" },
|
||||
{ ONLP_CONFIG_PLATFORM_NAME(__onlp_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef ONLP_CONFIG_PLATFORM_FILENAME
|
||||
{ __onlp_config_STRINGIFY_NAME(ONLP_CONFIG_PLATFORM_FILENAME), __onlp_config_STRINGIFY_VALUE(ONLP_CONFIG_PLATFORM_FILENAME) },
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -32,11 +32,13 @@
|
||||
#include <onlp/psu.h>
|
||||
#include <onlp/led.h>
|
||||
|
||||
#include "onlp_log.h"
|
||||
|
||||
/* <auto.start.enum(ALL).source> */
|
||||
aim_map_si_t onlp_fan_caps_map[] =
|
||||
{
|
||||
{ "B2F", ONLP_FAN_CAPS_B2F },
|
||||
{ "F2B", ONLP_FAN_CAPS_F2B },
|
||||
{ "SET_DIR", ONLP_FAN_CAPS_SET_DIR },
|
||||
{ "GET_DIR", ONLP_FAN_CAPS_GET_DIR },
|
||||
{ "SET_RPM", ONLP_FAN_CAPS_SET_RPM },
|
||||
{ "SET_PERCENTAGE", ONLP_FAN_CAPS_SET_PERCENTAGE },
|
||||
{ "GET_RPM", ONLP_FAN_CAPS_GET_RPM },
|
||||
@@ -46,8 +48,8 @@ aim_map_si_t onlp_fan_caps_map[] =
|
||||
|
||||
aim_map_si_t onlp_fan_caps_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_FAN_CAPS_B2F },
|
||||
{ "None", ONLP_FAN_CAPS_F2B },
|
||||
{ "None", ONLP_FAN_CAPS_SET_DIR },
|
||||
{ "None", ONLP_FAN_CAPS_GET_DIR },
|
||||
{ "None", ONLP_FAN_CAPS_SET_RPM },
|
||||
{ "None", ONLP_FAN_CAPS_SET_PERCENTAGE },
|
||||
{ "None", ONLP_FAN_CAPS_GET_RPM },
|
||||
@@ -103,6 +105,7 @@ onlp_fan_caps_valid(onlp_fan_caps_t e)
|
||||
|
||||
aim_map_si_t onlp_fan_dir_map[] =
|
||||
{
|
||||
{ "UNKNOWN", ONLP_FAN_DIR_UNKNOWN },
|
||||
{ "B2F", ONLP_FAN_DIR_B2F },
|
||||
{ "F2B", ONLP_FAN_DIR_F2B },
|
||||
{ NULL, 0 }
|
||||
@@ -110,6 +113,7 @@ aim_map_si_t onlp_fan_dir_map[] =
|
||||
|
||||
aim_map_si_t onlp_fan_dir_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_FAN_DIR_UNKNOWN },
|
||||
{ "None", ONLP_FAN_DIR_B2F },
|
||||
{ "None", ONLP_FAN_DIR_F2B },
|
||||
{ NULL, 0 }
|
||||
@@ -155,133 +159,11 @@ onlp_fan_dir_desc(onlp_fan_dir_t e)
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_fan_mode_map[] =
|
||||
{
|
||||
{ "OFF", ONLP_FAN_MODE_OFF },
|
||||
{ "SLOW", ONLP_FAN_MODE_SLOW },
|
||||
{ "NORMAL", ONLP_FAN_MODE_NORMAL },
|
||||
{ "FAST", ONLP_FAN_MODE_FAST },
|
||||
{ "MAX", ONLP_FAN_MODE_MAX },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_fan_mode_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_FAN_MODE_OFF },
|
||||
{ "None", ONLP_FAN_MODE_SLOW },
|
||||
{ "None", ONLP_FAN_MODE_NORMAL },
|
||||
{ "None", ONLP_FAN_MODE_FAST },
|
||||
{ "None", ONLP_FAN_MODE_MAX },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_fan_mode_name(onlp_fan_mode_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_fan_mode_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_fan_mode'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_fan_mode_value(const char* str, onlp_fan_mode_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_fan_mode_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_fan_mode_desc(onlp_fan_mode_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_fan_mode_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_fan_mode'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_fan_status_map[] =
|
||||
{
|
||||
{ "PRESENT", ONLP_FAN_STATUS_PRESENT },
|
||||
{ "FAILED", ONLP_FAN_STATUS_FAILED },
|
||||
{ "B2F", ONLP_FAN_STATUS_B2F },
|
||||
{ "F2B", ONLP_FAN_STATUS_F2B },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_fan_status_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_FAN_STATUS_PRESENT },
|
||||
{ "None", ONLP_FAN_STATUS_FAILED },
|
||||
{ "None", ONLP_FAN_STATUS_B2F },
|
||||
{ "None", ONLP_FAN_STATUS_F2B },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_fan_status_name(onlp_fan_status_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_fan_status_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_fan_status'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_fan_status_value(const char* str, onlp_fan_status_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_fan_status_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_fan_status_desc(onlp_fan_status_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_fan_status_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_fan_status'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_fan_status_valid(onlp_fan_status_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_fan_status_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_led_caps_map[] =
|
||||
{
|
||||
{ "ON_OFF", ONLP_LED_CAPS_ON_OFF },
|
||||
{ "OFF", ONLP_LED_CAPS_OFF },
|
||||
{ "AUTO", ONLP_LED_CAPS_AUTO },
|
||||
{ "AUTO_BLINKING", ONLP_LED_CAPS_AUTO_BLINKING },
|
||||
{ "CHAR", ONLP_LED_CAPS_CHAR },
|
||||
{ "RED", ONLP_LED_CAPS_RED },
|
||||
{ "RED_BLINKING", ONLP_LED_CAPS_RED_BLINKING },
|
||||
@@ -295,14 +177,14 @@ aim_map_si_t onlp_led_caps_map[] =
|
||||
{ "BLUE_BLINKING", ONLP_LED_CAPS_BLUE_BLINKING },
|
||||
{ "PURPLE", ONLP_LED_CAPS_PURPLE },
|
||||
{ "PURPLE_BLINKING", ONLP_LED_CAPS_PURPLE_BLINKING },
|
||||
{ "AUTO", ONLP_LED_CAPS_AUTO },
|
||||
{ "AUTO_BLINKING", ONLP_LED_CAPS_AUTO_BLINKING },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_led_caps_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_LED_CAPS_ON_OFF },
|
||||
{ "None", ONLP_LED_CAPS_OFF },
|
||||
{ "None", ONLP_LED_CAPS_AUTO },
|
||||
{ "None", ONLP_LED_CAPS_AUTO_BLINKING },
|
||||
{ "None", ONLP_LED_CAPS_CHAR },
|
||||
{ "None", ONLP_LED_CAPS_RED },
|
||||
{ "None", ONLP_LED_CAPS_RED_BLINKING },
|
||||
@@ -316,8 +198,6 @@ aim_map_si_t onlp_led_caps_desc_map[] =
|
||||
{ "None", ONLP_LED_CAPS_BLUE_BLINKING },
|
||||
{ "None", ONLP_LED_CAPS_PURPLE },
|
||||
{ "None", ONLP_LED_CAPS_PURPLE_BLINKING },
|
||||
{ "None", ONLP_LED_CAPS_AUTO },
|
||||
{ "None", ONLP_LED_CAPS_AUTO_BLINKING },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
@@ -370,8 +250,9 @@ onlp_led_caps_valid(onlp_led_caps_t e)
|
||||
aim_map_si_t onlp_led_mode_map[] =
|
||||
{
|
||||
{ "OFF", ONLP_LED_MODE_OFF },
|
||||
{ "ON", ONLP_LED_MODE_ON },
|
||||
{ "BLINKING", ONLP_LED_MODE_BLINKING },
|
||||
{ "AUTO", ONLP_LED_MODE_AUTO },
|
||||
{ "AUTO_BLINKING", ONLP_LED_MODE_AUTO_BLINKING },
|
||||
{ "CHAR", ONLP_LED_MODE_CHAR },
|
||||
{ "RED", ONLP_LED_MODE_RED },
|
||||
{ "RED_BLINKING", ONLP_LED_MODE_RED_BLINKING },
|
||||
{ "ORANGE", ONLP_LED_MODE_ORANGE },
|
||||
@@ -384,16 +265,15 @@ aim_map_si_t onlp_led_mode_map[] =
|
||||
{ "BLUE_BLINKING", ONLP_LED_MODE_BLUE_BLINKING },
|
||||
{ "PURPLE", ONLP_LED_MODE_PURPLE },
|
||||
{ "PURPLE_BLINKING", ONLP_LED_MODE_PURPLE_BLINKING },
|
||||
{ "AUTO", ONLP_LED_MODE_AUTO },
|
||||
{ "AUTO_BLINKING", ONLP_LED_MODE_AUTO_BLINKING },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_led_mode_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_LED_MODE_OFF },
|
||||
{ "None", ONLP_LED_MODE_ON },
|
||||
{ "None", ONLP_LED_MODE_BLINKING },
|
||||
{ "None", ONLP_LED_MODE_AUTO },
|
||||
{ "None", ONLP_LED_MODE_AUTO_BLINKING },
|
||||
{ "None", ONLP_LED_MODE_CHAR },
|
||||
{ "None", ONLP_LED_MODE_RED },
|
||||
{ "None", ONLP_LED_MODE_RED_BLINKING },
|
||||
{ "None", ONLP_LED_MODE_ORANGE },
|
||||
@@ -406,8 +286,6 @@ aim_map_si_t onlp_led_mode_desc_map[] =
|
||||
{ "None", ONLP_LED_MODE_BLUE_BLINKING },
|
||||
{ "None", ONLP_LED_MODE_PURPLE },
|
||||
{ "None", ONLP_LED_MODE_PURPLE_BLINKING },
|
||||
{ "None", ONLP_LED_MODE_AUTO },
|
||||
{ "None", ONLP_LED_MODE_AUTO_BLINKING },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
@@ -450,47 +328,37 @@ onlp_led_mode_desc(onlp_led_mode_t e)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_led_mode_valid(onlp_led_mode_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_led_mode_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_led_status_map[] =
|
||||
aim_map_si_t onlp_log_flag_map[] =
|
||||
{
|
||||
{ "PRESENT", ONLP_LED_STATUS_PRESENT },
|
||||
{ "FAILED", ONLP_LED_STATUS_FAILED },
|
||||
{ "ON", ONLP_LED_STATUS_ON },
|
||||
{ "JSON", ONLP_LOG_FLAG_JSON },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_led_status_desc_map[] =
|
||||
aim_map_si_t onlp_log_flag_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_LED_STATUS_PRESENT },
|
||||
{ "None", ONLP_LED_STATUS_FAILED },
|
||||
{ "None", ONLP_LED_STATUS_ON },
|
||||
{ "None", ONLP_LOG_FLAG_JSON },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_led_status_name(onlp_led_status_t e)
|
||||
onlp_log_flag_name(onlp_log_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_led_status_map, 0)) {
|
||||
if(aim_map_si_i(&name, e, onlp_log_flag_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_led_status'";
|
||||
return "-invalid value for enum type 'onlp_log_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_led_status_value(const char* str, onlp_led_status_t* e, int substr)
|
||||
onlp_log_flag_value(const char* str, onlp_log_flag_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_led_status_map, 0)) {
|
||||
if(aim_map_si_s(&i, str, onlp_log_flag_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
@@ -501,23 +369,17 @@ onlp_led_status_value(const char* str, onlp_led_status_t* e, int substr)
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_led_status_desc(onlp_led_status_t e)
|
||||
onlp_log_flag_desc(onlp_log_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_led_status_desc_map, 0)) {
|
||||
if(aim_map_si_i(&name, e, onlp_log_flag_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_led_status'";
|
||||
return "-invalid value for enum type 'onlp_log_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_led_status_valid(onlp_led_status_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_led_status_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_dump_map[] =
|
||||
{
|
||||
@@ -572,10 +434,182 @@ onlp_oid_dump_desc(onlp_oid_dump_t e)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_dump_valid(onlp_oid_dump_t e)
|
||||
|
||||
aim_map_si_t onlp_oid_format_map[] =
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_oid_dump_map, 0) ? 1 : 0;
|
||||
{ "JSON", ONLP_OID_FORMAT_JSON },
|
||||
{ "YAML", ONLP_OID_FORMAT_YAML },
|
||||
{ "USER", ONLP_OID_FORMAT_USER },
|
||||
{ "DEBUG", ONLP_OID_FORMAT_DEBUG },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_format_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_FORMAT_JSON },
|
||||
{ "None", ONLP_OID_FORMAT_YAML },
|
||||
{ "None", ONLP_OID_FORMAT_USER },
|
||||
{ "None", ONLP_OID_FORMAT_DEBUG },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_oid_format_name(onlp_oid_format_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_format_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_format'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_format_value(const char* str, onlp_oid_format_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_oid_format_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_oid_format_desc(onlp_oid_format_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_format_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_format'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_format_flags_map[] =
|
||||
{
|
||||
{ "RECURSIVE", ONLP_OID_FORMAT_FLAGS_RECURSIVE },
|
||||
{ "MISSING", ONLP_OID_FORMAT_FLAGS_MISSING },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_format_flags_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_FORMAT_FLAGS_RECURSIVE },
|
||||
{ "None", ONLP_OID_FORMAT_FLAGS_MISSING },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_oid_format_flags_name(onlp_oid_format_flags_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_format_flags_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_format_flags'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_format_flags_value(const char* str, onlp_oid_format_flags_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_oid_format_flags_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_oid_format_flags_desc(onlp_oid_format_flags_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_format_flags_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_format_flags'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_format_flags_valid(onlp_oid_format_flags_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_oid_format_flags_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_json_flag_map[] =
|
||||
{
|
||||
{ "RECURSIVE", ONLP_OID_JSON_FLAG_RECURSIVE },
|
||||
{ "UNSUPPORTED_FIELDS", ONLP_OID_JSON_FLAG_UNSUPPORTED_FIELDS },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_json_flag_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_JSON_FLAG_RECURSIVE },
|
||||
{ "None", ONLP_OID_JSON_FLAG_UNSUPPORTED_FIELDS },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_oid_json_flag_name(onlp_oid_json_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_json_flag_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_json_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_json_flag_value(const char* str, onlp_oid_json_flag_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_oid_json_flag_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_oid_json_flag_desc(onlp_oid_json_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_json_flag_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_json_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_json_flag_valid(onlp_oid_json_flag_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_oid_json_flag_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -641,27 +675,93 @@ onlp_oid_show_valid(onlp_oid_show_t e)
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_status_flag_map[] =
|
||||
{
|
||||
{ "PRESENT", ONLP_OID_STATUS_FLAG_PRESENT },
|
||||
{ "FAILED", ONLP_OID_STATUS_FLAG_FAILED },
|
||||
{ "OPERATIONAL", ONLP_OID_STATUS_FLAG_OPERATIONAL },
|
||||
{ "UNPLUGGED", ONLP_OID_STATUS_FLAG_UNPLUGGED },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_status_flag_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_STATUS_FLAG_PRESENT },
|
||||
{ "None", ONLP_OID_STATUS_FLAG_FAILED },
|
||||
{ "None", ONLP_OID_STATUS_FLAG_OPERATIONAL },
|
||||
{ "None", ONLP_OID_STATUS_FLAG_UNPLUGGED },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_oid_status_flag_name(onlp_oid_status_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_status_flag_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_status_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_status_flag_value(const char* str, onlp_oid_status_flag_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_oid_status_flag_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_oid_status_flag_desc(onlp_oid_status_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_status_flag_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_status_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_status_flag_valid(onlp_oid_status_flag_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_oid_status_flag_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_type_map[] =
|
||||
{
|
||||
{ "SYS", ONLP_OID_TYPE_SYS },
|
||||
{ "CHASSIS", ONLP_OID_TYPE_CHASSIS },
|
||||
{ "MODULE", ONLP_OID_TYPE_MODULE },
|
||||
{ "THERMAL", ONLP_OID_TYPE_THERMAL },
|
||||
{ "FAN", ONLP_OID_TYPE_FAN },
|
||||
{ "PSU", ONLP_OID_TYPE_PSU },
|
||||
{ "LED", ONLP_OID_TYPE_LED },
|
||||
{ "MODULE", ONLP_OID_TYPE_MODULE },
|
||||
{ "RTC", ONLP_OID_TYPE_RTC },
|
||||
{ "SFP", ONLP_OID_TYPE_SFP },
|
||||
{ "GENERIC", ONLP_OID_TYPE_GENERIC },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_type_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_TYPE_SYS },
|
||||
{ "None", ONLP_OID_TYPE_CHASSIS },
|
||||
{ "None", ONLP_OID_TYPE_MODULE },
|
||||
{ "None", ONLP_OID_TYPE_THERMAL },
|
||||
{ "None", ONLP_OID_TYPE_FAN },
|
||||
{ "None", ONLP_OID_TYPE_PSU },
|
||||
{ "None", ONLP_OID_TYPE_LED },
|
||||
{ "None", ONLP_OID_TYPE_MODULE },
|
||||
{ "None", ONLP_OID_TYPE_RTC },
|
||||
{ "None", ONLP_OID_TYPE_SFP },
|
||||
{ "None", ONLP_OID_TYPE_GENERIC },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
@@ -711,31 +811,99 @@ onlp_oid_type_valid(onlp_oid_type_t e)
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_type_flag_map[] =
|
||||
{
|
||||
{ "CHASSIS", ONLP_OID_TYPE_FLAG_CHASSIS },
|
||||
{ "MODULE", ONLP_OID_TYPE_FLAG_MODULE },
|
||||
{ "THERMAL", ONLP_OID_TYPE_FLAG_THERMAL },
|
||||
{ "FAN", ONLP_OID_TYPE_FLAG_FAN },
|
||||
{ "PSU", ONLP_OID_TYPE_FLAG_PSU },
|
||||
{ "LED", ONLP_OID_TYPE_FLAG_LED },
|
||||
{ "SFP", ONLP_OID_TYPE_FLAG_SFP },
|
||||
{ "GENERIC", ONLP_OID_TYPE_FLAG_GENERIC },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_type_flag_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_TYPE_FLAG_CHASSIS },
|
||||
{ "None", ONLP_OID_TYPE_FLAG_MODULE },
|
||||
{ "None", ONLP_OID_TYPE_FLAG_THERMAL },
|
||||
{ "None", ONLP_OID_TYPE_FLAG_FAN },
|
||||
{ "None", ONLP_OID_TYPE_FLAG_PSU },
|
||||
{ "None", ONLP_OID_TYPE_FLAG_LED },
|
||||
{ "None", ONLP_OID_TYPE_FLAG_SFP },
|
||||
{ "None", ONLP_OID_TYPE_FLAG_GENERIC },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_oid_type_flag_name(onlp_oid_type_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_type_flag_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_type_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_type_flag_value(const char* str, onlp_oid_type_flag_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_oid_type_flag_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_oid_type_flag_desc(onlp_oid_type_flag_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_type_flag_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_type_flag'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_type_flag_valid(onlp_oid_type_flag_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_oid_type_flag_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_psu_caps_map[] =
|
||||
{
|
||||
{ "AC", ONLP_PSU_CAPS_AC },
|
||||
{ "DC12", ONLP_PSU_CAPS_DC12 },
|
||||
{ "DC48", ONLP_PSU_CAPS_DC48 },
|
||||
{ "VIN", ONLP_PSU_CAPS_VIN },
|
||||
{ "VOUT", ONLP_PSU_CAPS_VOUT },
|
||||
{ "IIN", ONLP_PSU_CAPS_IIN },
|
||||
{ "IOUT", ONLP_PSU_CAPS_IOUT },
|
||||
{ "PIN", ONLP_PSU_CAPS_PIN },
|
||||
{ "POUT", ONLP_PSU_CAPS_POUT },
|
||||
{ "GET_TYPE", ONLP_PSU_CAPS_GET_TYPE },
|
||||
{ "GET_VIN", ONLP_PSU_CAPS_GET_VIN },
|
||||
{ "GET_VOUT", ONLP_PSU_CAPS_GET_VOUT },
|
||||
{ "GET_IIN", ONLP_PSU_CAPS_GET_IIN },
|
||||
{ "GET_IOUT", ONLP_PSU_CAPS_GET_IOUT },
|
||||
{ "GET_PIN", ONLP_PSU_CAPS_GET_PIN },
|
||||
{ "GET_POUT", ONLP_PSU_CAPS_GET_POUT },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_psu_caps_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_PSU_CAPS_AC },
|
||||
{ "None", ONLP_PSU_CAPS_DC12 },
|
||||
{ "None", ONLP_PSU_CAPS_DC48 },
|
||||
{ "None", ONLP_PSU_CAPS_VIN },
|
||||
{ "None", ONLP_PSU_CAPS_VOUT },
|
||||
{ "None", ONLP_PSU_CAPS_IIN },
|
||||
{ "None", ONLP_PSU_CAPS_IOUT },
|
||||
{ "None", ONLP_PSU_CAPS_PIN },
|
||||
{ "None", ONLP_PSU_CAPS_POUT },
|
||||
{ "None", ONLP_PSU_CAPS_GET_TYPE },
|
||||
{ "None", ONLP_PSU_CAPS_GET_VIN },
|
||||
{ "None", ONLP_PSU_CAPS_GET_VOUT },
|
||||
{ "None", ONLP_PSU_CAPS_GET_IIN },
|
||||
{ "None", ONLP_PSU_CAPS_GET_IOUT },
|
||||
{ "None", ONLP_PSU_CAPS_GET_PIN },
|
||||
{ "None", ONLP_PSU_CAPS_GET_POUT },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
@@ -785,40 +953,40 @@ onlp_psu_caps_valid(onlp_psu_caps_t e)
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_psu_status_map[] =
|
||||
aim_map_si_t onlp_psu_type_map[] =
|
||||
{
|
||||
{ "PRESENT", ONLP_PSU_STATUS_PRESENT },
|
||||
{ "FAILED", ONLP_PSU_STATUS_FAILED },
|
||||
{ "UNPLUGGED", ONLP_PSU_STATUS_UNPLUGGED },
|
||||
{ "AC", ONLP_PSU_TYPE_AC },
|
||||
{ "DC12", ONLP_PSU_TYPE_DC12 },
|
||||
{ "DC48", ONLP_PSU_TYPE_DC48 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_psu_status_desc_map[] =
|
||||
aim_map_si_t onlp_psu_type_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_PSU_STATUS_PRESENT },
|
||||
{ "None", ONLP_PSU_STATUS_FAILED },
|
||||
{ "None", ONLP_PSU_STATUS_UNPLUGGED },
|
||||
{ "None", ONLP_PSU_TYPE_AC },
|
||||
{ "None", ONLP_PSU_TYPE_DC12 },
|
||||
{ "None", ONLP_PSU_TYPE_DC48 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_psu_status_name(onlp_psu_status_t e)
|
||||
onlp_psu_type_name(onlp_psu_type_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_psu_status_map, 0)) {
|
||||
if(aim_map_si_i(&name, e, onlp_psu_type_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_psu_status'";
|
||||
return "-invalid value for enum type 'onlp_psu_type'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psu_status_value(const char* str, onlp_psu_status_t* e, int substr)
|
||||
onlp_psu_type_value(const char* str, onlp_psu_type_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_psu_status_map, 0)) {
|
||||
if(aim_map_si_s(&i, str, onlp_psu_type_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
@@ -829,23 +997,17 @@ onlp_psu_status_value(const char* str, onlp_psu_status_t* e, int substr)
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_psu_status_desc(onlp_psu_status_t e)
|
||||
onlp_psu_type_desc(onlp_psu_type_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_psu_status_desc_map, 0)) {
|
||||
if(aim_map_si_i(&name, e, onlp_psu_type_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_psu_status'";
|
||||
return "-invalid value for enum type 'onlp_psu_type'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psu_status_valid(onlp_psu_status_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_psu_status_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_sfp_control_map[] =
|
||||
{
|
||||
@@ -985,6 +1147,64 @@ onlp_sfp_control_flag_valid(onlp_sfp_control_flag_t e)
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_sfp_type_map[] =
|
||||
{
|
||||
{ "SFP", ONLP_SFP_TYPE_SFP },
|
||||
{ "QSFP", ONLP_SFP_TYPE_QSFP },
|
||||
{ "SFP28", ONLP_SFP_TYPE_SFP28 },
|
||||
{ "QSFP28", ONLP_SFP_TYPE_QSFP28 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_sfp_type_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_SFP_TYPE_SFP },
|
||||
{ "None", ONLP_SFP_TYPE_QSFP },
|
||||
{ "None", ONLP_SFP_TYPE_SFP28 },
|
||||
{ "None", ONLP_SFP_TYPE_QSFP28 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_sfp_type_name(onlp_sfp_type_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_sfp_type_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_sfp_type'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfp_type_value(const char* str, onlp_sfp_type_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_sfp_type_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_sfp_type_desc(onlp_sfp_type_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_sfp_type_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_sfp_type'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_status_map[] =
|
||||
{
|
||||
{ "OK", ONLP_STATUS_OK },
|
||||
@@ -1121,66 +1341,6 @@ onlp_thermal_caps_valid(onlp_thermal_caps_t e)
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_thermal_status_map[] =
|
||||
{
|
||||
{ "PRESENT", ONLP_THERMAL_STATUS_PRESENT },
|
||||
{ "FAILED", ONLP_THERMAL_STATUS_FAILED },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_thermal_status_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_THERMAL_STATUS_PRESENT },
|
||||
{ "None", ONLP_THERMAL_STATUS_FAILED },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_thermal_status_name(onlp_thermal_status_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_thermal_status_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_thermal_status'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_thermal_status_value(const char* str, onlp_thermal_status_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_thermal_status_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_thermal_status_desc(onlp_thermal_status_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_thermal_status_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_thermal_status'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_thermal_status_valid(onlp_thermal_status_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_thermal_status_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_thermal_threshold_map[] =
|
||||
{
|
||||
{ "WARNING_DEFAULT", ONLP_THERMAL_THRESHOLD_WARNING_DEFAULT },
|
||||
@@ -1243,4 +1403,3 @@ onlp_thermal_threshold_valid(onlp_thermal_threshold_t e)
|
||||
}
|
||||
|
||||
/* <auto.end.enum(ALL).source> */
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <IOF/iof.h>
|
||||
#include <onlp/oids.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson_util/cjson_util.h>
|
||||
#include <cjson_util/cjson_util_format.h>
|
||||
#include "onlp_json.h"
|
||||
|
||||
/** Default IOF initializations for dump() and show() routines */
|
||||
@@ -44,4 +46,37 @@ void onlp_oid_show_description(iof_t* iof, onlp_oid_hdr_t* hdr);
|
||||
/** Standard message when an OID is missing. */
|
||||
void onlp_oid_show_state_missing(iof_t* iof);
|
||||
|
||||
#define __ONLP_PTR_VALIDATE(_ptr, _clr) \
|
||||
do { \
|
||||
if(!(_ptr)) { \
|
||||
return ONLP_STATUS_E_PARAM; \
|
||||
} \
|
||||
if(_clr) { \
|
||||
memset(_ptr, 0, sizeof(*_ptr)); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ONLP_PTR_VALIDATE_ZERO(_ptr) __ONLP_PTR_VALIDATE(_ptr, 1)
|
||||
#define ONLP_PTR_VALIDATE(_ptr) __ONLP_PTR_VALIDATE(_ptr, 0)
|
||||
|
||||
#define ONLP_PTR_VALIDATE_NR(_ptr) { \
|
||||
do { \
|
||||
if(!(_ptr)) { \
|
||||
return ; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define ONLP_PTR_CLEAR(_ptr) memset(_ptr, 0, sizeof(*_ptr))
|
||||
|
||||
/**
|
||||
* Create the initial JSON object when serializing an info structure.
|
||||
*/
|
||||
int onlp_info_to_json_create(onlp_oid_hdr_t* hdr, cJSON** cjp, uint32_t flags);
|
||||
int onlp_info_to_user_json_create(onlp_oid_hdr_t* hdr, cJSON** cjp, uint32_t flags);
|
||||
int onlp_info_to_user_json_finish(onlp_oid_hdr_t* hdr, cJSON* object,
|
||||
cJSON** cjp, uint32_t flags);
|
||||
int onlp_info_to_json_finish(onlp_oid_hdr_t* hdr, cJSON* object, cJSON** cjp,
|
||||
uint32_t flags);
|
||||
|
||||
void onlp_oid_hdr_sort(onlp_oid_hdr_t* hdr);
|
||||
#endif /* __ONLP_INT_H__ */
|
||||
|
||||
@@ -33,7 +33,11 @@
|
||||
* @brief Initialize the ONLP API lock infrastructure.
|
||||
*/
|
||||
void onlp_api_lock_init();
|
||||
void onlp_api_lock_denit();
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the ONLP API lock infrastructure.
|
||||
*/
|
||||
void onlp_api_lock_denit(void);
|
||||
|
||||
/**
|
||||
* @brief Take the ONLP API lock.
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -26,13 +26,51 @@
|
||||
#include <onlp/onlp_config.h>
|
||||
|
||||
#include "onlp_log.h"
|
||||
#include "onlp_int.h"
|
||||
|
||||
/*
|
||||
* onlp log struct.
|
||||
*/
|
||||
AIM_LOG_STRUCT_DEFINE(
|
||||
ONLP_CONFIG_LOG_OPTIONS_DEFAULT,
|
||||
ONLP_CONFIG_LOG_BITS_DEFAULT,
|
||||
NULL, /* Custom log map */
|
||||
onlp_log_flag_map,
|
||||
ONLP_CONFIG_LOG_CUSTOM_BITS_DEFAULT
|
||||
);
|
||||
|
||||
static int
|
||||
log_enabled__(int rv, uint32_t flags)
|
||||
{
|
||||
return ONLP_FAILURE(rv);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_vlog_error(uint32_t flags, int rv, const char* fmt, va_list vargs)
|
||||
{
|
||||
if(log_enabled__(rv, flags)) {
|
||||
char* s1 = aim_vdfstrdup(fmt, vargs);
|
||||
char* s2;
|
||||
if(ONLP_FAILURE(rv)) {
|
||||
s2 = aim_dfstrdup(" failed: %{onlp_status}", rv);
|
||||
AIM_LOG_ERROR("%s%s", s1, s2);
|
||||
}
|
||||
else {
|
||||
s2 = aim_dfstrdup(" %{onlp_status}", rv);
|
||||
AIM_LOG_INFO("%s%s", s1, s2);
|
||||
}
|
||||
aim_free(s1);
|
||||
aim_free(s2);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_log_error(uint32_t flags, int rv, const char* fmt, ...)
|
||||
{
|
||||
int rc;
|
||||
va_list vargs;
|
||||
va_start(vargs, fmt);
|
||||
rc = onlp_vlog_error(flags, rv, fmt, vargs);
|
||||
va_end(vargs);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -29,4 +29,91 @@
|
||||
#define AIM_LOG_MODULE_NAME onlp
|
||||
#include <AIM/aim_log.h>
|
||||
|
||||
/* <auto.start.enum(onlp_log_flag).header> */
|
||||
/** onlp_log_flag */
|
||||
typedef enum onlp_log_flag_e {
|
||||
ONLP_LOG_FLAG_JSON,
|
||||
ONLP_LOG_FLAG_LAST = ONLP_LOG_FLAG_JSON,
|
||||
ONLP_LOG_FLAG_COUNT,
|
||||
ONLP_LOG_FLAG_INVALID = -1,
|
||||
} onlp_log_flag_t;
|
||||
|
||||
/** Strings macro. */
|
||||
#define ONLP_LOG_FLAG_STRINGS \
|
||||
{\
|
||||
"JSON", \
|
||||
}
|
||||
/** Enum names. */
|
||||
const char* onlp_log_flag_name(onlp_log_flag_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_log_flag_value(const char* str, onlp_log_flag_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_log_flag_desc(onlp_log_flag_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_LOG_FLAG_VALID(_e) \
|
||||
( (0 <= (_e)) && ((_e) <= ONLP_LOG_FLAG_JSON))
|
||||
|
||||
/** onlp_log_flag_map table. */
|
||||
extern aim_map_si_t onlp_log_flag_map[];
|
||||
/** onlp_log_flag_desc_map table. */
|
||||
extern aim_map_si_t onlp_log_flag_desc_map[];
|
||||
/* <auto.end.enum(onlp_log_flag).header> */
|
||||
|
||||
/* <auto.start.aim_custom_log_macro(ALL).header> */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Custom Module Log Macros
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/** Log a module-level json */
|
||||
#define ONLP_LOG_MOD_JSON(...) \
|
||||
AIM_LOG_MOD_CUSTOM(ONLP_LOG_FLAG_JSON, "JSON", __VA_ARGS__)
|
||||
/** Log a module-level json with ratelimiting */
|
||||
#define ONLP_LOG_MOD_RL_JSON(_rl, _time, ...) \
|
||||
AIM_LOG_MOD_RL_CUSTOM(ONLP_LOG_FLAG_JSON, "JSON", _rl, _time, __VA_ARGS__)
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Custom Object Log Macros
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/** Log an object-level json */
|
||||
#define ONLP_LOG_OBJ_JSON(_obj, ...) \
|
||||
AIM_LOG_OBJ_CUSTOM(_obj, ONLP_LOG_FLAG_JSON, "JSON", __VA_ARGS__)
|
||||
/** Log an object-level json with ratelimiting */
|
||||
#define ONLP_LOG_OBJ_RL_JSON(_obj, _rl, _time, ...) \
|
||||
AIM_LOG_OBJ_RL_CUSTOM(_obj, ONLP_LOG_FLAG_JSON, "JSON", _rl, _time, __VA_ARGS__)
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Default Macro Mappings
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifdef AIM_LOG_OBJ_DEFAULT
|
||||
|
||||
/** JSON -> OBJ_JSON */
|
||||
#define ONLP_LOG_JSON ONLP_LOG_OBJ_JSON
|
||||
/** RL_JSON -> OBJ_RL_JSON */
|
||||
#define ONLP_LOG_RL_JSON ONLP_LOG_RL_OBJ_JSON
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/** JSON -> MOD_JSON */
|
||||
#define ONLP_LOG_JSON ONLP_LOG_MOD_JSON
|
||||
/** RL_JSON -> MOD_RL_JSON */
|
||||
#define ONLP_LOG_RL_JSON ONLP_LOG_MOD_RL_JSON
|
||||
|
||||
#endif
|
||||
/* <auto.end.aim_custom_log_macro(ALL).header> */
|
||||
|
||||
int onlp_vlog_error(uint32_t flags, int rv, const char* fmt, va_list vargs);
|
||||
int onlp_log_error(uint32_t flags, int rv, const char* fmt, ...);
|
||||
|
||||
#endif /* __ONLP_LOG_H__ */
|
||||
|
||||
@@ -22,150 +22,59 @@
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlp/oids.h>
|
||||
#include <uCli/ucli.h>
|
||||
#include <AIM/aim_thread.h>
|
||||
#include <unistd.h>
|
||||
#include <onlp/sys.h>
|
||||
#include <onlp/sfp.h>
|
||||
#include <sff/sff.h>
|
||||
#include <sff/sff_db.h>
|
||||
#include <AIM/aim_log_handler.h>
|
||||
#include <syslog.h>
|
||||
#include <onlp/platformi/sysi.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include "onlp_log.h"
|
||||
|
||||
static void platform_manager_daemon__(const char* pidfile, char** argv);
|
||||
|
||||
/**
|
||||
* Human-readable SFP inventory.
|
||||
* This should be moved to common.
|
||||
/*
|
||||
* Some CLI commands require the original argv vector
|
||||
* to implement things like daemonized restart.
|
||||
*/
|
||||
static void
|
||||
show_inventory__(aim_pvs_t* pvs, int database)
|
||||
{
|
||||
int port;
|
||||
onlp_sfp_bitmap_t bitmap;
|
||||
|
||||
onlp_sfp_bitmap_t_init(&bitmap);
|
||||
onlp_sfp_bitmap_get(&bitmap);
|
||||
|
||||
if(AIM_BITMAP_COUNT(&bitmap) == 0) {
|
||||
aim_printf(pvs, "No SFPs on this platform.\n");
|
||||
}
|
||||
else {
|
||||
if(!database) {
|
||||
aim_printf(pvs, "Port Type Media Status Len Vendor Model S/N \n");
|
||||
aim_printf(pvs, "---- -------------- ------ ------ ----- ---------------- ---------------- ----------------\n");
|
||||
}
|
||||
|
||||
AIM_BITMAP_ITER(&bitmap, port) {
|
||||
int rv;
|
||||
uint8_t* data;
|
||||
|
||||
rv = onlp_sfp_is_present(port);
|
||||
|
||||
if(rv == 0) {
|
||||
if(!database) {
|
||||
aim_printf(pvs, "%4d NONE\n", port);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(rv < 0) {
|
||||
aim_printf(pvs, "%4d Error %{onlp_status}\n", port, rv);
|
||||
continue;
|
||||
}
|
||||
|
||||
rv = onlp_sfp_eeprom_read(port, &data);
|
||||
|
||||
if(rv < 0) {
|
||||
aim_printf(pvs, "%4d Error %{onlp_status}\n", port, rv);
|
||||
continue;
|
||||
}
|
||||
|
||||
sff_eeprom_t sff;
|
||||
char status_str[32] = {0};
|
||||
|
||||
sff_eeprom_parse(&sff, data);
|
||||
|
||||
if(!sff.identified) {
|
||||
/* Present but unidentified. */
|
||||
aim_printf(pvs, "%13d UNK\n", port);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(database) {
|
||||
sff_db_entry_struct(&sff, &aim_pvs_stdout);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t status = 0;
|
||||
char* cp = status_str;
|
||||
onlp_sfp_control_flags_get(port, &status);
|
||||
if(status & ONLP_SFP_CONTROL_FLAG_RX_LOS) {
|
||||
*cp++ = 'R';
|
||||
}
|
||||
if(status & ONLP_SFP_CONTROL_FLAG_TX_FAULT) {
|
||||
*cp++ = 'T';
|
||||
}
|
||||
if(status & ONLP_SFP_CONTROL_FLAG_TX_DISABLE) {
|
||||
*cp++ = 'X';
|
||||
}
|
||||
if(status & ONLP_SFP_CONTROL_FLAG_LP_MODE) {
|
||||
*cp++ = 'L';
|
||||
}
|
||||
aim_printf(pvs, "%4d %-14s %-6s %-6.6s %-5.5s %-16.16s %-16.16s %16.16s\n",
|
||||
port,
|
||||
sff.info.module_type_name,
|
||||
sff.info.media_type_name,
|
||||
status_str,
|
||||
sff.info.length_desc,
|
||||
sff.info.vendor,
|
||||
sff.info.model,
|
||||
sff.info.serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
iterate_oids_callback__(onlp_oid_t oid, void* cookie)
|
||||
{
|
||||
int type = ONLP_OID_TYPE_GET(oid);
|
||||
int id = ONLP_OID_ID_GET(oid);
|
||||
|
||||
static int thermal = 1;
|
||||
static int fan = 1;
|
||||
static int psu = 1;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case ONLP_OID_TYPE_THERMAL:
|
||||
printf("thermal,Thermal %d,%d\n", id, thermal++);
|
||||
break;
|
||||
case ONLP_OID_TYPE_FAN:
|
||||
printf("fan,Fan %d,%d\n", id, fan++);
|
||||
break;
|
||||
case ONLP_OID_TYPE_PSU:
|
||||
printf("psu,PSU %d,%d\n", id, psu++);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
iterate_oids__(void)
|
||||
{
|
||||
onlp_oid_iterate(ONLP_OID_SYS, 0,
|
||||
iterate_oids_callback__, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern char** onlp_ucli_argv;
|
||||
|
||||
int
|
||||
onlpdump_main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
ucli_t* ucli = NULL;
|
||||
char** argv_strings;
|
||||
char** opt;
|
||||
|
||||
aim_thread_name_set("onlpd.main");
|
||||
onlp_ucli_argv = argv;
|
||||
|
||||
extern ucli_node_t* onlp_ucli_node_create(void);
|
||||
char hostname[128] = {0};
|
||||
gethostname(hostname, sizeof(hostname)-1);
|
||||
const char* prompt = aim_fstrdup("%s.onlp", hostname);
|
||||
|
||||
AIM_TRY_OR_DIE(onlp_sw_init(NULL));
|
||||
|
||||
AIM_TRY_OR_DIE(ucli_init());
|
||||
ucli = ucli_create(prompt, NULL, onlp_ucli_node_create());
|
||||
argv_strings = ucli_argv_to_strings(argv+1);
|
||||
if(argv_strings) {
|
||||
for(opt = argv_strings; *opt; opt++) {
|
||||
if(ucli_dispatch_string(ucli, &aim_pvs_stdout, *opt) < 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ucli_argv_to_strings_free(argv_strings);
|
||||
}
|
||||
if(!argv_strings || !argv_strings[0]) {
|
||||
ucli_run(ucli, prompt);
|
||||
}
|
||||
aim_free((char*)prompt);
|
||||
ucli_destroy(ucli);
|
||||
|
||||
AIM_TRY_OR_DIE(onlp_sw_denit());
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TO_BE_CONVERTED_TO_UCLI
|
||||
|
||||
int show = 0;
|
||||
uint32_t showflags = 0;
|
||||
int help = 0;
|
||||
@@ -189,14 +98,9 @@ onlpdump_main(int argc, char* argv[])
|
||||
/**
|
||||
* debug trap
|
||||
*/
|
||||
if(argc > 1 && (!strcmp(argv[1], "debug") || !strcmp(argv[1], "debugi"))) {
|
||||
if(!strcmp(argv[1], "debug")) {
|
||||
onlp_init();
|
||||
return onlp_sys_debug(&aim_pvs_stdout, argc-2, argv+2);
|
||||
}
|
||||
else {
|
||||
return onlp_sysi_debug(&aim_pvs_stdout, argc-2, argv+2);
|
||||
}
|
||||
if(argc > 1 && (!strcmp(argv[1], "debug"))) {
|
||||
onlp_sw_init(NULL);
|
||||
return onlp_debug(&aim_pvs_stdout, argc-2, argv+2);
|
||||
}
|
||||
|
||||
while( (c = getopt(argc, argv, "srehdojmyM:ipxlSt:O:bJ:")) != -1) {
|
||||
@@ -248,6 +152,8 @@ onlpdump_main(int argc, char* argv[])
|
||||
return rv;
|
||||
}
|
||||
|
||||
AIM_REFERENCE(j);
|
||||
|
||||
if(J) {
|
||||
int rv;
|
||||
onlp_onie_info_t onie;
|
||||
@@ -278,7 +184,7 @@ onlpdump_main(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
onlp_init();
|
||||
onlp_sw_init(NULL);
|
||||
|
||||
if(M) {
|
||||
platform_manager_daemon__(pidfile, argv);
|
||||
@@ -344,7 +250,6 @@ onlpdump_main(int argc, char* argv[])
|
||||
onlp_sys_info_free(&si);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(show >= 0) {
|
||||
if(show == 0) {
|
||||
/* Default to full dump */
|
||||
@@ -360,10 +265,10 @@ onlpdump_main(int argc, char* argv[])
|
||||
|
||||
if(m) {
|
||||
printf("Running the platform manager for 600 seconds...\n");
|
||||
onlp_sys_platform_manage_start(0);
|
||||
onlp_platform_manager_start(0);
|
||||
sleep(600);
|
||||
printf("Stopping the platform manager.\n");
|
||||
onlp_sys_platform_manage_stop(1);
|
||||
onlp_platform_manager_stop(1);
|
||||
}
|
||||
|
||||
if(p) {
|
||||
@@ -378,12 +283,9 @@ onlpdump_main(int argc, char* argv[])
|
||||
aim_printf(&aim_pvs_stdout, "%{aim_bitmap}\n", &presence);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if AIM_CONFIG_INCLUDE_DAEMONIZE == 1
|
||||
|
||||
#include <AIM/aim_daemon.h>
|
||||
#include <AIM/aim_pvs_syslog.h>
|
||||
#include <signal.h>
|
||||
@@ -392,7 +294,7 @@ onlpdump_main(int argc, char* argv[])
|
||||
void
|
||||
sighandler__(int signal)
|
||||
{
|
||||
onlp_sys_platform_manage_stop(0);
|
||||
onlp_platform_manager_stop(0);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -435,21 +337,12 @@ platform_manager_daemon__(const char* pidfile, char** argv)
|
||||
signal(SIGTERM, sighandler__);
|
||||
|
||||
/** Start and block in platform manager. */
|
||||
onlp_sys_platform_manage_start(1);
|
||||
onlp_platform_manager_start(1);
|
||||
|
||||
/** Terminated via signal. Cleanup and exit. */
|
||||
onlp_sys_platform_manage_stop(1);
|
||||
onlp_platform_manager_stop(1);
|
||||
|
||||
aim_log_handler_basic_denit_all();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
static void
|
||||
platform_manager_daemon__(const char* pidfile, char** argv)
|
||||
{
|
||||
fprintf(stderr, "Daemon mode not supported in this build.\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
***********************************************************/
|
||||
|
||||
#include <onlp/onlp_config.h>
|
||||
|
||||
#include <onlp/onlp.h>
|
||||
#include "onlp_log.h"
|
||||
#include <onlplib/shlocks.h>
|
||||
#include <onlp/oids.h>
|
||||
@@ -33,18 +33,45 @@ static int
|
||||
onlp_aim_ts__onlp_oid(aim_datatype_context_t* dtc, aim_va_list_t* vargs,
|
||||
const char** rv)
|
||||
{
|
||||
char str[64];
|
||||
onlp_oid_t oid = va_arg(vargs->val, onlp_oid_t);
|
||||
int id = ONLP_OID_ID_GET(oid);
|
||||
if(ONLP_SUCCESS(onlp_oid_to_str(oid, str))) {
|
||||
*rv = aim_strdup(str);
|
||||
return AIM_DATATYPE_OK;
|
||||
}
|
||||
*rv = NULL;
|
||||
return AIM_DATATYPE_ERROR;
|
||||
}
|
||||
|
||||
switch(ONLP_OID_TYPE_GET(oid))
|
||||
static int
|
||||
onlp_aim_fs__onlp_oid(aim_datatype_context_t* dtc,
|
||||
const char* arg, aim_va_list_t* vargs)
|
||||
{
|
||||
onlp_oid_t* oidp = va_arg(vargs->val, onlp_oid_t*);
|
||||
AIM_REFERENCE(dtc);
|
||||
|
||||
if(ONLP_SUCCESS(onlp_oid_from_str((char*)arg, oidp))) {
|
||||
return AIM_DATATYPE_OK;
|
||||
}
|
||||
|
||||
return AIM_DATATYPE_ERROR;
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_aim_ts__onlp_oid_hdr(aim_datatype_context_t* dtc, aim_va_list_t* vargs,
|
||||
const char** rv)
|
||||
{
|
||||
onlp_oid_hdr_t* hdr = va_arg(vargs->val, onlp_oid_hdr_t*);
|
||||
int id = ONLP_OID_ID_GET(hdr->id);
|
||||
switch(ONLP_OID_TYPE_GET(hdr->id))
|
||||
{
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
*rv = aim_fstrdup("%s:%d", #_name, id); \
|
||||
#define ONLP_OID_TYPE_ENTRY(_name, _value, _upper, _lower) \
|
||||
case ONLP_OID_TYPE_##_name: \
|
||||
*rv = aim_dfstrdup(#_lower" %d %s status=%{onlp_oid_status_flags}", \
|
||||
id, hdr->description, hdr->status); \
|
||||
break;
|
||||
#include <onlp/onlp.x>
|
||||
}
|
||||
|
||||
return AIM_DATATYPE_OK;
|
||||
}
|
||||
|
||||
@@ -55,23 +82,24 @@ datatypes_init__(void)
|
||||
#include <onlp/onlp.x>
|
||||
aim_datatype_register(0, "onlp_oid",
|
||||
"ONLP OID",
|
||||
NULL,
|
||||
onlp_aim_fs__onlp_oid,
|
||||
onlp_aim_ts__onlp_oid, NULL);
|
||||
aim_datatype_register(0, "onlp_oid_hdr",
|
||||
"ONLP OID Header",
|
||||
NULL,
|
||||
onlp_aim_ts__onlp_oid_hdr, NULL);
|
||||
|
||||
|
||||
/*
|
||||
* Register our flag maps.
|
||||
*/
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_oid_status_flags, onlp_oid_status_flag_map, "OID Status Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_sfp_control_flags, onlp_sfp_control_flag_map, "SFP Control Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_fan_caps_flags, onlp_fan_caps_map, "FAN Capability Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_fan_status_flags, onlp_fan_status_map, "FAN Status Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_thermal_status_flags, onlp_thermal_status_map, "Thermal Status Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_thermal_caps_flags, onlp_thermal_caps_map, "Thermal Capability Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_led_caps_flags, onlp_led_caps_map, "LED Capability Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_led_status_flags, onlp_led_status_map, "LED Status Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_psu_status_flags, onlp_psu_status_map, "PSU Status Flags", AIM_LOG_INTERNAL);
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_psu_caps_flags, onlp_psu_caps_map, "PSU Capability Flags", AIM_LOG_INTERNAL);
|
||||
|
||||
AIM_DATATYPE_FMAP_REGISTER(onlp_oid_type_flags, onlp_oid_type_flag_map, "ONLP OID Type Flags", AIM_LOG_INTERNAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -91,4 +119,3 @@ void __onlp_module_init__(void)
|
||||
__onlp_platform_version_default__ = __onlp_platform_version__;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -30,13 +30,366 @@
|
||||
#include <uCli/ucli.h>
|
||||
#include <uCli/ucli_argparse.h>
|
||||
#include <uCli/ucli_handler_macros.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include <onlp/platform.h>
|
||||
#include <onlp/attribute.h>
|
||||
#include <onlp/stdattrs.h>
|
||||
#include <onlp/fan.h>
|
||||
#include <onlp/sfp.h>
|
||||
#include <onlplib/onie.h>
|
||||
#include <onlp/oids.h>
|
||||
#include <cjson_util/cjson_util_format.h>
|
||||
#include <AIM/aim_sleep.h>
|
||||
|
||||
#include <onlp/chassis.h>
|
||||
#include <onlp/module.h>
|
||||
#include <onlp/thermal.h>
|
||||
#include <onlp/fan.h>
|
||||
#include <onlp/led.h>
|
||||
#include <onlp/generic.h>
|
||||
#include <onlp/psu.h>
|
||||
|
||||
/**
|
||||
* Needed for commands which invoke daemonized restart.
|
||||
*/
|
||||
char** onlp_ucli_argv = NULL;
|
||||
|
||||
#define ONLP_CMD_STATUS(_rv) \
|
||||
do { \
|
||||
if(ONLP_FAILURE(_rv)) { \
|
||||
ucli_printf(uc, "failed: %{onlp_status}\n", _rv); \
|
||||
} \
|
||||
return 0; \
|
||||
} while(0)
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli_ucli__config__(ucli_context_t* uc)
|
||||
onlp_ucli__chassis__attribute__onie__get__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_HANDLER_MACRO_MODULE_CONFIG(onlp)
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"get", -1,
|
||||
"$summary#Show the Chassis ONIE information."
|
||||
"$args#[yaml|json]");
|
||||
int rv;
|
||||
int format;
|
||||
cJSON* cj;
|
||||
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "{choice:yaml}", &format,
|
||||
"format", 2, "yaml", "json");
|
||||
|
||||
if(ONLP_SUCCESS(rv = onlp_attribute_get(ONLP_OID_CHASSIS,
|
||||
ONLP_ATTRIBUTE_ONIE_INFO_JSON,
|
||||
(void**)&cj))) {
|
||||
if(format) {
|
||||
cjson_util_json_pvs(&uc->pvs, cj);
|
||||
}
|
||||
else {
|
||||
cjson_util_yaml_pvs(&uc->pvs, cj);
|
||||
}
|
||||
onlp_attribute_free(ONLP_OID_CHASSIS, ONLP_ATTRIBUTE_ONIE_INFO_JSON,
|
||||
cj);
|
||||
}
|
||||
|
||||
ONLP_CMD_STATUS(rv);
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__chassis__environment__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"environment", 0,
|
||||
"Show environment.");
|
||||
int rv;
|
||||
cJSON* cj = NULL;
|
||||
if(ONLP_SUCCESS(rv = onlp_oid_to_user_json(ONLP_OID_CHASSIS, &cj,
|
||||
ONLP_OID_JSON_FLAG_RECURSIVE))) {
|
||||
cjson_util_yaml_pvs(&uc->pvs, cj);
|
||||
cJSON_Delete(cj);
|
||||
return UCLI_STATUS_OK;
|
||||
}
|
||||
else {
|
||||
ucli_printf(uc, "Failed: %{onlp_status}", rv);
|
||||
return UCLI_STATUS_E_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__chassis__dump__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"dump", 0,
|
||||
"Dump all chassis OIDs.");
|
||||
int rv;
|
||||
cJSON* cj = NULL;
|
||||
if(ONLP_SUCCESS(rv = onlp_oid_to_json(ONLP_OID_CHASSIS, &cj,
|
||||
ONLP_OID_JSON_FLAG_RECURSIVE))) {
|
||||
cjson_util_yaml_pvs(&uc->pvs, cj);
|
||||
cJSON_Delete(cj);
|
||||
return UCLI_STATUS_OK;
|
||||
}
|
||||
else {
|
||||
ucli_printf(uc, "Failed: %{onlp_status}", rv);
|
||||
return UCLI_STATUS_E_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__chassis__attribute__asset__get__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"get", -1,
|
||||
"$summary#Show the Chassis Asset information."
|
||||
"$args#[yaml|json]");
|
||||
int rv;
|
||||
int format;
|
||||
cJSON* cj;
|
||||
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "{choice:yaml}", &format,
|
||||
"format", 2, "yaml", "json");
|
||||
|
||||
if(ONLP_SUCCESS(rv = onlp_attribute_get(ONLP_OID_CHASSIS,
|
||||
ONLP_ATTRIBUTE_ASSET_INFO_JSON,
|
||||
(void**)&cj))) {
|
||||
if(format) {
|
||||
cjson_util_json_pvs(&uc->pvs, cj);
|
||||
}
|
||||
else {
|
||||
cjson_util_yaml_pvs(&uc->pvs, cj);
|
||||
}
|
||||
onlp_attribute_free(ONLP_OID_CHASSIS,
|
||||
ONLP_ATTRIBUTE_ASSET_INFO_JSON, cj);
|
||||
}
|
||||
|
||||
ONLP_CMD_STATUS(rv);
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__oid__info__all__(ucli_context_t* uc)
|
||||
{
|
||||
onlp_oid_type_flags_t types;
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"all", 1, "");
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "{onlp_oid_type_flags}", &types);
|
||||
onlp_oid_info_format_all(ONLP_OID_CHASSIS, types, 0x0, 0x0, &uc->pvs, 0x0);
|
||||
return UCLI_STATUS_OK;
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__oid__hdr__all__(ucli_context_t* uc)
|
||||
{
|
||||
onlp_oid_type_flags_t types;
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"all", 1, "");
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "{onlp_oid_type_flags}", &types);
|
||||
onlp_oid_hdr_format_all(ONLP_OID_CHASSIS, types, 0x0, 0x0, &uc->pvs, 0x0);
|
||||
return UCLI_STATUS_OK;
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__debug__oid__verify__json__(ucli_context_t* uc)
|
||||
{
|
||||
onlp_oid_t oid;
|
||||
UCLI_COMMAND_INFO(uc, "json", 1, "");
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "{onlp_oid}", &oid);
|
||||
ucli_printf(uc, "%{onlp_oid}: %{onlp_status}\n",
|
||||
oid, onlp_oid_json_verify(oid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__debug__oid__from__json__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc, "json", 1, "");
|
||||
int rv;
|
||||
cJSON* cj;
|
||||
char* filename;
|
||||
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "s", &filename);
|
||||
if(cjson_util_parse_file(filename, &cj) < 0) {
|
||||
ucli_printf(uc, "Could not parse json file %s\n", filename);
|
||||
return -1;
|
||||
}
|
||||
biglist_t* all_oids = NULL;
|
||||
if(ONLP_SUCCESS(rv = onlp_oid_from_json(cj, NULL, &all_oids,
|
||||
ONLP_OID_JSON_FLAG_RECURSIVE))) {
|
||||
biglist_t* ble;
|
||||
onlp_oid_hdr_t* hdr;
|
||||
BIGLIST_FOREACH_DATA(ble, all_oids, onlp_oid_hdr_t*, hdr) {
|
||||
cJSON* object = NULL;
|
||||
ucli_printf(uc, "%{onlp_oid_hdr}\n", hdr);
|
||||
if(ONLP_SUCCESS(onlp_oid_info_to_json(hdr, &object, 0))) {
|
||||
cjson_util_yaml_pvs(&uc->pvs, object);
|
||||
}
|
||||
cJSON_Delete(object);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ucli_printf(uc, "onlp_oid_from_json returned %{onlp_status}\n", rv);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__debug__oid__to__json__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"json", 2, "");
|
||||
|
||||
int rv;
|
||||
cJSON* cj = NULL;
|
||||
onlp_oid_t oid;
|
||||
int choice;
|
||||
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "{onlp_oid}{choice}", &oid, &choice, "type", 3, "debug", "debug-all", "user");
|
||||
switch(choice)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
rv = onlp_oid_to_json(oid, &cj, 0);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
rv = onlp_oid_to_json(oid, &cj, ONLP_OID_JSON_FLAG_RECURSIVE);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
rv = onlp_oid_to_user_json(oid, &cj,
|
||||
ONLP_OID_JSON_FLAG_RECURSIVE);
|
||||
break;
|
||||
}
|
||||
default: rv = ONLP_STATUS_E_PARAM; break;
|
||||
}
|
||||
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
cjson_util_json_pvs(&uc->pvs, cj);
|
||||
cJSON_Delete(cj);
|
||||
}
|
||||
else {
|
||||
ucli_printf(uc, "oid to json failed: %{onlp_status}", rv);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__oid__hdr__json__id__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"id", 1, "");
|
||||
int rv;
|
||||
onlp_oid_t oid;
|
||||
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "{onlp_oid}", &oid);
|
||||
|
||||
onlp_oid_hdr_t hdr;
|
||||
if(ONLP_SUCCESS(rv = onlp_oid_hdr_get(oid, &hdr))) {
|
||||
cJSON* cj;
|
||||
if(ONLP_SUCCESS(rv = onlp_oid_hdr_to_json(&hdr, &cj, 0))) {
|
||||
cjson_util_json_pvs(&uc->pvs, cj);
|
||||
cJSON_Delete(cj);
|
||||
}
|
||||
else {
|
||||
ucli_printf(uc, "onlp_oid_hdr_to_json failed: %{onlp_status}", rv);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ucli_printf(uc, "onlp_oid_hdr_get failed: %{onlp_status}", rv);
|
||||
}
|
||||
return UCLI_STATUS_OK;
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__oid__hdr__json__file__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"file", 1, "");
|
||||
|
||||
int rv;
|
||||
char* f;
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "s", &f);
|
||||
|
||||
cJSON* cj;
|
||||
if(cjson_util_parse_file(f, &cj) < 0) {
|
||||
ucli_printf(uc, "failed to open or parse '%s'\n", f);
|
||||
return UCLI_STATUS_E_ERROR;
|
||||
}
|
||||
onlp_oid_hdr_t hdr;
|
||||
if(ONLP_FAILURE(rv = onlp_oid_hdr_from_json(cj, &hdr))) {
|
||||
ucli_printf(uc, "hdr from json failed: %{onlp_status}\n", rv);
|
||||
return UCLI_STATUS_E_ERROR;
|
||||
}
|
||||
cJSON_Delete(cj);
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_oid_hdr_to_json(&hdr, &cj, 0))) {
|
||||
ucli_printf(uc, "hdr to json failed: %{onlp_status}\n", rv);
|
||||
return UCLI_STATUS_E_ERROR;
|
||||
}
|
||||
cjson_util_json_pvs(&uc->pvs, cj);
|
||||
cJSON_Delete(cj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__sfp__inventory__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"inventory", 0,
|
||||
"$summary#Show the SFP inventory.");
|
||||
onlp_sfp_inventory_show(&uc->pvs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__platform__manager__run__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"run", 1,
|
||||
"$summary#Run the platform manager for the given number of seconds."
|
||||
"$args#<seconds>");
|
||||
int seconds;
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "i", &seconds);
|
||||
ucli_printf(uc, "Running the platform manager for %d seconds...\n", seconds);
|
||||
onlp_platform_manager_start(0);
|
||||
aim_sleep_usecs(seconds*1000000);
|
||||
ucli_printf(uc, "Stopping the platform manager...");
|
||||
onlp_platform_manager_stop(1);
|
||||
ucli_printf(uc, "done\n");
|
||||
return UCLI_STATUS_OK;
|
||||
}
|
||||
|
||||
static ucli_status_t
|
||||
onlp_ucli__platform__manager__daemon__(ucli_context_t* uc)
|
||||
{
|
||||
UCLI_COMMAND_INFO(uc,
|
||||
"daemon", 3,
|
||||
"$summary#Start the platform management daemon."
|
||||
"$args#<agent-name> <log-file> <pid-file>");
|
||||
|
||||
char *name, *pid, *log;
|
||||
|
||||
if(onlp_ucli_argv == NULL) {
|
||||
/*
|
||||
* This is not an interactive command. It must be invoked
|
||||
* via the command line tool.
|
||||
*/
|
||||
ucli_printf(uc, "This command cannot be invoked interactively..");
|
||||
return UCLI_STATUS_E_ERROR;
|
||||
}
|
||||
|
||||
UCLI_ARGPARSE_OR_RETURN(uc, "sss", &name, &log, &pid);
|
||||
onlp_platform_manager_daemon(name, log, pid, onlp_ucli_argv);
|
||||
|
||||
/* We should never get here. */
|
||||
ucli_printf(uc, "platform manager daemon has failed.");
|
||||
return UCLI_STATUS_E_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
/* <auto.ucli.handlers.start> */
|
||||
/******************************************************************************
|
||||
*
|
||||
@@ -44,31 +397,239 @@ onlp_ucli_ucli__config__(ucli_context_t* uc)
|
||||
* source file.
|
||||
*
|
||||
*****************************************************************************/
|
||||
static ucli_command_handler_f onlp_ucli_ucli_handlers__[] =
|
||||
ucli_node_t* onlp_ucli__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__debug__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__debug__oid__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__debug__oid__verify__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__debug__oid__verify__verify__handlers__[] =
|
||||
{
|
||||
onlp_ucli_ucli__config__,
|
||||
onlp_ucli__debug__oid__verify__json__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__debug__oid__verify__verify__module__ =
|
||||
{
|
||||
"verify",
|
||||
NULL,
|
||||
onlp_ucli__debug__oid__verify__verify__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__debug__oid__from__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__debug__oid__from__from__handlers__[] =
|
||||
{
|
||||
onlp_ucli__debug__oid__from__json__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__debug__oid__from__from__module__ =
|
||||
{
|
||||
"from",
|
||||
NULL,
|
||||
onlp_ucli__debug__oid__from__from__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__debug__oid__to__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__debug__oid__to__to__handlers__[] =
|
||||
{
|
||||
onlp_ucli__debug__oid__to__json__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__debug__oid__to__to__module__ =
|
||||
{
|
||||
"to",
|
||||
NULL,
|
||||
onlp_ucli__debug__oid__to__to__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__platform__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__platform__manager__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__platform__manager__manager__handlers__[] =
|
||||
{
|
||||
onlp_ucli__platform__manager__run__,
|
||||
onlp_ucli__platform__manager__daemon__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__platform__manager__manager__module__ =
|
||||
{
|
||||
"manager",
|
||||
NULL,
|
||||
onlp_ucli__platform__manager__manager__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__chassis__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__chassis__attribute__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__chassis__attribute__onie__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__chassis__attribute__onie__onie__handlers__[] =
|
||||
{
|
||||
onlp_ucli__chassis__attribute__onie__get__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__chassis__attribute__onie__onie__module__ =
|
||||
{
|
||||
"onie",
|
||||
NULL,
|
||||
onlp_ucli__chassis__attribute__onie__onie__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__chassis__attribute__asset__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__chassis__attribute__asset__asset__handlers__[] =
|
||||
{
|
||||
onlp_ucli__chassis__attribute__asset__get__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__chassis__attribute__asset__asset__module__ =
|
||||
{
|
||||
"asset",
|
||||
NULL,
|
||||
onlp_ucli__chassis__attribute__asset__asset__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
static ucli_command_handler_f onlp_ucli__chassis__chassis__handlers__[] =
|
||||
{
|
||||
onlp_ucli__chassis__environment__,
|
||||
onlp_ucli__chassis__dump__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__chassis__chassis__module__ =
|
||||
{
|
||||
"chassis",
|
||||
NULL,
|
||||
onlp_ucli__chassis__chassis__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__sfp__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__sfp__sfp__handlers__[] =
|
||||
{
|
||||
onlp_ucli__sfp__inventory__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__sfp__sfp__module__ =
|
||||
{
|
||||
"sfp",
|
||||
NULL,
|
||||
onlp_ucli__sfp__sfp__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__oid__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__oid__info__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__oid__info__info__handlers__[] =
|
||||
{
|
||||
onlp_ucli__oid__info__all__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__oid__info__info__module__ =
|
||||
{
|
||||
"info",
|
||||
NULL,
|
||||
onlp_ucli__oid__info__info__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
ucli_node_t* onlp_ucli__oid__hdr__node__ = NULL;
|
||||
ucli_node_t* onlp_ucli__oid__hdr__json__node__ = NULL;
|
||||
static ucli_command_handler_f onlp_ucli__oid__hdr__json__json__handlers__[] =
|
||||
{
|
||||
onlp_ucli__oid__hdr__json__id__,
|
||||
onlp_ucli__oid__hdr__json__file__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__oid__hdr__json__json__module__ =
|
||||
{
|
||||
"json",
|
||||
NULL,
|
||||
onlp_ucli__oid__hdr__json__json__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
static ucli_command_handler_f onlp_ucli__oid__hdr__hdr__handlers__[] =
|
||||
{
|
||||
onlp_ucli__oid__hdr__all__,
|
||||
NULL
|
||||
};
|
||||
static ucli_module_t onlp_ucli__oid__hdr__hdr__module__ =
|
||||
{
|
||||
"hdr",
|
||||
NULL,
|
||||
onlp_ucli__oid__hdr__hdr__handlers__,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
static ucli_node_t* __ucli_auto_init__(void)
|
||||
{
|
||||
if(onlp_ucli__node__ == NULL) onlp_ucli__node__ = ucli_node_create("onlp", NULL, NULL);
|
||||
if(onlp_ucli__debug__node__ == NULL) onlp_ucli__debug__node__ = ucli_node_create("debug", NULL, NULL);
|
||||
if(onlp_ucli__debug__oid__node__ == NULL) onlp_ucli__debug__oid__node__ = ucli_node_create("oid", NULL, NULL);
|
||||
if(onlp_ucli__debug__oid__verify__node__ == NULL) onlp_ucli__debug__oid__verify__node__ = ucli_node_create("verify", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__debug__oid__verify__verify__module__);
|
||||
if(onlp_ucli__debug__oid__from__node__ == NULL) onlp_ucli__debug__oid__from__node__ = ucli_node_create("from", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__debug__oid__from__from__module__);
|
||||
if(onlp_ucli__debug__oid__to__node__ == NULL) onlp_ucli__debug__oid__to__node__ = ucli_node_create("to", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__debug__oid__to__to__module__);
|
||||
if(onlp_ucli__platform__node__ == NULL) onlp_ucli__platform__node__ = ucli_node_create("platform", NULL, NULL);
|
||||
if(onlp_ucli__platform__manager__node__ == NULL) onlp_ucli__platform__manager__node__ = ucli_node_create("manager", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__platform__manager__manager__module__);
|
||||
if(onlp_ucli__chassis__node__ == NULL) onlp_ucli__chassis__node__ = ucli_node_create("chassis", NULL, NULL);
|
||||
if(onlp_ucli__chassis__attribute__node__ == NULL) onlp_ucli__chassis__attribute__node__ = ucli_node_create("attribute", NULL, NULL);
|
||||
if(onlp_ucli__chassis__attribute__onie__node__ == NULL) onlp_ucli__chassis__attribute__onie__node__ = ucli_node_create("onie", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__chassis__attribute__onie__onie__module__);
|
||||
if(onlp_ucli__chassis__attribute__asset__node__ == NULL) onlp_ucli__chassis__attribute__asset__node__ = ucli_node_create("asset", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__chassis__attribute__asset__asset__module__);
|
||||
ucli_module_init(&onlp_ucli__chassis__chassis__module__);
|
||||
if(onlp_ucli__sfp__node__ == NULL) onlp_ucli__sfp__node__ = ucli_node_create("sfp", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__sfp__sfp__module__);
|
||||
if(onlp_ucli__oid__node__ == NULL) onlp_ucli__oid__node__ = ucli_node_create("oid", NULL, NULL);
|
||||
if(onlp_ucli__oid__info__node__ == NULL) onlp_ucli__oid__info__node__ = ucli_node_create("info", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__oid__info__info__module__);
|
||||
if(onlp_ucli__oid__hdr__node__ == NULL) onlp_ucli__oid__hdr__node__ = ucli_node_create("hdr", NULL, NULL);
|
||||
if(onlp_ucli__oid__hdr__json__node__ == NULL) onlp_ucli__oid__hdr__json__node__ = ucli_node_create("json", NULL, NULL);
|
||||
ucli_module_init(&onlp_ucli__oid__hdr__json__json__module__);
|
||||
ucli_module_init(&onlp_ucli__oid__hdr__hdr__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__node__, onlp_ucli__debug__node__);
|
||||
ucli_node_subnode_add(onlp_ucli__debug__node__, onlp_ucli__debug__oid__node__);
|
||||
ucli_node_subnode_add(onlp_ucli__debug__oid__node__, onlp_ucli__debug__oid__verify__node__);
|
||||
ucli_node_module_add(onlp_ucli__debug__oid__verify__node__, &onlp_ucli__debug__oid__verify__verify__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__debug__oid__node__, onlp_ucli__debug__oid__from__node__);
|
||||
ucli_node_module_add(onlp_ucli__debug__oid__from__node__, &onlp_ucli__debug__oid__from__from__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__debug__oid__node__, onlp_ucli__debug__oid__to__node__);
|
||||
ucli_node_module_add(onlp_ucli__debug__oid__to__node__, &onlp_ucli__debug__oid__to__to__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__node__, onlp_ucli__platform__node__);
|
||||
ucli_node_subnode_add(onlp_ucli__platform__node__, onlp_ucli__platform__manager__node__);
|
||||
ucli_node_module_add(onlp_ucli__platform__manager__node__, &onlp_ucli__platform__manager__manager__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__node__, onlp_ucli__chassis__node__);
|
||||
ucli_node_subnode_add(onlp_ucli__chassis__node__, onlp_ucli__chassis__attribute__node__);
|
||||
ucli_node_subnode_add(onlp_ucli__chassis__attribute__node__, onlp_ucli__chassis__attribute__onie__node__);
|
||||
ucli_node_module_add(onlp_ucli__chassis__attribute__onie__node__, &onlp_ucli__chassis__attribute__onie__onie__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__chassis__attribute__node__, onlp_ucli__chassis__attribute__asset__node__);
|
||||
ucli_node_module_add(onlp_ucli__chassis__attribute__asset__node__, &onlp_ucli__chassis__attribute__asset__asset__module__);
|
||||
ucli_node_module_add(onlp_ucli__chassis__node__, &onlp_ucli__chassis__chassis__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__node__, onlp_ucli__sfp__node__);
|
||||
ucli_node_module_add(onlp_ucli__sfp__node__, &onlp_ucli__sfp__sfp__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__node__, onlp_ucli__oid__node__);
|
||||
ucli_node_subnode_add(onlp_ucli__oid__node__, onlp_ucli__oid__info__node__);
|
||||
ucli_node_module_add(onlp_ucli__oid__info__node__, &onlp_ucli__oid__info__info__module__);
|
||||
ucli_node_subnode_add(onlp_ucli__oid__node__, onlp_ucli__oid__hdr__node__);
|
||||
ucli_node_subnode_add(onlp_ucli__oid__hdr__node__, onlp_ucli__oid__hdr__json__node__);
|
||||
ucli_node_module_add(onlp_ucli__oid__hdr__json__node__, &onlp_ucli__oid__hdr__json__json__module__);
|
||||
ucli_node_module_add(onlp_ucli__oid__hdr__node__, &onlp_ucli__oid__hdr__hdr__module__);
|
||||
return onlp_ucli__node__;
|
||||
}
|
||||
/******************************************************************************/
|
||||
/* <auto.ucli.handlers.end> */
|
||||
|
||||
static ucli_module_t
|
||||
onlp_ucli_module__ =
|
||||
{
|
||||
"onlp_ucli",
|
||||
NULL,
|
||||
onlp_ucli_ucli_handlers__,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
ucli_node_t*
|
||||
onlp_ucli_node_create(void)
|
||||
{
|
||||
ucli_node_t* n;
|
||||
ucli_module_init(&onlp_ucli_module__);
|
||||
n = ucli_node_create("onlp", NULL, &onlp_ucli_module__);
|
||||
ucli_node_subnode_add(n, ucli_module_log_node_create("onlp"));
|
||||
static ucli_node_t* n = NULL;
|
||||
if(n) {
|
||||
return NULL;
|
||||
}
|
||||
n = __ucli_auto_init__();
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -79,4 +640,3 @@ onlp_ucli_node_create(void)
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -69,3 +69,117 @@ onlp_oid_show_state_missing(iof_t* iof)
|
||||
{
|
||||
iof_iprintf(iof, "State: Missing");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initial JSON object when serializing an info structure.
|
||||
*/
|
||||
int
|
||||
onlp_info_to_json_create(onlp_oid_hdr_t* hdr, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
cJSON* cj_hdr;
|
||||
if(ONLP_FAILURE(rv = onlp_oid_hdr_to_json(hdr, &cj_hdr, flags))) {
|
||||
return rv;
|
||||
}
|
||||
cJSON* cj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(cj, "hdr", cj_hdr);
|
||||
*cjp = cj;
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
onlp_info_to_user_json_create(onlp_oid_hdr_t* hdr, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
cJSON* object = cJSON_CreateObject();
|
||||
cjson_util_add_string_to_object(object, "Description", hdr->description[0] ? hdr->description : "None");
|
||||
|
||||
if(hdr->status & ONLP_OID_STATUS_FLAG_PRESENT) {
|
||||
cjson_util_add_string_to_object(object, "State", "Present");
|
||||
|
||||
char* status = "Unknown";
|
||||
if(hdr->status & ONLP_OID_STATUS_FLAG_UNPLUGGED) {
|
||||
status = "Unplugged";
|
||||
rv = 0;
|
||||
}
|
||||
else if(hdr->status & ONLP_OID_STATUS_FLAG_FAILED) {
|
||||
switch(ONLP_OID_TYPE_GET(hdr->id))
|
||||
{
|
||||
case ONLP_OID_TYPE_PSU: status = "Failed or Unplugged."; break;
|
||||
default: status = "Failed"; break;
|
||||
}
|
||||
rv = 0;
|
||||
}
|
||||
else {
|
||||
switch(ONLP_OID_TYPE_GET(hdr->id))
|
||||
{
|
||||
case ONLP_OID_TYPE_CHASSIS:
|
||||
case ONLP_OID_TYPE_THERMAL:
|
||||
status = "Functional"; break;
|
||||
default:
|
||||
status = "Running"; break;
|
||||
}
|
||||
rv = 1;
|
||||
}
|
||||
cjson_util_add_string_to_object(object, "Status", status);
|
||||
}
|
||||
else {
|
||||
cjson_util_add_string_to_object(object, "State", "Missing");
|
||||
rv = 0;
|
||||
}
|
||||
|
||||
*cjp = object;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_info_to_user_json_finish(onlp_oid_hdr_t* hdr, cJSON* object, cJSON** cjp,
|
||||
uint32_t flags)
|
||||
{
|
||||
char name[64];
|
||||
onlp_oid_to_user_str(hdr->id, name);
|
||||
if(*cjp) {
|
||||
cJSON_AddItemToObject(*cjp, name, object);
|
||||
}
|
||||
else {
|
||||
*cjp = object;
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_JSON_FLAG_RECURSIVE) {
|
||||
onlp_oid_t* oidp;
|
||||
ONLP_OID_TABLE_ITER(hdr->coids, oidp) {
|
||||
onlp_oid_to_user_json(*oidp, &object, flags);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
onlp_info_to_json_finish(onlp_oid_hdr_t* hdr, cJSON* object, cJSON** cjp,
|
||||
uint32_t flags)
|
||||
{
|
||||
char name[64];
|
||||
onlp_oid_to_str(hdr->id, name);
|
||||
|
||||
if(flags & ONLP_OID_JSON_FLAG_RECURSIVE) {
|
||||
onlp_oid_t* oidp;
|
||||
cJSON* children = cJSON_CreateObject();
|
||||
ONLP_OID_TABLE_ITER(hdr->coids, oidp) {
|
||||
onlp_oid_to_json(*oidp, &children, flags);
|
||||
}
|
||||
if(cJSON_GetArraySize(children) > 0) {
|
||||
cJSON_AddItemToObject(object, "coids", children);
|
||||
}
|
||||
else {
|
||||
cJSON_Delete(children);
|
||||
}
|
||||
}
|
||||
|
||||
if(*cjp) {
|
||||
cJSON_AddItemToObject(*cjp, name, object);
|
||||
}
|
||||
else {
|
||||
*cjp = object;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
206
packages/base/any/onlp/src/onlp/module/src/platform.c
Normal file
206
packages/base/any/onlp/src/onlp/module/src/platform.c
Normal file
@@ -0,0 +1,206 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platform.h>
|
||||
#include <onlp/platformi/platformi.h>
|
||||
|
||||
#include <AIM/aim.h>
|
||||
#include <AIM/aim_daemon.h>
|
||||
|
||||
#include "onlp_log.h"
|
||||
#include "onlp_int.h"
|
||||
#include "onlp_locks.h"
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
/**
|
||||
* @brief Determine the platform name from the filesystem.
|
||||
*/
|
||||
static char*
|
||||
platform_detect_fs__(void)
|
||||
{
|
||||
/*
|
||||
* Check the filesystem for the platform identifier.
|
||||
*/
|
||||
char* rv = NULL;
|
||||
if(ONLP_CONFIG_PLATFORM_FILENAME) {
|
||||
FILE* fp;
|
||||
if((fp=fopen(ONLP_CONFIG_PLATFORM_FILENAME, "r"))) {
|
||||
char platform[256];
|
||||
if(fgets(platform, sizeof(platform), fp) == platform) {
|
||||
if(platform[0]) {
|
||||
if(platform[ONLP_STRLEN(platform)-1] == '\n') {
|
||||
platform[ONLP_STRLEN(platform)-1] = 0;
|
||||
}
|
||||
rv = aim_strdup(platform);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
else {
|
||||
AIM_LOG_ERROR("could not open platform filename '%s'", ONLP_CONFIG_PLATFORM_FILENAME);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static char*
|
||||
onlp_platform_name_get__(const char* override)
|
||||
{
|
||||
if(override) {
|
||||
return aim_strdup(override);
|
||||
}
|
||||
|
||||
if(getenv("ONLP_CONFIG_PLATFORM_NAME")) {
|
||||
return aim_strdup(getenv("ONLP_CONFIG_PLATFORM_NAME"));
|
||||
}
|
||||
|
||||
if(ONLP_CONFIG_PLATFORM_NAME) {
|
||||
/** Set at compile time. */
|
||||
return aim_strdup(ONLP_CONFIG_PLATFORM_NAME);
|
||||
}
|
||||
return platform_detect_fs__();
|
||||
}
|
||||
|
||||
char*
|
||||
onlp_platform_name_get(void)
|
||||
{
|
||||
return onlp_platform_name_get__(NULL);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_platform_sw_init_locked__(const char* platform)
|
||||
{
|
||||
int rv;
|
||||
platform = onlp_platform_name_get__(platform);
|
||||
if(platform == NULL) {
|
||||
AIM_DIE("Could not determine the current platform.");
|
||||
}
|
||||
|
||||
const char* driver = onlp_platformi_get();
|
||||
|
||||
if( (driver == NULL) ||
|
||||
strcmp(driver, platform) ) {
|
||||
/**
|
||||
* The platform name and the driver name do not match.
|
||||
* Request the current platform explicitly.
|
||||
*/
|
||||
if(ONLP_FAILURE(rv = onlp_platformi_set(platform))) {
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
AIM_LOG_ERROR("The current platform interface (%s) does not support the current platform (%s). This is fatal.",
|
||||
driver, platform);
|
||||
}
|
||||
else {
|
||||
AIM_LOG_ERROR("onlp_platformi_set(%s) failed: %{onlp_status}",
|
||||
platform, rv);
|
||||
}
|
||||
aim_free((void*)platform);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we get here, its all good */
|
||||
aim_free((void*)platform);
|
||||
|
||||
rv = onlp_platformi_sw_init();
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_platform_sw_init, const char*, platform);
|
||||
|
||||
|
||||
int
|
||||
onlp_platform_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
return onlp_platformi_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_platform_hw_init, uint32_t, flags);
|
||||
|
||||
int
|
||||
onlp_platform_sw_denit_locked__(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_platform_sw_denit);
|
||||
|
||||
static void
|
||||
daemon_sighandler__(int signal)
|
||||
{
|
||||
onlp_platform_manager_stop(0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
onlp_platform_manager_daemon(const char* name,
|
||||
const char* logfile,
|
||||
const char* pidfile,
|
||||
char** argv)
|
||||
{
|
||||
aim_pvs_t* aim_pvs_syslog = NULL;
|
||||
aim_daemon_restart_config_t rconfig;
|
||||
aim_daemon_config_t config;
|
||||
|
||||
memset(&config, 0, sizeof(config));
|
||||
aim_daemon_restart_config_init(&rconfig, 1, 1, argv);
|
||||
AIM_BITMAP_CLR(&rconfig.signal_restarts, SIGTERM);
|
||||
AIM_BITMAP_CLR(&rconfig.exit_restarts, 0);
|
||||
rconfig.maximum_restarts=50;
|
||||
rconfig.pvs = NULL;
|
||||
config.wd = "/";
|
||||
|
||||
aim_daemonize(&config, &rconfig);
|
||||
aim_log_handler_basic_init_all(name,
|
||||
logfile,
|
||||
1024*1024,
|
||||
99);
|
||||
if(pidfile) {
|
||||
FILE* fp = fopen(pidfile, "w");
|
||||
if(fp == NULL) {
|
||||
int e = errno;
|
||||
aim_printf(aim_pvs_syslog, "fatal: open(%s): %s\n",
|
||||
pidfile, strerror(e));
|
||||
aim_printf(&aim_pvs_stderr, "fatal: open(%s): %s\n",
|
||||
pidfile, strerror(e));
|
||||
|
||||
/* Don't attempt restart */
|
||||
raise(SIGTERM);
|
||||
}
|
||||
fprintf(fp, "%d\n", getpid());
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/** Signal handler for terminating the platform manager */
|
||||
signal(SIGTERM, daemon_sighandler__);
|
||||
|
||||
/** Start and block in platform manager. */
|
||||
onlp_platform_manager_start(1);
|
||||
|
||||
/** Terminated via signal. Cleanup and exit. */
|
||||
onlp_platform_manager_stop(1);
|
||||
|
||||
aim_log_handler_basic_denit_all();
|
||||
exit(0);
|
||||
}
|
||||
@@ -22,10 +22,9 @@
|
||||
* This file implements the Platform Management infrastructure.
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/sys.h>
|
||||
#include <onlp/psu.h>
|
||||
#include <onlp/fan.h>
|
||||
#include <onlp/platformi/sysi.h>
|
||||
#include <onlp/platformi/platformi.h>
|
||||
#include <onlplib/mmap.h>
|
||||
#include <timer_wheel/timer_wheel.h>
|
||||
#include <OS/os_time.h>
|
||||
@@ -97,14 +96,14 @@ static management_entry_t management_entries[] =
|
||||
{
|
||||
{
|
||||
{ },
|
||||
onlp_sysi_platform_manage_fans,
|
||||
onlp_platformi_manage_fans,
|
||||
/* Every 10 seconds */
|
||||
10*1000*1000,
|
||||
"Fans",
|
||||
},
|
||||
{
|
||||
{ },
|
||||
onlp_sysi_platform_manage_leds,
|
||||
onlp_platformi_manage_leds,
|
||||
/* Every 2 seconds */
|
||||
2*1000*1000,
|
||||
"LEDs",
|
||||
@@ -134,7 +133,7 @@ onlp_sys_platform_manage_init(void)
|
||||
int i;
|
||||
uint64_t now = os_time_monotonic();
|
||||
|
||||
onlp_sysi_platform_manage_init();
|
||||
onlp_platformi_manage_init();
|
||||
control__.tw = timer_wheel_create(4, 512, now);
|
||||
|
||||
for(i = 0; i < AIM_ARRAYSIZE(management_entries); i++) {
|
||||
@@ -229,7 +228,7 @@ onlp_sys_platform_manage_thread__(void* vctrl)
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sys_platform_manage_start(int block)
|
||||
onlp_platform_manager_start(int block)
|
||||
{
|
||||
onlp_sys_platform_manage_init();
|
||||
|
||||
@@ -252,14 +251,14 @@ onlp_sys_platform_manage_start(int block)
|
||||
}
|
||||
|
||||
if(block) {
|
||||
onlp_sys_platform_manage_join();
|
||||
onlp_platform_manager_join();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sys_platform_manage_stop(int block)
|
||||
onlp_platform_manager_stop(int block)
|
||||
{
|
||||
if(control__.eventfd > 0) {
|
||||
uint64_t zero = 1;
|
||||
@@ -267,14 +266,14 @@ onlp_sys_platform_manage_stop(int block)
|
||||
write(control__.eventfd, &zero, sizeof(zero));
|
||||
|
||||
if(block) {
|
||||
onlp_sys_platform_manage_join();
|
||||
onlp_platform_manager_join();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sys_platform_manage_join(void)
|
||||
onlp_platform_manager_join(void)
|
||||
{
|
||||
if(control__.eventfd > 0) {
|
||||
/* Wait for the thread to terminate */
|
||||
@@ -285,205 +284,245 @@ onlp_sys_platform_manage_join(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static onlp_oid_hdr_t*
|
||||
oid_hdr_entry_find__(biglist_t* list, onlp_oid_t oid)
|
||||
{
|
||||
onlp_oid_hdr_t* hdr;
|
||||
biglist_t* ble;
|
||||
|
||||
BIGLIST_FOREACH_DATA(ble, list, onlp_oid_hdr_t*, hdr) {
|
||||
if(hdr->id == oid) {
|
||||
return hdr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
platform_psus_notify__(void)
|
||||
{
|
||||
static onlp_oid_t psu_oid_table[ONLP_OID_TABLE_SIZE] = {0};
|
||||
static onlp_psu_info_t psu_info_table[ONLP_OID_TABLE_SIZE];
|
||||
int i = 0;
|
||||
static int flag[ONLP_OID_TABLE_SIZE] = {0};
|
||||
int rv;
|
||||
static biglist_t* previous = NULL;
|
||||
static biglist_t* current = NULL;
|
||||
|
||||
if(psu_oid_table[0] == 0) {
|
||||
/* We haven't retreived the system PSU oids yet. */
|
||||
onlp_sys_info_t si;
|
||||
onlp_oid_t* oidp;
|
||||
biglist_t* ble;
|
||||
onlp_oid_hdr_t* hdr;
|
||||
|
||||
if(onlp_sys_info_get(&si) < 0) {
|
||||
AIM_LOG_ERROR("onlp_sys_info_get() failed.");
|
||||
return -1;
|
||||
}
|
||||
ONLP_OID_TABLE_ITER_TYPE(si.hdr.coids, oidp, PSU) {
|
||||
psu_oid_table[i++] = *oidp;
|
||||
}
|
||||
if(ONLP_FAILURE(rv = onlp_oid_hdr_get_all(ONLP_OID_CHASSIS,
|
||||
ONLP_OID_TYPE_FLAG_PSU, 0x0,
|
||||
¤t))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
for(i = 0; i < AIM_ARRAYSIZE(psu_oid_table); i++) {
|
||||
onlp_psu_info_t pi;
|
||||
int pid = ONLP_OID_ID_GET(psu_oid_table[i]);
|
||||
if(previous == NULL) {
|
||||
/** Log initial states. */
|
||||
BIGLIST_FOREACH_DATA(ble, current, onlp_oid_hdr_t*, hdr) {
|
||||
int pid = ONLP_OID_ID_GET(hdr->id);
|
||||
|
||||
if(psu_oid_table[i] == 0) {
|
||||
break;
|
||||
}
|
||||
if(ONLP_OID_PRESENT(hdr)) {
|
||||
AIM_SYSLOG_INFO("PSU <id> is present.",
|
||||
"The given PSU is present.",
|
||||
"PSU %d is present.", pid);
|
||||
|
||||
if(onlp_psu_info_get(psu_oid_table[i], &pi) < 0) {
|
||||
AIM_LOG_ERROR("Failure retreiving status of PSU ID %d",
|
||||
pid);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* report initial failed state */
|
||||
if ( !flag[i] ) {
|
||||
if ( !(pi.status & 0x1) ) {
|
||||
AIM_SYSLOG_WARN("PSU <id> is not present.",
|
||||
if(ONLP_OID_FAILED(hdr)) {
|
||||
AIM_SYSLOG_CRIT("PSU <id> has failed.",
|
||||
"The given PSU has failed.",
|
||||
"PSU %d has failed.", pid);
|
||||
}
|
||||
else if(ONLP_OID_STATUS_FLAG_IS_SET(hdr, UNPLUGGED)) {
|
||||
AIM_SYSLOG_WARN("PSU <id> is unplugged.",
|
||||
"The given PSU is unplugged.",
|
||||
"PSU %d is unplugged.", pid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
AIM_SYSLOG_INFO("PSU <id> is not present.",
|
||||
"The given PSU is not present.",
|
||||
"PSU %d is not present.", pid);
|
||||
}
|
||||
if ( pi.status & ONLP_PSU_STATUS_FAILED ) {
|
||||
AIM_SYSLOG_CRIT("PSU <id> has failed.",
|
||||
"The given PSU has failed.",
|
||||
"PSU %d has failed.", pid);
|
||||
}
|
||||
if ((pi.status & 0x01) && !(pi.status & ONLP_PSU_STATUS_FAILED) && (pi.status & ONLP_PSU_STATUS_UNPLUGGED)) {
|
||||
AIM_SYSLOG_WARN("PSU <id> power cord not plugged.",
|
||||
"The given PSU does not have power cord plugged.",
|
||||
"PSU %d power cord not plugged.", pid);
|
||||
}
|
||||
flag[i] = 1;
|
||||
}
|
||||
previous = current;
|
||||
current = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BIGLIST_FOREACH_DATA(ble, current, onlp_oid_hdr_t*, hdr) {
|
||||
|
||||
int pid = ONLP_OID_ID_GET(hdr->id);
|
||||
onlp_oid_hdr_t* phdr = oid_hdr_entry_find__(previous, hdr->id);
|
||||
|
||||
if(!phdr) {
|
||||
/* A new PSU has popped into existance. Unlikely. */
|
||||
AIM_SYSLOG_INFO("PSU <id> has been discovered.",
|
||||
"A new PSU has been discovered.",
|
||||
"PSU %d has been discovered.", pid);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Log any presences or failure transitions.
|
||||
*/
|
||||
if(pi.status != psu_info_table[i].status) {
|
||||
uint32_t new = pi.status;
|
||||
uint32_t old = psu_info_table[i].status;
|
||||
uint32_t xor = hdr->status ^ phdr->status;
|
||||
|
||||
if( !(old & 0x1) && (new & 0x1) ) {
|
||||
/* PSU Inserted */
|
||||
if(xor & ONLP_OID_STATUS_FLAG_PRESENT) {
|
||||
if(ONLP_OID_PRESENT(hdr)) {
|
||||
AIM_SYSLOG_INFO("PSU <id> has been inserted.",
|
||||
"A PSU has been inserted in the given slot.",
|
||||
"PSU %d has been inserted.", pid);
|
||||
}
|
||||
if( (old & 0x1) && !(new & 0x1) ) {
|
||||
/* PSU Removed */
|
||||
else {
|
||||
AIM_SYSLOG_WARN("PSU <id> has been removed.",
|
||||
"A PSU has been removed from the given slot.",
|
||||
"PSU %d has been removed.", pid);
|
||||
/* The remaining bits are only relevant if the PSU is present. */
|
||||
continue;
|
||||
}
|
||||
if( (new & 0x1) && (old & ONLP_PSU_STATUS_FAILED) && !(new & ONLP_PSU_STATUS_FAILED) ) {
|
||||
/* PSU recovery (seems unlikely) */
|
||||
AIM_SYSLOG_INFO("PSU <id> has recovered.",
|
||||
"The given PSU has recovered from a failure.",
|
||||
"PSU %d has recovered.", pid);
|
||||
}
|
||||
|
||||
if( !(old & ONLP_PSU_STATUS_FAILED) && (new & ONLP_PSU_STATUS_FAILED) ) {
|
||||
/* PSU Failure */
|
||||
}
|
||||
if(xor & ONLP_OID_STATUS_FLAG_FAILED) {
|
||||
if(ONLP_OID_FAILED(hdr)) {
|
||||
AIM_SYSLOG_CRIT("PSU <id> has failed.",
|
||||
"The given PSU has failed.",
|
||||
"PSU %d has failed.", pid);
|
||||
}
|
||||
|
||||
if(!(new & ONLP_PSU_STATUS_FAILED) && (new & ONLP_PSU_STATUS_PRESENT)) {
|
||||
if( (old & ONLP_PSU_STATUS_UNPLUGGED) && !(new & ONLP_PSU_STATUS_UNPLUGGED)) {
|
||||
/* PSU has been plugged in */
|
||||
AIM_SYSLOG_INFO("PSU <id> has been plugged in.",
|
||||
"The given PSU has been plugged in.",
|
||||
"PSU %d has been plugged in.", pid);
|
||||
}
|
||||
|
||||
if(!(old & ONLP_PSU_STATUS_UNPLUGGED) && (new & ONLP_PSU_STATUS_UNPLUGGED)) {
|
||||
/* PSU has been unplugged. */
|
||||
AIM_SYSLOG_WARN("PSU <id> has been unplugged.",
|
||||
"The given PSU has been unplugged.",
|
||||
"PSU %d has been unplugged.", pid);
|
||||
}
|
||||
else {
|
||||
AIM_SYSLOG_INFO("PSU <id> has recovered.",
|
||||
"The given PSU has recovered from a failure.",
|
||||
"PSU %d has recovered.", pid);
|
||||
}
|
||||
}
|
||||
if(xor & ONLP_OID_STATUS_FLAG_UNPLUGGED) {
|
||||
if(ONLP_OID_STATUS_FLAG_IS_SET(hdr, UNPLUGGED)) {
|
||||
/* PSU has been unplugged. */
|
||||
AIM_SYSLOG_WARN("PSU <id> has been unplugged.",
|
||||
"The given PSU has been unplugged.",
|
||||
"PSU %d has been unplugged.", pid);
|
||||
}
|
||||
else {
|
||||
/* PSU has been plugged in */
|
||||
AIM_SYSLOG_INFO("PSU <id> has been plugged in.",
|
||||
"The given PSU has been plugged in.",
|
||||
"PSU %d has been plugged in.", pid);
|
||||
}
|
||||
|
||||
memcpy(psu_info_table+i, &pi, sizeof(pi));
|
||||
}
|
||||
}
|
||||
|
||||
BIGLIST_FOREACH_DATA(ble, previous, onlp_oid_hdr_t*, hdr) {
|
||||
onlp_oid_hdr_t* chdr = oid_hdr_entry_find__(current, hdr->id);
|
||||
if(!chdr) {
|
||||
/* A PSU has disappeared. */
|
||||
AIM_SYSLOG_INFO("PSU <id> has disappeared.",
|
||||
"A PSU has disappeared.",
|
||||
"PSU %d has disappeared.", ONLP_OID_ID_GET(hdr->id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* The previous list is deleted and the current list becomes the previous */
|
||||
onlp_oid_get_all_free(previous);
|
||||
previous = current;
|
||||
current = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
platform_fans_notify__(void)
|
||||
{
|
||||
static onlp_oid_t fan_oid_table[ONLP_OID_TABLE_SIZE] = {0};
|
||||
static onlp_fan_info_t fan_info_table[ONLP_OID_TABLE_SIZE];
|
||||
int i = 0;
|
||||
static int flag[ONLP_OID_TABLE_SIZE] = {0};
|
||||
int rv;
|
||||
static biglist_t* previous = NULL;
|
||||
static biglist_t* current = NULL;
|
||||
|
||||
if(fan_oid_table[0] == 0) {
|
||||
/* We haven't retreived the system FAN oids yet. */
|
||||
onlp_sys_info_t si;
|
||||
onlp_oid_t* oidp;
|
||||
biglist_t* ble;
|
||||
onlp_oid_hdr_t* hdr;
|
||||
|
||||
if(onlp_sys_info_get(&si) < 0) {
|
||||
AIM_LOG_ERROR("onlp_sys_info_get() failed.");
|
||||
return -1;
|
||||
}
|
||||
ONLP_OID_TABLE_ITER_TYPE(si.hdr.coids, oidp, FAN) {
|
||||
fan_oid_table[i++] = *oidp;
|
||||
}
|
||||
if(ONLP_FAILURE(rv = onlp_oid_hdr_get_all(ONLP_OID_CHASSIS,
|
||||
ONLP_OID_TYPE_FLAG_FAN, 0x0,
|
||||
¤t))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
for(i = 0; i < AIM_ARRAYSIZE(fan_oid_table); i++) {
|
||||
onlp_fan_info_t fi;
|
||||
int fid = ONLP_OID_ID_GET(fan_oid_table[i]);
|
||||
if(previous == NULL) {
|
||||
/** Log initial states. */
|
||||
BIGLIST_FOREACH_DATA(ble, current, onlp_oid_hdr_t*, hdr) {
|
||||
int fid = ONLP_OID_ID_GET(hdr->id);
|
||||
|
||||
if(fan_oid_table[i] == 0) {
|
||||
break;
|
||||
if(ONLP_OID_PRESENT(hdr)) {
|
||||
AIM_SYSLOG_INFO("Fan <id> is present.",
|
||||
"The given fan is present.",
|
||||
"Fan %d is present.", fid);
|
||||
|
||||
if(ONLP_OID_FAILED(hdr)) {
|
||||
AIM_SYSLOG_INFO("Fan <id> has failed.",
|
||||
"The given fan has failed.",
|
||||
"Fan %d has failed.", fid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
AIM_SYSLOG_INFO("Fan <id> is not present.",
|
||||
"The given fan is not present.",
|
||||
"Fan %d is not present.", fid);
|
||||
}
|
||||
}
|
||||
previous = current;
|
||||
current = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(onlp_fan_info_get(fan_oid_table[i], &fi) < 0) {
|
||||
AIM_LOG_ERROR("Failure retreiving status of FAN ID %d",
|
||||
fid);
|
||||
|
||||
BIGLIST_FOREACH_DATA(ble, current, onlp_oid_hdr_t*, hdr) {
|
||||
|
||||
int fid = ONLP_OID_ID_GET(hdr->id);
|
||||
onlp_oid_hdr_t* phdr = oid_hdr_entry_find__(previous, hdr->id);
|
||||
|
||||
if(!phdr) {
|
||||
/* A new Fan has popped into existance. Unlikely. */
|
||||
AIM_SYSLOG_INFO("Fan <id> has been discovered.",
|
||||
"A new fan has been discovered.",
|
||||
"Fan %d has been discovered.", fid);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* report initial failed state */
|
||||
if ( !flag[i] ) {
|
||||
if ( !(fi.status & 0x1) ) {
|
||||
AIM_SYSLOG_WARN("Fan <id> is not present.",
|
||||
"The given Fan is not present.",
|
||||
"Fan %d is not present.", fid);
|
||||
}
|
||||
if ( fi.status & ONLP_FAN_STATUS_FAILED ) {
|
||||
AIM_SYSLOG_CRIT("Fan <id> has failed.",
|
||||
"The given fan has failed.",
|
||||
"Fan %d has failed.", fid);
|
||||
}
|
||||
flag[i] = 1;
|
||||
}
|
||||
uint32_t xor = hdr->status ^ phdr->status;
|
||||
|
||||
/*
|
||||
* Log any presences or failure transitions.
|
||||
*/
|
||||
if(fi.status != fan_info_table[i].status) {
|
||||
uint32_t new = fi.status;
|
||||
uint32_t old = fan_info_table[i].status;
|
||||
|
||||
if( !(old & 0x1) && (new & 0x1) ) {
|
||||
/* FAN Inserted */
|
||||
if(xor & ONLP_OID_STATUS_FLAG_PRESENT) {
|
||||
if(ONLP_OID_PRESENT(hdr)) {
|
||||
AIM_SYSLOG_INFO("Fan <id> has been inserted.",
|
||||
"The given Fan has been inserted.",
|
||||
"A fan has been inserted.",
|
||||
"Fan %d has been inserted.", fid);
|
||||
}
|
||||
if( (old & 0x1) && !(new & 0x1) ) {
|
||||
/* FAN Removed */
|
||||
else {
|
||||
AIM_SYSLOG_WARN("Fan <id> has been removed.",
|
||||
"The given Fan has been removed.",
|
||||
"A fan has been removed.",
|
||||
"Fan %d has been removed.", fid);
|
||||
/* The remaining bits are only relevant if the Fan is present. */
|
||||
continue;
|
||||
}
|
||||
if( (old & ONLP_FAN_STATUS_FAILED) && !(new & ONLP_FAN_STATUS_FAILED) ) {
|
||||
AIM_SYSLOG_INFO("Fan <id> has recovered.",
|
||||
"The given Fan has recovered from failure.",
|
||||
"Fan %d has recovered.", fid);
|
||||
}
|
||||
|
||||
if( !(old & ONLP_FAN_STATUS_FAILED) && (new & ONLP_FAN_STATUS_FAILED) ) {
|
||||
/* FAN Failure */
|
||||
}
|
||||
if(xor & ONLP_OID_STATUS_FLAG_FAILED) {
|
||||
if(ONLP_OID_FAILED(hdr)) {
|
||||
AIM_SYSLOG_CRIT("Fan <id> has failed.",
|
||||
"The given fan has failed.",
|
||||
"Fan %d has failed.", fid);
|
||||
}
|
||||
|
||||
memcpy(fan_info_table+i, &fi, sizeof(fi));
|
||||
else {
|
||||
AIM_SYSLOG_INFO("Fan <id> has recovered.",
|
||||
"The given fan has recovered from a failure.",
|
||||
"Fan %d has recovered.", fid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIGLIST_FOREACH_DATA(ble, previous, onlp_oid_hdr_t*, hdr) {
|
||||
onlp_oid_hdr_t* chdr = oid_hdr_entry_find__(current, hdr->id);
|
||||
if(!chdr) {
|
||||
/* A Fan has disappeared. */
|
||||
AIM_SYSLOG_INFO("Fan <id> has disappeared.",
|
||||
"A fan has disappeared.",
|
||||
"Fan %d has disappeared.", ONLP_OID_ID_GET(hdr->id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* The previous list is deleted and the current list becomes the previous */
|
||||
onlp_oid_get_all_free(previous);
|
||||
previous = current;
|
||||
current = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,253 +30,173 @@
|
||||
#include "onlp_int.h"
|
||||
#include "onlp_locks.h"
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_PSU(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define VALIDATENR(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_PSU(_id)) { \
|
||||
return; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static int
|
||||
onlp_psu_sw_init_locked__(void)
|
||||
{
|
||||
return onlp_psui_sw_init();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_psu_sw_init);
|
||||
|
||||
static int
|
||||
onlp_psu_init_locked__(void)
|
||||
onlp_psu_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
return onlp_psui_init();
|
||||
return onlp_psui_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_psu_init);
|
||||
ONLP_LOCKED_API1(onlp_psu_hw_init, uint32_t, flags);
|
||||
|
||||
static int
|
||||
onlp_psu_info_get_locked__(onlp_oid_t id, onlp_psu_info_t* info)
|
||||
onlp_psu_sw_denit_locked__(void)
|
||||
{
|
||||
VALIDATE(id);
|
||||
return onlp_psui_info_get(id, info);
|
||||
return onlp_psui_sw_denit();
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_psu_info_get, onlp_oid_t, id, onlp_psu_info_t*, info);
|
||||
ONLP_LOCKED_API0(onlp_psu_sw_denit);
|
||||
|
||||
static int
|
||||
onlp_psu_status_get_locked__(onlp_oid_t id, uint32_t* status)
|
||||
onlp_psu_hdr_get_locked__(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
int rv = onlp_psui_status_get(id, status);
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_psu_info_t pi;
|
||||
rv = onlp_psui_info_get(id, &pi);
|
||||
*status = pi.status;
|
||||
}
|
||||
return rv;
|
||||
ONLP_OID_PSU_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(hdr);
|
||||
return onlp_psui_hdr_get(oid, hdr);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_psu_status_get, onlp_oid_t, id, uint32_t*, status);
|
||||
ONLP_LOCKED_API2(onlp_psu_hdr_get, onlp_oid_t, oid, onlp_oid_hdr_t*, hdr);
|
||||
|
||||
static int
|
||||
onlp_psu_hdr_get_locked__(onlp_oid_t id, onlp_oid_hdr_t* hdr)
|
||||
onlp_psu_info_get_locked__(onlp_oid_t oid, onlp_psu_info_t* info)
|
||||
{
|
||||
int rv = onlp_psui_hdr_get(id, hdr);
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_psu_info_t pi;
|
||||
rv = onlp_psui_info_get(id, &pi);
|
||||
memcpy(hdr, &pi.hdr, sizeof(pi.hdr));
|
||||
}
|
||||
return rv;
|
||||
ONLP_OID_PSU_VALIDATE(oid);
|
||||
ONLP_PTR_VALIDATE_ZERO(info);
|
||||
return onlp_psui_info_get(oid, info);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_psu_hdr_get, onlp_oid_t, id, onlp_oid_hdr_t*, hdr);
|
||||
int
|
||||
onlp_psu_vioctl_locked__(onlp_oid_t id, va_list vargs)
|
||||
{
|
||||
return onlp_psui_ioctl(id, vargs);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_psu_vioctl, onlp_oid_t, id, va_list, vargs);
|
||||
ONLP_LOCKED_API2(onlp_psu_info_get, onlp_oid_t, oid, onlp_psu_info_t*, info);
|
||||
|
||||
int
|
||||
onlp_psu_ioctl(onlp_oid_t id, ...)
|
||||
{
|
||||
va_list vargs;
|
||||
va_start(vargs, id);
|
||||
int rv = onlp_psu_vioctl(id, vargs);
|
||||
va_end(vargs);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* Debug and Show Functions
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
void
|
||||
onlp_psu_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
onlp_psu_format(onlp_oid_t id, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_psu_info_t info;
|
||||
|
||||
VALIDATENR(id);
|
||||
onlp_oid_dump_iof_init_default(&iof, pvs);
|
||||
|
||||
iof_push(&iof, "psu @ %d", ONLP_OID_ID_GET(id));
|
||||
rv = onlp_psu_info_get(id, &info);
|
||||
if(rv < 0) {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
if(ONLP_SUCCESS(rv = onlp_psu_info_get(id, &info))) {
|
||||
rv = onlp_psu_info_format(&info, format, pvs, flags);
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Description: %s", info.hdr.description);
|
||||
if(info.status & 1) {
|
||||
/* Present */
|
||||
iof_iprintf(&iof, "Model: %s", info.model[0] ? info.model : "NULL");
|
||||
iof_iprintf(&iof, "SN: %s", info.serial[0] ? info.serial : "NULL");
|
||||
iof_iprintf(&iof, "Status: %{onlp_psu_status_flags}", info.status);
|
||||
iof_iprintf(&iof, "Caps: %{onlp_psu_caps_flags}", info.caps);
|
||||
iof_iprintf(&iof, "Vin: %d", info.mvin);
|
||||
iof_iprintf(&iof, "Vout: %d", info.mvout);
|
||||
iof_iprintf(&iof, "Iin: %d", info.miin);
|
||||
iof_iprintf(&iof, "Iout: %d", info.miout);
|
||||
iof_iprintf(&iof, "Pin: %d", info.mpin);
|
||||
iof_iprintf(&iof, "Pout: %d", info.mpout);
|
||||
if(flags & ONLP_OID_DUMP_RECURSE) {
|
||||
onlp_oid_table_dump(info.hdr.coids, &iof.inherit, flags);
|
||||
}
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Not present.");
|
||||
}
|
||||
}
|
||||
iof_pop(&iof);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
onlp_psu_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
int
|
||||
onlp_psu_info_format(onlp_psu_info_t* info,
|
||||
onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
aim_printf(pvs, "%{onlp_oid_hdr} caps=%{onlp_psu_caps_flags}\n",
|
||||
info, info->caps);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psu_info_to_user_json(onlp_psu_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_psu_info_t pi;
|
||||
int yaml;
|
||||
cJSON* object;
|
||||
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
rv = onlp_psu_info_get(id, &pi);
|
||||
rv = onlp_info_to_user_json_create(&info->hdr, &object, flags);
|
||||
if(rv > 0) {
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
if(info->model[0]) {
|
||||
cjson_util_add_string_to_object(object, "Model", info->model);
|
||||
}
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "- ");
|
||||
iof_iprintf(&iof, "Name: PSU %d", ONLP_OID_ID_GET(id));
|
||||
} else {
|
||||
iof_push(&iof, "PSU %d", ONLP_OID_ID_GET(id));
|
||||
if(info->serial[0]) {
|
||||
cjson_util_add_string_to_object(object, "Serial", info->serial);
|
||||
}
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_TYPE)) {
|
||||
cjson_util_add_string_to_object(object, "Type", "%{onlp_psu_type}",
|
||||
info->type);
|
||||
}
|
||||
|
||||
#define _MILLIFIELD(_cap, _name, _field) \
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, _cap)) { \
|
||||
cjson_util_add_string_to_object(object, _name, "%d.%d", \
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(info->_field)); \
|
||||
}
|
||||
|
||||
_MILLIFIELD(GET_VIN, "Vin", mvin);
|
||||
_MILLIFIELD(GET_VOUT, "Vout", mvout);
|
||||
_MILLIFIELD(GET_IIN, "Iin", miin);
|
||||
_MILLIFIELD(GET_IOUT, "Iout", miout);
|
||||
_MILLIFIELD(GET_PIN, "Pin", mpin);
|
||||
_MILLIFIELD(GET_POUT, "Pout", mpout);
|
||||
#undef _MILLIFIELD
|
||||
}
|
||||
|
||||
if(rv < 0) {
|
||||
if(yaml) {
|
||||
iof_iprintf(&iof, "State: Error");
|
||||
iof_iprintf(&iof, "Error: %{onlp_status}", rv);
|
||||
}
|
||||
else {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
}
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_description(&iof, &pi.hdr);
|
||||
if(pi.status & 0x1) {
|
||||
/* Present */
|
||||
iof_iprintf(&iof, "State: Present");
|
||||
if(pi.status & ONLP_PSU_STATUS_UNPLUGGED) {
|
||||
iof_iprintf(&iof, "Status: Unplugged");
|
||||
}
|
||||
else if(pi.status & ONLP_PSU_STATUS_FAILED) {
|
||||
iof_iprintf(&iof, "Status: Unplugged or Failed");
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Status: Running");
|
||||
if(pi.model[0]) iof_iprintf(&iof, "Model: %s", pi.model);
|
||||
if(pi.serial[0]) iof_iprintf(&iof, "SN: %s", pi.serial);
|
||||
if(pi.caps & ONLP_PSU_CAPS_AC) {
|
||||
iof_iprintf(&iof, "Type: AC");
|
||||
}
|
||||
else if(pi.caps & ONLP_PSU_CAPS_DC12) {
|
||||
iof_iprintf(&iof, "Type: DC 12V");
|
||||
}
|
||||
else if(pi.caps & ONLP_PSU_CAPS_DC48) {
|
||||
iof_iprintf(&iof, "Type: DC 48V");
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Type: Unknown");
|
||||
}
|
||||
if(pi.caps & ONLP_PSU_CAPS_VIN) {
|
||||
iof_iprintf(&iof, "Vin: %d.%d",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(pi.mvin));
|
||||
}
|
||||
if(pi.caps & ONLP_PSU_CAPS_VOUT) {
|
||||
iof_iprintf(&iof, "Vout: %d.%d",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(pi.mvout));
|
||||
}
|
||||
if(pi.caps & ONLP_PSU_CAPS_IIN) {
|
||||
iof_iprintf(&iof, "Iin: %d.%d",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(pi.miin));
|
||||
}
|
||||
if(pi.caps & ONLP_PSU_CAPS_IOUT) {
|
||||
iof_iprintf(&iof, "Iout: %d.%d",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(pi.miout));
|
||||
}
|
||||
if(pi.caps & ONLP_PSU_CAPS_PIN) {
|
||||
iof_iprintf(&iof, "Pin: %d.%d",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(pi.mpin));
|
||||
}
|
||||
if(pi.caps & ONLP_PSU_CAPS_POUT) {
|
||||
iof_iprintf(&iof, "Pout: %d.%d",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(pi.mpout));
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_SHOW_RECURSE) {
|
||||
/*
|
||||
* Display sub oids.
|
||||
*
|
||||
* The standard version only includes
|
||||
* Fans and Thermal Sensors.
|
||||
*/
|
||||
onlp_oid_t* oidp;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "Fans: ");
|
||||
}
|
||||
ONLP_OID_TABLE_ITER_TYPE(pi.hdr.coids, oidp, FAN) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
}
|
||||
if(yaml) {
|
||||
iof_pop(&iof);
|
||||
}
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "Thermals: ");
|
||||
}
|
||||
ONLP_OID_TABLE_ITER_TYPE(pi.hdr.coids, oidp, THERMAL) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
}
|
||||
if(yaml) {
|
||||
iof_pop(&iof);
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_SHOW_EXTENDED) {
|
||||
/* Include all other types as well. */
|
||||
ONLP_OID_TABLE_ITER_TYPE(pi.hdr.coids, oidp, LED) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Not present */
|
||||
onlp_oid_show_state_missing(&iof);
|
||||
}
|
||||
}
|
||||
iof_pop(&iof);
|
||||
return onlp_info_to_user_json_finish(&info->hdr, object, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psu_info_to_json(onlp_psu_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
cJSON* cj;
|
||||
|
||||
int unsupported = (flags & ONLP_OID_JSON_FLAG_UNSUPPORTED_FIELDS);
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_info_to_json_create(&info->hdr, &cj, flags))) {
|
||||
return rv;
|
||||
}
|
||||
cJSON_AddItemToObject(cj, "caps", cjson_util_flag_array(info->caps,
|
||||
onlp_psu_caps_map));
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_TYPE)) {
|
||||
cjson_util_add_string_to_object(cj, "type", "%{onlp_psu_type}",
|
||||
info->type);
|
||||
}
|
||||
|
||||
#define _FIELD(_cap, _field) \
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, _cap) || unsupported) { \
|
||||
cJSON_AddNumberToObject(cj, #_field, info->_field); \
|
||||
}
|
||||
|
||||
_FIELD(GET_VIN, mvin);
|
||||
_FIELD(GET_VOUT, mvout);
|
||||
_FIELD(GET_IIN, miin);
|
||||
_FIELD(GET_IOUT, miout);
|
||||
_FIELD(GET_PIN, mpin);
|
||||
_FIELD(GET_POUT, mpout);
|
||||
#undef _FIELD
|
||||
|
||||
return onlp_info_to_json_finish(&info->hdr, cj, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_psu_info_from_json(cJSON* cj, onlp_psu_info_t* info)
|
||||
{
|
||||
cJSON* j;
|
||||
|
||||
ONLP_IF_ERROR_RETURN(onlp_oid_hdr_from_json(cj, &info->hdr));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup(cj, &j, "caps"));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_array_to_flags(j, &info->caps,
|
||||
onlp_psu_caps_map));
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_VIN)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->mvin, "mvin"));
|
||||
}
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_VOUT)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->mvout, "mvout"));
|
||||
}
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_IIN)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->miin, "miin"));
|
||||
}
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_IOUT)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->miout, "miout"));
|
||||
}
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_PIN)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->mpin, "mpin"));
|
||||
}
|
||||
|
||||
if(ONLP_PSU_INFO_CAP_IS_SET(info, GET_POUT)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->mpout, "mpout"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,59 @@
|
||||
#include <onlp/platformi/sfpi.h>
|
||||
#include "onlp_log.h"
|
||||
#include "onlp_locks.h"
|
||||
#include <onlp/oids.h>
|
||||
#include "onlp_int.h"
|
||||
#include <IOF/iof.h>
|
||||
|
||||
/**
|
||||
* All port numbers will be validated before calling the SFP driver.
|
||||
*/
|
||||
static onlp_sfp_bitmap_t sfpi_bitmap__;
|
||||
|
||||
static int sfp_oid_validate__(onlp_oid_t* oid, int* pid)
|
||||
{
|
||||
if(oid == NULL) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int port;
|
||||
|
||||
if(ONLP_OID_IS_SFP(*oid)) {
|
||||
/** OID Formatted SFP Port */
|
||||
port = ONLP_OID_ID_GET(*oid);
|
||||
/** Ports start from 0, OIDS start from 1 */
|
||||
port--;
|
||||
}
|
||||
else if(ONLP_OID_TYPE_GET(*oid) == 0) {
|
||||
/** Raw port number */
|
||||
port = *oid;
|
||||
*oid = ONLP_SFP_ID_CREATE(port+1);
|
||||
}
|
||||
else {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
if(AIM_BITMAP_GET(&sfpi_bitmap__, port) == 0) {
|
||||
/** Not a valid port id */
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
int rport;
|
||||
if(ONLP_SUCCESS(onlp_sfpi_port_map(port, &rport))) {
|
||||
port = rport;
|
||||
}
|
||||
|
||||
if(pid) {
|
||||
*pid = port;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define ONLP_SFP_PORT_VALIDATE_AND_MAP(_oid, _port) \
|
||||
do { \
|
||||
ONLP_IF_ERROR_RETURN(sfp_oid_validate__(_oid, _port)); \
|
||||
} while(0)
|
||||
|
||||
void
|
||||
onlp_sfp_bitmap_t_init(onlp_sfp_bitmap_t* bmap)
|
||||
{
|
||||
@@ -40,11 +87,11 @@ onlp_sfp_bitmap_t_init(onlp_sfp_bitmap_t* bmap)
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_sfp_init_locked__(void)
|
||||
onlp_sfp_sw_init_locked__(void)
|
||||
{
|
||||
onlp_sfp_bitmap_t_init(&sfpi_bitmap__);
|
||||
|
||||
int rv = onlp_sfpi_init();
|
||||
int rv = onlp_sfpi_sw_init();
|
||||
if(rv < 0) {
|
||||
if(rv == ONLP_STATUS_E_UNSUPPORTED) {
|
||||
/*
|
||||
@@ -67,9 +114,14 @@ onlp_sfp_init_locked__(void)
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_sfp_init)
|
||||
|
||||
ONLP_LOCKED_API0(onlp_sfp_sw_init)
|
||||
|
||||
static int
|
||||
onlp_sfp_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
return onlp_sfpi_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_sfp_hw_init, uint32_t, flags);
|
||||
|
||||
static int
|
||||
onlp_sfp_bitmap_get_locked__(onlp_sfp_bitmap_t* bmap)
|
||||
@@ -81,31 +133,30 @@ ONLP_LOCKED_API1(onlp_sfp_bitmap_get, onlp_sfp_bitmap_t*, bmap);
|
||||
|
||||
|
||||
static int
|
||||
onlp_sfp_denit_locked__(void)
|
||||
onlp_sfp_sw_denit_locked__(void)
|
||||
{
|
||||
return onlp_sfpi_denit();
|
||||
return onlp_sfpi_sw_denit();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_sfp_denit);
|
||||
ONLP_LOCKED_API0(onlp_sfp_sw_denit);
|
||||
|
||||
|
||||
#define ONLP_SFP_PORT_VALIDATE_AND_MAP(_port) \
|
||||
do { \
|
||||
if(AIM_BITMAP_GET(&sfpi_bitmap__, _port) == 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
int _rport; \
|
||||
if(onlp_sfpi_port_map(_port, &_rport) >= 0) { \
|
||||
_port = _rport; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static int
|
||||
onlp_sfp_is_present_locked__(int port)
|
||||
onlp_sfp_is_present_locked__(onlp_oid_t oid)
|
||||
{
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_is_present(port);
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_sfp_is_present, int, port);
|
||||
ONLP_LOCKED_API1(onlp_sfp_is_present, onlp_oid_t, port);
|
||||
|
||||
static int
|
||||
onlp_sfp_type_get_locked__(onlp_oid_t oid, onlp_sfp_type_t* rtype)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_type_get(port, rtype);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_sfp_type_get, onlp_oid_t, oid, onlp_sfp_type_t*, rtype);
|
||||
|
||||
static int
|
||||
onlp_sfp_presence_bitmap_get_locked__(onlp_sfp_bitmap_t* dst)
|
||||
@@ -133,128 +184,28 @@ onlp_sfp_presence_bitmap_get_locked__(onlp_sfp_bitmap_t* dst)
|
||||
ONLP_LOCKED_API1(onlp_sfp_presence_bitmap_get, onlp_sfp_bitmap_t*, dst);
|
||||
|
||||
int
|
||||
onlp_sfp_port_valid(int port)
|
||||
onlp_sfp_port_valid(onlp_oid_t oid)
|
||||
{
|
||||
return AIM_BITMAP_GET(&sfpi_bitmap__, port);
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_sfp_eeprom_read_locked__(int port, uint8_t** datap)
|
||||
onlp_sfp_post_insert_locked__(onlp_oid_t oid, sff_info_t* info)
|
||||
{
|
||||
int rv;
|
||||
uint8_t* data;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
|
||||
data = aim_zmalloc(256);
|
||||
if((rv = onlp_sfpi_eeprom_read(port, data)) < 0) {
|
||||
aim_free(data);
|
||||
data = NULL;
|
||||
}
|
||||
*datap = data;
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_sfp_eeprom_read, int, port, uint8_t**, rv);
|
||||
|
||||
static int
|
||||
onlp_sfp_dom_read_locked__(int port, uint8_t** datap)
|
||||
{
|
||||
int rv;
|
||||
uint8_t* data;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
|
||||
data = aim_zmalloc(256);
|
||||
if((rv = onlp_sfpi_dom_read(port, data)) < 0) {
|
||||
aim_free(data);
|
||||
data = NULL;
|
||||
}
|
||||
*datap = data;
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_sfp_dom_read, int, port, uint8_t**, rv);
|
||||
|
||||
void
|
||||
onlp_sfp_dump(aim_pvs_t* pvs)
|
||||
{
|
||||
int p;
|
||||
int rv;
|
||||
|
||||
if(AIM_BITMAP_COUNT(&sfpi_bitmap__) == 0) {
|
||||
aim_printf(pvs, "There are no SFP capable ports.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
onlp_sfp_bitmap_t bmap;
|
||||
onlp_sfp_bitmap_t_init(&bmap);
|
||||
rv = onlp_sfp_presence_bitmap_get(&bmap);
|
||||
aim_printf(pvs, " Presence Bitmap: ");
|
||||
if(rv == 0) {
|
||||
aim_printf(pvs, "%{aim_bitmap}\n", &bmap);
|
||||
}
|
||||
else {
|
||||
aim_printf(pvs,"Error: %{onlp_status}\n", rv);
|
||||
}
|
||||
aim_printf(pvs, " RX_LOS Bitmap: ");
|
||||
rv = onlp_sfp_rx_los_bitmap_get(&bmap);
|
||||
if(rv == 0) {
|
||||
aim_printf(pvs, "%{aim_bitmap}\n", &bmap);
|
||||
}
|
||||
else {
|
||||
aim_printf(pvs, "Error: %{onlp_status}\n", rv);
|
||||
}
|
||||
aim_printf(pvs, "\n");
|
||||
|
||||
AIM_BITMAP_ITER(&sfpi_bitmap__, p) {
|
||||
rv = onlp_sfp_is_present(p);
|
||||
aim_printf(pvs, "Port %.2d: ", p);
|
||||
if(rv == 0) {
|
||||
/* Missing, OK */
|
||||
aim_printf(pvs, "Missing.\n");
|
||||
}
|
||||
else if(rv == 1) {
|
||||
/* Present, OK */
|
||||
int srv;
|
||||
uint32_t flags = 0;
|
||||
srv = onlp_sfp_control_flags_get(p, &flags);
|
||||
if(srv >= 0) {
|
||||
aim_printf(pvs, "Present, Status = %{onlp_sfp_control_flags}\n", flags);
|
||||
}
|
||||
else {
|
||||
aim_printf(pvs, "Present, Status Unavailable [ %{onlp_status} ]\n", srv);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Error */
|
||||
aim_printf(pvs, "Error: %{onlp_status}\n", rv);
|
||||
}
|
||||
if(rv == 1) {
|
||||
uint8_t* idprom = NULL;
|
||||
rv = onlp_sfp_eeprom_read(p, &idprom);
|
||||
if(rv < 0) {
|
||||
aim_printf(pvs, "Error reading eeprom: %{onlp_status}\n");
|
||||
}
|
||||
else {
|
||||
aim_printf(pvs, "eeprom:\n%{data}\n", idprom, 256);
|
||||
aim_free(idprom);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_sfp_post_insert_locked__(int port, sff_info_t* info)
|
||||
{
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_post_insert(port, info);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_sfp_post_insert, int, port, sff_info_t*, info);
|
||||
ONLP_LOCKED_API2(onlp_sfp_post_insert, onlp_oid_t, port, sff_info_t*, info);
|
||||
|
||||
static int
|
||||
onlp_sfp_control_set_locked__(int port, onlp_sfp_control_t control, int value)
|
||||
onlp_sfp_control_set_locked__(onlp_oid_t oid, onlp_sfp_control_t control, int value)
|
||||
{
|
||||
int port;
|
||||
int supported;
|
||||
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
|
||||
if(!ONLP_SFP_CONTROL_VALID(control)) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
@@ -279,13 +230,14 @@ onlp_sfp_control_set_locked__(int port, onlp_sfp_control_t control, int value)
|
||||
}
|
||||
return onlp_sfpi_control_set(port, control, value);
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_sfp_control_set, int, port, onlp_sfp_control_t, control,
|
||||
ONLP_LOCKED_API3(onlp_sfp_control_set, onlp_oid_t, port, onlp_sfp_control_t, control,
|
||||
int, value);
|
||||
|
||||
static int
|
||||
onlp_sfp_control_get_locked__(int port, onlp_sfp_control_t control, int* value)
|
||||
onlp_sfp_control_get_locked__(onlp_oid_t oid, onlp_sfp_control_t control, int* value)
|
||||
{
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
|
||||
if(!ONLP_SFP_CONTROL_VALID(control)) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
@@ -310,7 +262,7 @@ onlp_sfp_control_get_locked__(int port, onlp_sfp_control_t control, int* value)
|
||||
|
||||
return (value) ? onlp_sfpi_control_get(port, control, value) : ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_sfp_control_get, int, port, onlp_sfp_control_t, control,
|
||||
ONLP_LOCKED_API3(onlp_sfp_control_get, onlp_oid_t, port, onlp_sfp_control_t, control,
|
||||
int*, value);
|
||||
|
||||
|
||||
@@ -342,8 +294,11 @@ ONLP_LOCKED_API1(onlp_sfp_rx_los_bitmap_get, onlp_sfp_bitmap_t*, dst);
|
||||
|
||||
|
||||
int
|
||||
onlp_sfp_control_flags_get(int port, uint32_t* flags)
|
||||
onlp_sfp_control_flags_get(onlp_oid_t oid, uint32_t* flags)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
|
||||
/**
|
||||
* These are the control bits queried and returned.
|
||||
*/
|
||||
@@ -381,52 +336,330 @@ onlp_sfp_control_flags_get(int port, uint32_t* flags)
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfp_ioctl(int port, ...)
|
||||
onlp_sfp_dev_read_locked__(onlp_oid_t oid, int devaddr, int addr,
|
||||
uint8_t* dst, int len)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_dev_read(port, devaddr, addr, dst, len);
|
||||
}
|
||||
ONLP_LOCKED_API5(onlp_sfp_dev_read, onlp_oid_t, port, int, devaddr,
|
||||
int, addr, uint8_t*, dst, int, len);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_write_locked__(onlp_oid_t oid, int devaddr, int addr,
|
||||
uint8_t* src, int len)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_dev_write(port, devaddr, addr, src, len);
|
||||
}
|
||||
ONLP_LOCKED_API5(onlp_sfp_dev_write, onlp_oid_t, port, int, devaddr,
|
||||
int, addr, uint8_t*, src, int, len);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_readb_locked__(onlp_oid_t oid, int devaddr, int addr)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_dev_readb(port, devaddr, addr);
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_sfp_dev_readb, onlp_oid_t, port, int, devaddr, int, addr);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_writeb_locked__(onlp_oid_t oid, int devaddr, int addr,
|
||||
uint8_t value)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_dev_writeb(port, devaddr, addr, value);
|
||||
}
|
||||
ONLP_LOCKED_API4(onlp_sfp_dev_writeb, onlp_oid_t, port, int, devaddr, int, addr, uint8_t, value);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_readw_locked__(onlp_oid_t oid, int devaddr, int addr)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_dev_readw(port, devaddr, addr);
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_sfp_dev_readw, onlp_oid_t, port, int, devaddr, int, addr);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_writew_locked__(onlp_oid_t oid, int devaddr, int addr, uint16_t value)
|
||||
{
|
||||
int port;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
return onlp_sfpi_dev_writew(port, devaddr, addr, value);
|
||||
}
|
||||
ONLP_LOCKED_API4(onlp_sfp_dev_writew, onlp_oid_t, port, int, devaddr, int, addr, uint16_t, value);
|
||||
|
||||
int
|
||||
onlp_sfp_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
va_list vargs;
|
||||
va_start(vargs, port);
|
||||
rv = onlp_sfp_vioctl(port, vargs);
|
||||
va_end(vargs);
|
||||
onlp_sfp_info_t info;
|
||||
if(ONLP_SUCCESS(rv = onlp_sfp_info_get(oid, &info))) {
|
||||
return onlp_sfp_info_format(&info, format, pvs, flags);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfp_vioctl_locked__(int port, va_list vargs)
|
||||
onlp_sfp_info_format(onlp_sfp_info_t* info, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return onlp_sfpi_ioctl(port, vargs);
|
||||
};
|
||||
ONLP_LOCKED_API2(onlp_sfp_vioctl, int, port, va_list, vargs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char*
|
||||
sfp_control_str__(uint32_t controls)
|
||||
{
|
||||
char tmp[16] = { 0 };
|
||||
char* cp = tmp;
|
||||
|
||||
if(controls & ONLP_SFP_CONTROL_FLAG_RX_LOS) {
|
||||
*cp++ = 'R';
|
||||
}
|
||||
if(controls & ONLP_SFP_CONTROL_FLAG_TX_FAULT) {
|
||||
*cp++ = 'T';
|
||||
}
|
||||
if(controls & ONLP_SFP_CONTROL_FLAG_TX_DISABLE) {
|
||||
*cp++ = 'X';
|
||||
}
|
||||
if(controls & ONLP_SFP_CONTROL_FLAG_LP_MODE) {
|
||||
*cp++ = 'L';
|
||||
}
|
||||
if(controls & ONLP_SFP_CONTROL_RESET_STATE) {
|
||||
*cp++ = '~';
|
||||
}
|
||||
return aim_strdup(tmp);
|
||||
}
|
||||
|
||||
static int
|
||||
sfp_inventory_show_iter__(onlp_oid_t oid, void* cookie)
|
||||
{
|
||||
int rv = 0;
|
||||
onlp_sfp_info_t info;
|
||||
char* fields[10] = { 0 };
|
||||
|
||||
fields[0] = aim_dfstrdup("%d", ONLP_OID_ID_GET(oid));
|
||||
|
||||
rv = onlp_sfp_info_get(oid, &info);
|
||||
|
||||
/*
|
||||
* These fields get populated regardless of the
|
||||
* success or failure of the call to onlp_sfp_info_get().
|
||||
*/
|
||||
if(ONLP_SFP_TYPE_VALID(info.type)) {
|
||||
fields[1] = aim_dfstrdup("%{onlp_sfp_type}", info.type);
|
||||
}
|
||||
else {
|
||||
fields[1] = aim_strdup("");
|
||||
}
|
||||
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
|
||||
fields[4] = sfp_control_str__(info.controls);
|
||||
|
||||
if(ONLP_OID_PRESENT(&info)) {
|
||||
|
||||
/** SFP Present. */
|
||||
fields[6] = aim_strdup(info.sff.vendor);
|
||||
fields[7] = aim_strdup(info.sff.model);
|
||||
fields[8] = aim_strdup(info.sff.serial);
|
||||
|
||||
if(info.sff.sfp_type != SFF_SFP_TYPE_INVALID) {
|
||||
/** SFP Identified */
|
||||
fields[2] = aim_strdup(info.sff.module_type_name);
|
||||
fields[3] = aim_strdup(info.sff.media_type_name);
|
||||
fields[5] = aim_strdup(info.sff.length_desc);
|
||||
}
|
||||
else {
|
||||
fields[2] = aim_strdup("Unknown");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
fields[2] = aim_dfstrdup("%{onlp_status}", rv);
|
||||
}
|
||||
|
||||
#define _NS(_string) ( (_string) ? (_string) : "")
|
||||
|
||||
aim_printf((aim_pvs_t*)cookie, "%4s %-6s %-14s %-6s %-6.6s %-5.5s %-16.16s %-16.16s %16.16s\n",
|
||||
_NS(fields[0]), _NS(fields[1]), _NS(fields[2]), _NS(fields[3]),
|
||||
_NS(fields[4]), _NS(fields[5]), _NS(fields[6]), _NS(fields[7]), _NS(fields[8]));
|
||||
|
||||
for(rv = 0; rv < AIM_ARRAYSIZE(fields); rv++) {
|
||||
aim_free(fields[rv]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
onlp_sfp_dev_readb_locked__(int port, uint8_t devaddr, uint8_t addr)
|
||||
onlp_sfp_inventory_show(aim_pvs_t* pvs)
|
||||
{
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
return onlp_sfpi_dev_readb(port, devaddr, addr);
|
||||
aim_printf(pvs, "Port Type Module Media Status Len Vendor Model S/N \n");
|
||||
aim_printf(pvs, "---- ------ -------------- ------ ------ ----- ---------------- ---------------- ----------------\n");
|
||||
onlp_oid_iterate(ONLP_OID_CHASSIS, ONLP_OID_TYPE_FLAG_SFP,
|
||||
sfp_inventory_show_iter__, pvs);
|
||||
return 0;
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_sfp_dev_readb, int, port, uint8_t, devaddr, uint8_t, addr);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_writeb_locked__(int port, uint8_t devaddr, uint8_t addr, uint8_t value)
|
||||
onlp_sfp_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
return onlp_sfpi_dev_writeb(port, devaddr, addr, value);
|
||||
int port, rv;
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, &port);
|
||||
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
ONLP_IF_ERROR_RETURN(rv = onlp_sfp_is_present(oid));
|
||||
|
||||
if(rv) {
|
||||
ONLP_OID_STATUS_FLAG_SET(hdr, PRESENT);
|
||||
}
|
||||
hdr->id = oid;
|
||||
hdr->poid = ONLP_OID_CHASSIS;
|
||||
sprintf(hdr->description, "SFP %d", port);
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API4(onlp_sfp_dev_writeb, int, port, uint8_t, devaddr, uint8_t, addr, uint8_t, value);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_readw_locked__(int port, uint8_t devaddr, uint8_t addr)
|
||||
onlp_sfp_info_get(onlp_oid_t oid, onlp_sfp_info_t* info)
|
||||
{
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
return onlp_sfpi_dev_readw(port, devaddr, addr);
|
||||
int rv;
|
||||
|
||||
memset(info, 0, sizeof(*info));
|
||||
|
||||
ONLP_IF_ERROR_RETURN(onlp_sfp_hdr_get(oid, &info->hdr));
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(&oid, NULL);
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_sfp_type_get(oid, &info->type))) {
|
||||
info->type = ONLP_SFP_TYPE_INVALID;
|
||||
}
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_sfp_control_flags_get(oid, &info->controls))) {
|
||||
AIM_LOG_ERROR("%{onlp_oid}: sfp_info_get: sfp_control_flags_get returned %{onlp_status}",
|
||||
oid, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_sfp_is_present(oid))) {
|
||||
AIM_LOG_ERROR("%{onlp_oid}: sfp_info_get: is_present returned %{onlp_status}",
|
||||
oid, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if(rv == 0) {
|
||||
/** Module not present. */
|
||||
ONLP_OID_STATUS_FLAG_CLR(info, PRESENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Module present. */
|
||||
ONLP_OID_STATUS_FLAG_SET(info, PRESENT);
|
||||
|
||||
/** Read the IDPROM */
|
||||
if(ONLP_FAILURE(rv = onlp_sfp_dev_read(oid, 0x50, 0, info->bytes.a0,
|
||||
sizeof(info->bytes.a0)))) {
|
||||
AIM_LOG_ERROR("%{onlp_oid}: sfp_info_get: sfp_dev_read(0x50) failed: %{onlp_status}",
|
||||
oid, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/** SFF Parsing */
|
||||
sff_eeprom_t sffe;
|
||||
sff_eeprom_parse(&sffe, info->bytes.a0);
|
||||
memcpy(&info->sff, &sffe.info, sizeof(info->sff));
|
||||
if(sffe.identified == 0) {
|
||||
info->sff.sfp_type = SFF_SFP_TYPE_INVALID;
|
||||
/* Nothing more to do */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** DOM Information */
|
||||
if(ONLP_FAILURE(rv = sff_dom_spec_get(&info->sff, info->bytes.a0, &info->dom.spec))) {
|
||||
AIM_LOG_ERROR("%{onlp_oid}: sfp_info_get: sffp_dom_spec_get failed: %{onlp_status}",
|
||||
oid, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if(info->dom.spec == SFF_DOM_SPEC_UNSUPPORTED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(info->dom.spec == SFF_DOM_SPEC_SFF8472) {
|
||||
/** Need the a2 data */
|
||||
if(ONLP_FAILURE(rv = onlp_sfp_dev_read(oid, 0x51, 0, info->bytes.a2,
|
||||
sizeof(info->bytes.a2)))) {
|
||||
AIM_LOG_ERROR("%{onlp_oid}: sfp_info_get: sfp_dev_read(0x51) failed: %{onlp_status}",
|
||||
oid, rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if(ONLP_FAILURE(rv = sff_dom_info_get(&info->dom, &info->sff,
|
||||
info->bytes.a0, info->bytes.a2))) {
|
||||
AIM_LOG_ERROR("%{onlp_oid}: sfp_info_get: sfp_dom_info_get failed: %{onlp_status}",
|
||||
oid, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_sfp_dev_readw, int, port, uint8_t, devaddr, uint8_t, addr);
|
||||
|
||||
int
|
||||
onlp_sfp_dev_writew_locked__(int port, uint8_t devaddr, uint8_t addr, uint16_t value)
|
||||
onlp_sfp_info_to_user_json(onlp_sfp_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
ONLP_SFP_PORT_VALIDATE_AND_MAP(port);
|
||||
return onlp_sfpi_dev_writew(port, devaddr, addr, value);
|
||||
int rv;
|
||||
cJSON* cj;
|
||||
rv = onlp_info_to_user_json_create(&info->hdr, &cj, flags);
|
||||
if(rv > 0) {
|
||||
if(ONLP_OID_PRESENT(info)) {
|
||||
if(info->sff.sfp_type != SFF_SFP_TYPE_INVALID) {
|
||||
cjson_util_add_string_to_object(cj, "Module", info->sff.module_type_name);
|
||||
cjson_util_add_string_to_object(cj, "Media", info->sff.media_type_name);
|
||||
cjson_util_add_string_to_object(cj, "Vendor", info->sff.vendor);
|
||||
cjson_util_add_string_to_object(cj, "Model", info->sff.model);
|
||||
cjson_util_add_string_to_object(cj, "Serial", info->sff.serial);
|
||||
}
|
||||
else {
|
||||
cjson_util_add_string_to_object(cj, "Module", "Unknown");
|
||||
}
|
||||
}
|
||||
else {
|
||||
cjson_util_add_string_to_object(cj, "Module", "Not Present");
|
||||
}
|
||||
}
|
||||
return onlp_info_to_user_json_finish(&info->hdr, cj, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfp_info_to_json(onlp_sfp_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
cJSON* cj;
|
||||
|
||||
if(ONLP_FAILURE(rv = onlp_info_to_json_create(&info->hdr, &cj, flags))) {
|
||||
AIM_LOG_ERROR("%{onlp_status}", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
cjson_util_add_string_to_object(cj, "type", "%{onlp_sfp_type}", info->type);
|
||||
|
||||
if(ONLP_OID_PRESENT(info)) {
|
||||
sff_info_to_json(&info->sff, &cj);
|
||||
sff_dom_info_to_json(&info->dom, &cj);
|
||||
}
|
||||
*cjp = cj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sfp_info_from_json(cJSON* cj, onlp_sfp_info_t* info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ONLP_LOCKED_API4(onlp_sfp_dev_writew, int, port, uint8_t, devaddr, uint8_t, addr, uint16_t, value);
|
||||
|
||||
64
packages/base/any/onlp/src/onlp/module/src/stdattrs.c
Normal file
64
packages/base/any/onlp/src/onlp/module/src/stdattrs.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <onlp/stdattrs.h>
|
||||
#include <onlp/onlp.h>
|
||||
#include <cjson_util/cjson_util_format.h>
|
||||
|
||||
int
|
||||
onlp_asset_info_free(onlp_asset_info_t* aip)
|
||||
{
|
||||
if(!aip) {
|
||||
return ONLP_STATUS_E_PARAM;
|
||||
}
|
||||
|
||||
#define ONLP_ASSET_INFO_ENTRY_str(_field, _name) \
|
||||
do { \
|
||||
aim_free(aip->_field); \
|
||||
} while(0);
|
||||
#define ONLP_ASSET_INFO_ENTRY(_field, _name, _type) \
|
||||
ONLP_ASSET_INFO_ENTRY_##_type(_field, _name)
|
||||
|
||||
#include <onlp/onlp.x>
|
||||
#undef ONLP_ASSET_INFO_ENTRY_str
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_asset_info_to_json(onlp_asset_info_t* aip, cJSON** rv)
|
||||
{
|
||||
cJSON* cj = cJSON_CreateObject();
|
||||
|
||||
#define ONLP_ASSET_INFO_ENTRY_str(_field, _name) \
|
||||
do { \
|
||||
if(aip->_field) { \
|
||||
cJSON_AddStringToObject(cj, #_name, aip->_field); \
|
||||
} else { \
|
||||
cJSON_AddNullToObject(cj, #_name); \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#define ONLP_ASSET_INFO_ENTRY(_field, _name, _type) \
|
||||
ONLP_ASSET_INFO_ENTRY_##_type(_field, _name)
|
||||
#include <onlp/onlp.x>
|
||||
#undef ONLP_ASSET_INFO_str
|
||||
|
||||
*rv = cj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_asset_info_show(onlp_asset_info_t* aip, aim_pvs_t* pvs)
|
||||
{
|
||||
int rv;
|
||||
cJSON* cj;
|
||||
if(ONLP_SUCCESS(rv = onlp_asset_info_to_json(aip, &cj))) {
|
||||
cjson_util_yaml_pvs(pvs, cj);
|
||||
cJSON_Delete(cj);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -1,305 +0,0 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/sys.h>
|
||||
#include <onlp/platformi/sysi.h>
|
||||
#include <onlplib/mmap.h>
|
||||
#include <AIM/aim.h>
|
||||
#include "onlp_log.h"
|
||||
#include "onlp_int.h"
|
||||
#include "onlp_locks.h"
|
||||
|
||||
static char*
|
||||
platform_detect_fs__(int warn)
|
||||
{
|
||||
/*
|
||||
* Check the filesystem for the platform identifier.
|
||||
*/
|
||||
char* rv = NULL;
|
||||
if(ONLP_CONFIG_PLATFORM_FILENAME) {
|
||||
FILE* fp;
|
||||
if((fp=fopen(ONLP_CONFIG_PLATFORM_FILENAME, "r"))) {
|
||||
char platform[256];
|
||||
if(fgets(platform, sizeof(platform), fp) == platform) {
|
||||
/* TODO: Base this detection on the global platform registry. */
|
||||
if(platform[0]) {
|
||||
if(platform[ONLP_STRLEN(platform)-1] == '\n') {
|
||||
platform[ONLP_STRLEN(platform)-1] = 0;
|
||||
}
|
||||
rv = aim_strdup(platform);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
else {
|
||||
if(warn) {
|
||||
AIM_LOG_WARN("could not open platform filename '%s'", ONLP_CONFIG_PLATFORM_FILENAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static char*
|
||||
platform_detect__(void)
|
||||
{
|
||||
#if ONLP_CONFIG_INCLUDE_PLATFORM_STATIC == 1
|
||||
return aim_strdup(ONLP_CONFIG_PLATFORM_STATIC);
|
||||
#endif
|
||||
return platform_detect_fs__(1);
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_sys_init_locked__(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
const char* current_platform = platform_detect__();
|
||||
if(current_platform == NULL) {
|
||||
AIM_DIE("Could not determine the current platform.");
|
||||
}
|
||||
const char* current_interface = onlp_sysi_platform_get();
|
||||
if(current_interface == NULL) {
|
||||
AIM_DIE("The platform driver did not return an appropriate platform identifier.");
|
||||
}
|
||||
|
||||
if(strcmp(current_interface, current_platform)) {
|
||||
/* They do not match. Ask the interface if it supports the current platform. */
|
||||
int rv = onlp_sysi_platform_set(current_platform);
|
||||
if(rv < 0) {
|
||||
AIM_DIE("The current platform interface (%s) does not support the current platform (%s). This is fatal.",
|
||||
current_interface, current_platform);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we get here, its all good */
|
||||
aim_free((char*)current_platform);
|
||||
rv = onlp_sysi_init();
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_sys_init);
|
||||
|
||||
static uint8_t*
|
||||
onie_data_get__(int* free)
|
||||
{
|
||||
void* pa;
|
||||
uint8_t* ma = NULL;
|
||||
int size;
|
||||
if(onlp_sysi_onie_data_phys_addr_get(&pa) == 0) {
|
||||
ma = onlp_mmap((off_t)pa, 64*1024, "onie_data_get__");
|
||||
*free = 0;
|
||||
}
|
||||
else if(onlp_sysi_onie_data_get(&ma, &size) == 0) {
|
||||
*free = 1;
|
||||
}
|
||||
else {
|
||||
ma = NULL;
|
||||
*free = 0;
|
||||
}
|
||||
return ma;
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_sys_info_get_locked__(onlp_sys_info_t* rv)
|
||||
{
|
||||
if(rv == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(rv, 0, sizeof(*rv));
|
||||
|
||||
/**
|
||||
* Get the system ONIE information.
|
||||
*/
|
||||
int free;
|
||||
uint8_t* onie_data = onie_data_get__(&free);
|
||||
|
||||
if(onie_data) {
|
||||
onlp_onie_decode(&rv->onie_info, onie_data, -1);
|
||||
if(free) {
|
||||
onlp_sysi_onie_data_free(onie_data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(onlp_sysi_onie_info_get(&rv->onie_info) != 0) {
|
||||
memset(&rv->onie_info, 0, sizeof(rv->onie_info));
|
||||
list_init(&rv->onie_info.vx_list);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Query the sys oids
|
||||
*/
|
||||
onlp_sysi_oids_get(rv->hdr.coids, AIM_ARRAYSIZE(rv->hdr.coids));
|
||||
|
||||
/*
|
||||
* Platform Information
|
||||
*/
|
||||
onlp_sysi_platform_info_get(&rv->platform_info);
|
||||
|
||||
return 0;
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_sys_info_get,onlp_sys_info_t*,rv);
|
||||
|
||||
void
|
||||
onlp_sys_info_free(onlp_sys_info_t* info)
|
||||
{
|
||||
onlp_onie_info_free(&info->onie_info);
|
||||
onlp_sysi_platform_info_free(&info->platform_info);
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_sys_hdr_get_locked__(onlp_oid_hdr_t* hdr)
|
||||
{
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
return onlp_sysi_oids_get(hdr->coids, AIM_ARRAYSIZE(hdr->coids));
|
||||
}
|
||||
ONLP_LOCKED_API1(onlp_sys_hdr_get, onlp_oid_hdr_t*, hdr);
|
||||
|
||||
|
||||
void
|
||||
onlp_sys_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_sys_info_t si;
|
||||
|
||||
onlp_oid_dump_iof_init_default(&iof, pvs);
|
||||
|
||||
if(ONLP_OID_TYPE_GET(id) != ONLP_OID_TYPE_SYS) {
|
||||
return;
|
||||
}
|
||||
|
||||
iof_push(&iof, "System Information:");
|
||||
rv = onlp_sys_info_get(&si);
|
||||
if(rv < 0) {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
iof_pop(&iof);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
onlp_onie_show(&si.onie_info, &iof.inherit);
|
||||
iof_pop(&iof);
|
||||
}
|
||||
onlp_oid_table_dump(si.hdr.coids, pvs, flags);
|
||||
onlp_sys_info_free(&si);
|
||||
}
|
||||
|
||||
void
|
||||
onlp_sys_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_sys_info_t si;
|
||||
int yaml;
|
||||
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
yaml = (flags & ONLP_OID_SHOW_YAML);
|
||||
|
||||
if(id && ONLP_OID_TYPE_GET(id) != ONLP_OID_TYPE_SYS) {
|
||||
return;
|
||||
}
|
||||
|
||||
rv = onlp_sys_info_get(&si);
|
||||
if(rv < 0) {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
return;
|
||||
}
|
||||
|
||||
#define YPUSH(key) do { if(yaml) { iof_push(&iof, key); } } while(0)
|
||||
#define YPOP() do { if(yaml) { iof_pop(&iof); } } while(0)
|
||||
|
||||
/*
|
||||
* The system information is not actually shown
|
||||
* unless you specify EXTENDED or !RECURSIVE
|
||||
*/
|
||||
if(yaml ||
|
||||
flags & ONLP_OID_SHOW_EXTENDED ||
|
||||
(flags & ONLP_OID_SHOW_RECURSE) == 0) {
|
||||
iof_push(&iof, "System Information:");
|
||||
onlp_onie_show(&si.onie_info, &iof.inherit);
|
||||
iof_pop(&iof);
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_SHOW_RECURSE) {
|
||||
|
||||
onlp_oid_t* oidp;
|
||||
|
||||
/** Show all Chassis Fans */
|
||||
YPUSH("Fans:");
|
||||
ONLP_OID_TABLE_ITER_TYPE(si.hdr.coids, oidp, FAN) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
}
|
||||
YPOP();
|
||||
|
||||
/** Show all System Thermals */
|
||||
YPUSH("Thermals:");
|
||||
ONLP_OID_TABLE_ITER_TYPE(si.hdr.coids, oidp, THERMAL) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
}
|
||||
YPOP();
|
||||
|
||||
/** Show all PSUs */
|
||||
YPUSH("PSUs:");
|
||||
ONLP_OID_TABLE_ITER_TYPE(si.hdr.coids, oidp, PSU) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
}
|
||||
YPOP();
|
||||
|
||||
if(flags & ONLP_OID_SHOW_EXTENDED) {
|
||||
/** Show all LEDs */
|
||||
YPUSH("LEDs:");
|
||||
ONLP_OID_TABLE_ITER_TYPE(si.hdr.coids, oidp, LED) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
}
|
||||
YPOP();
|
||||
}
|
||||
}
|
||||
onlp_sys_info_free(&si);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_sys_ioctl(int code, ...)
|
||||
{
|
||||
int rv;
|
||||
va_list vargs;
|
||||
va_start(vargs, code);
|
||||
rv = onlp_sys_vioctl(code, vargs);
|
||||
va_end(vargs);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_sys_vioctl_locked__(int code, va_list vargs)
|
||||
{
|
||||
return onlp_sysi_ioctl(code, vargs);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_sys_vioctl, int, code, va_list, vargs);
|
||||
|
||||
static int
|
||||
onlp_sys_debug_locked__(aim_pvs_t* pvs, int argc, char* argv[])
|
||||
{
|
||||
return onlp_sysi_debug(pvs, argc, argv);
|
||||
}
|
||||
ONLP_LOCKED_API3(onlp_sys_debug, aim_pvs_t*, pvs, int, argc, char**, argv);
|
||||
@@ -28,89 +28,27 @@
|
||||
#include "onlp_int.h"
|
||||
#include "onlp_locks.h"
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_THERMAL(_id)) { \
|
||||
return ONLP_STATUS_E_INVALID; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define VALIDATENR(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_THERMAL(_id)) { \
|
||||
return; \
|
||||
} \
|
||||
} while(0)
|
||||
static int
|
||||
onlp_thermal_sw_init_locked__(void)
|
||||
{
|
||||
return onlp_thermali_sw_init();
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_thermal_sw_init);
|
||||
|
||||
|
||||
static int
|
||||
onlp_thermal_init_locked__(void)
|
||||
onlp_thermal_hw_init_locked__(uint32_t flags)
|
||||
{
|
||||
return onlp_thermali_init();
|
||||
return onlp_thermali_hw_init(flags);
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_thermal_init);
|
||||
|
||||
#if ONLP_CONFIG_INCLUDE_PLATFORM_OVERRIDES == 1
|
||||
ONLP_LOCKED_API1(onlp_thermal_hw_init, uint32_t, flags)
|
||||
|
||||
static int
|
||||
onlp_thermali_info_from_json__(cJSON* data, onlp_thermal_info_t* info, int errorcheck)
|
||||
onlp_thermal_sw_denit_locked__(void)
|
||||
{
|
||||
int rv;
|
||||
int t;
|
||||
|
||||
if(data == NULL) {
|
||||
return (errorcheck) ? ONLP_STATUS_E_PARAM : 0;
|
||||
}
|
||||
|
||||
rv = cjson_util_lookup_int(data, (int*) &info->status, "status");
|
||||
if(rv < 0 && errorcheck) return rv;
|
||||
|
||||
rv = cjson_util_lookup_int(data, &t, "mcelsius");
|
||||
if(rv < 0 && errorcheck) return rv;
|
||||
info->mcelsius = t;
|
||||
|
||||
return 0;
|
||||
return onlp_thermali_sw_denit();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int
|
||||
onlp_thermal_info_get_locked__(onlp_oid_t oid, onlp_thermal_info_t* info)
|
||||
{
|
||||
int rv;
|
||||
VALIDATE(oid);
|
||||
|
||||
rv = onlp_thermali_info_get(oid, info);
|
||||
if(rv >= 0) {
|
||||
|
||||
#if ONLP_CONFIG_INCLUDE_PLATFORM_OVERRIDES == 1
|
||||
int id = ONLP_OID_ID_GET(oid);
|
||||
cJSON* entry = NULL;
|
||||
|
||||
cjson_util_lookup(onlp_json_get(0), &entry, "overrides.thermal.%d", id);
|
||||
onlp_thermali_info_from_json__(entry, info, 0);
|
||||
#endif
|
||||
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_thermal_info_get, onlp_oid_t, oid, onlp_thermal_info_t*, info);
|
||||
|
||||
static int
|
||||
onlp_thermal_status_get_locked__(onlp_oid_t id, uint32_t* status)
|
||||
{
|
||||
int rv = onlp_thermali_status_get(id, status);
|
||||
if(ONLP_SUCCESS(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_thermal_info_t ti;
|
||||
rv = onlp_thermali_info_get(id, &ti);
|
||||
*status = ti.status;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_thermal_status_get, onlp_oid_t, id, uint32_t*, status);
|
||||
ONLP_LOCKED_API0(onlp_thermal_sw_denit);
|
||||
|
||||
static int
|
||||
onlp_thermal_hdr_get_locked__(onlp_oid_t id, onlp_oid_hdr_t* hdr)
|
||||
@@ -127,138 +65,116 @@ onlp_thermal_hdr_get_locked__(onlp_oid_t id, onlp_oid_hdr_t* hdr)
|
||||
return rv;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_thermal_hdr_get, onlp_oid_t, id, onlp_oid_hdr_t*, hdr);
|
||||
|
||||
|
||||
static int
|
||||
onlp_thermal_info_get_locked__(onlp_oid_t oid, onlp_thermal_info_t* info)
|
||||
{
|
||||
ONLP_OID_THERMAL_VALIDATE(oid);
|
||||
return onlp_thermali_info_get(oid, info);
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_thermal_info_get, onlp_oid_t, oid, onlp_thermal_info_t*, info);
|
||||
|
||||
|
||||
int
|
||||
onlp_thermal_ioctl(int code, ...)
|
||||
onlp_thermal_format(onlp_oid_t oid, onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
va_list vargs;
|
||||
va_start(vargs, code);
|
||||
rv = onlp_thermal_vioctl(code, vargs);
|
||||
va_end(vargs);
|
||||
onlp_thermal_info_t info;
|
||||
if(ONLP_SUCCESS(rv = onlp_thermal_info_get(oid, &info))) {
|
||||
return onlp_thermal_info_format(&info, format, pvs, flags);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int
|
||||
onlp_thermal_vioctl_locked__(int code, va_list vargs)
|
||||
int
|
||||
onlp_thermal_info_format(onlp_thermal_info_t* info,
|
||||
onlp_oid_format_t format,
|
||||
aim_pvs_t* pvs, uint32_t flags)
|
||||
{
|
||||
return onlp_thermali_ioctl(code, vargs);
|
||||
aim_printf(pvs, "%{onlp_oid_hdr} caps=%{onlp_thermal_caps_flags} m=%d thresholds=[ %d, %d, %d ]\n",
|
||||
info, info->caps, info->mcelsius,
|
||||
info->thresholds.warning, info->thresholds.error, info->thresholds.shutdown);
|
||||
return 0;
|
||||
}
|
||||
ONLP_LOCKED_API2(onlp_thermal_vioctl, int, code, va_list, vargs);
|
||||
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* Debug and Show Functions
|
||||
*
|
||||
***********************************************************/
|
||||
void
|
||||
onlp_thermal_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
int
|
||||
onlp_thermal_info_to_user_json(onlp_thermal_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_thermal_info_t info;
|
||||
cJSON* object;
|
||||
|
||||
VALIDATENR(id);
|
||||
onlp_oid_dump_iof_init_default(&iof, pvs);
|
||||
rv = onlp_info_to_user_json_create(&info->hdr, &object, flags);
|
||||
if(rv > 0) {
|
||||
|
||||
iof_push(&iof, "thermal @ %d", ONLP_OID_ID_GET(id));
|
||||
rv = onlp_thermal_info_get(id, &info);
|
||||
if(rv < 0) {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
#define _MILLIFIELD(_cap, _name, _field) \
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, _cap)) { \
|
||||
cjson_util_add_string_to_object(object, _name, "%d.%d", \
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(info->_field)); \
|
||||
} \
|
||||
|
||||
_MILLIFIELD(GET_TEMPERATURE, "Temperature", mcelsius);
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_description(&iof, &info.hdr);
|
||||
if(info.status & 1) {
|
||||
/* Present */
|
||||
iof_iprintf(&iof, "Status: %{onlp_thermal_status_flags}", info.status);
|
||||
iof_iprintf(&iof, "Caps: %{onlp_thermal_caps_flags}", info.caps);
|
||||
iof_iprintf(&iof, "Temperature: %d", info.mcelsius);
|
||||
iof_push(&iof, "thresholds");
|
||||
{
|
||||
iof_iprintf(&iof, "Warning: %d", info.thresholds.warning);
|
||||
iof_iprintf(&iof, "Error: %d", info.thresholds.error);
|
||||
iof_iprintf(&iof, "Shutdown: %d", info.thresholds.shutdown);
|
||||
iof_pop(&iof);
|
||||
}
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Not present.");
|
||||
}
|
||||
}
|
||||
iof_pop(&iof);
|
||||
|
||||
return onlp_info_to_user_json_finish(&info->hdr, object, cjp, flags);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
onlp_thermal_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
int
|
||||
onlp_thermal_info_to_json(onlp_thermal_info_t* info, cJSON** cjp, uint32_t flags)
|
||||
{
|
||||
int rv;
|
||||
iof_t iof;
|
||||
onlp_thermal_info_t ti;
|
||||
VALIDATENR(id);
|
||||
int yaml;
|
||||
cJSON* cj;
|
||||
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
|
||||
|
||||
rv = onlp_thermal_info_get(id, &ti);
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "- ");
|
||||
iof_iprintf(&iof, "Name: Thermal %d", ONLP_OID_ID_GET(id));
|
||||
ONLP_IF_ERROR_RETURN(onlp_info_to_json_create(&info->hdr, &cj, flags));
|
||||
cJSON_AddItemToObject(cj, "caps", cjson_util_flag_array(info->caps,
|
||||
onlp_thermal_caps_map));
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_TEMPERATURE)) {
|
||||
cJSON_AddNumberToObject(cj, "mcelsius", info->mcelsius);
|
||||
}
|
||||
else {
|
||||
iof_push(&iof, "Thermal %d", ONLP_OID_ID_GET(id));
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_WARNING_THRESHOLD)) {
|
||||
cJSON_AddNumberToObject(cj, "warning-threshold",
|
||||
info->thresholds.warning);
|
||||
}
|
||||
|
||||
if(rv < 0) {
|
||||
if(yaml) {
|
||||
iof_iprintf(&iof, "State: Error");
|
||||
iof_iprintf(&iof, "Error: %{onlp_status}", rv);
|
||||
}
|
||||
else {
|
||||
onlp_oid_info_get_error(&iof, rv);
|
||||
}
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_ERROR_THRESHOLD)) {
|
||||
cJSON_AddNumberToObject(cj, "error-threshold",
|
||||
info->thresholds.error);
|
||||
}
|
||||
else {
|
||||
onlp_oid_show_description(&iof, &ti.hdr);
|
||||
if(ti.status & 0x1) {
|
||||
/* Present */
|
||||
if(ti.status & ONLP_THERMAL_STATUS_FAILED) {
|
||||
iof_iprintf(&iof, "Status: Failed");
|
||||
}
|
||||
else {
|
||||
iof_iprintf(&iof, "Status: Functional");
|
||||
if(ti.caps & ONLP_THERMAL_CAPS_GET_TEMPERATURE) {
|
||||
iof_iprintf(&iof, "Temperature: %d.%d C",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.mcelsius));
|
||||
}
|
||||
#if ONLP_CONFIG_INCLUDE_THERMAL_THRESHOLDS == 1
|
||||
|
||||
if(ti.caps & ONLP_THERMAL_CAPS_GET_ANY_THRESHOLD) {
|
||||
iof_push(&iof, "Thresholds:");
|
||||
if(ti.caps & ONLP_THERMAL_CAPS_GET_WARNING_THRESHOLD) {
|
||||
iof_iprintf(&iof, "Warning : %d.%d C",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.thresholds.warning));
|
||||
}
|
||||
if(ti.caps & ONLP_THERMAL_CAPS_GET_ERROR_THRESHOLD) {
|
||||
iof_iprintf(&iof, "Error : %d.%d C",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.thresholds.error));
|
||||
}
|
||||
if(ti.caps & ONLP_THERMAL_CAPS_GET_SHUTDOWN_THRESHOLD) {
|
||||
iof_iprintf(&iof, "Shutdown: %d.%d C",
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(ti.thresholds.shutdown));
|
||||
}
|
||||
iof_pop(&iof);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Not present */
|
||||
onlp_oid_show_state_missing(&iof);
|
||||
}
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_SHUTDOWN_THRESHOLD)) {
|
||||
cJSON_AddNumberToObject(cj, "shutdown-threshold",
|
||||
info->thresholds.shutdown);
|
||||
}
|
||||
iof_pop(&iof);
|
||||
return onlp_info_to_json_finish(&info->hdr, cj, cjp, flags);
|
||||
}
|
||||
|
||||
int
|
||||
onlp_thermal_info_from_json(cJSON* cj, onlp_thermal_info_t* info)
|
||||
{
|
||||
cJSON* j;
|
||||
memset(info, 0, sizeof(*info));
|
||||
|
||||
ONLP_IF_ERROR_RETURN(onlp_oid_hdr_from_json(cj, &info->hdr));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup(cj, &j, "caps"));
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_array_to_flags(j, &info->caps,
|
||||
onlp_thermal_caps_map));
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_TEMPERATURE)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj, &info->mcelsius, "mcelsius"));
|
||||
}
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_WARNING_THRESHOLD)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj,
|
||||
&info->thresholds.warning,
|
||||
"warning-threshold"));
|
||||
}
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_ERROR_THRESHOLD)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj,
|
||||
&info->thresholds.error,
|
||||
"error-threshold"));
|
||||
}
|
||||
if(ONLP_THERMAL_INFO_CAP_IS_SET(info, GET_SHUTDOWN_THRESHOLD)) {
|
||||
ONLP_IF_ERROR_RETURN(cjson_util_lookup_int(cj,
|
||||
&info->thresholds.shutdown,
|
||||
"shutdown-threshold"));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
*.mk
|
||||
@@ -0,0 +1,35 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2017 v=onl>
|
||||
*
|
||||
* Copyright 2017 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
* Attribute Platform Implementation Defaults.
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platformi/attributei.h>
|
||||
#include "onlp_platform_defaults_int.h"
|
||||
#include "onlp_platform_defaults_log.h"
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_attributei_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_attributei_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_attributei_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_attributei_supported(onlp_oid_t id, const char* attribute));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_attributei_set(onlp_oid_t id, const char* attribute, void* value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_attributei_get(onlp_oid_t id, const char* attribute, void** value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_attributei_free(onlp_oid_t id, const char* attribute, void* value));
|
||||
@@ -0,0 +1,32 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platformi/chassisi.h>
|
||||
#include "onlp_platform_defaults_int.h"
|
||||
#include "onlp_platform_defaults_log.h"
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_chassisi_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_chassisi_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_chassisi_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_chassisi_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_chassisi_info_get(onlp_oid_t oid, onlp_chassis_info_t* info));
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -30,13 +30,12 @@
|
||||
* These are the default implementations for all currently
|
||||
* defined interface functions.
|
||||
*/
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_status_get(onlp_oid_t id, uint32_t* status));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_fani_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_fani_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_fani_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* hdr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_rpm_set(onlp_oid_t id, int rpm));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_percentage_set(onlp_oid_t id, int p));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_fani_ioctl(onlp_oid_t id, va_list vargs));
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
#include "onlp_platform_defaults_int.h"
|
||||
#include "onlp_platform_defaults_log.h"
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_status_get(onlp_oid_t id, uint32_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_ledi_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_ledi_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_ledi_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_set(onlp_oid_t id, int on_or_off));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_ioctl(onlp_oid_t id, va_list vargs));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* rv));
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_ledi_char_set(onlp_oid_t id, char c));
|
||||
|
||||
@@ -80,7 +80,7 @@ onlp_platform_defaults_config_lookup(const char* setting)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; onlp_platform_defaults_config_settings[i].name; i++) {
|
||||
if(!strcmp(onlp_platform_defaults_config_settings[i].name, setting)) {
|
||||
if(strcmp(onlp_platform_defaults_config_settings[i].name, setting)) {
|
||||
return onlp_platform_defaults_config_settings[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -71,20 +71,26 @@ extern aim_map_si_t onlp_platform_defaults_log_flag_desc_map[];
|
||||
|
||||
#define ONLP_SYSI_PLATFORM_NAME_DEFAULT "onlp-sysi-platform-default"
|
||||
|
||||
|
||||
#define __ONLP_DEFAULTI_IMPLEMENTATION(__f) \
|
||||
int __ONLP_DEFAULTI __f \
|
||||
{ \
|
||||
ONLP_PLATFORM_DEFAULTS_LOG_CALLED("using default %s", __func__); \
|
||||
return ONLP_STATUS_E_UNSUPPORTED; \
|
||||
#define __ONLP_DEFAULT_IMPLEMENTATION__(_f, _rc) \
|
||||
int __ONLP_DEFAULTI _f \
|
||||
{ \
|
||||
ONLP_PLATFORM_DEFAULTS_LOG_CALLED("using default %s", \
|
||||
__func__); \
|
||||
return _rc; \
|
||||
}
|
||||
|
||||
#define __ONLP_DEFAULTI_VIMPLEMENTATION(__f) \
|
||||
void __ONLP_DEFAULTI __f \
|
||||
{ \
|
||||
ONLP_PLATFORM_DEFAULTS_LOG_CALLED("using default %s", __func__); \
|
||||
}
|
||||
#define __ONLP_DEFAULTI_IMPLEMENTATION(_f) \
|
||||
__ONLP_DEFAULT_IMPLEMENTATION__(_f, ONLP_STATUS_E_UNSUPPORTED)
|
||||
|
||||
#define __ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(_f) \
|
||||
__ONLP_DEFAULT_IMPLEMENTATION__(_f, ONLP_STATUS_OK)
|
||||
|
||||
#define __ONLP_DEFAULTI_VIMPLEMENTATION(_f) \
|
||||
void __ONLP_DEFAULTI _f \
|
||||
{ \
|
||||
ONLP_PLATFORM_DEFAULTS_LOG_CALLED("using default %s", \
|
||||
__func__); \
|
||||
}
|
||||
|
||||
|
||||
#endif /* __ONLP_PLATFORM_DEFAULTS_INT_H__ */
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
*
|
||||
***********************************************************/
|
||||
#include <onlp/platformi/sysi.h>
|
||||
#include <onlp/platformi/platformi.h>
|
||||
#include "onlp_platform_defaults_int.h"
|
||||
#include "onlp_platform_defaults_log.h"
|
||||
|
||||
const char* __ONLP_DEFAULTI
|
||||
onlp_sysi_platform_get(void)
|
||||
onlp_platformi_get(void)
|
||||
{
|
||||
/*
|
||||
* This function should never be called.
|
||||
@@ -34,38 +34,28 @@ onlp_sysi_platform_get(void)
|
||||
* If we get here its because the platform libraries are
|
||||
* not written, initialized, or setup properly before we execute.
|
||||
*/
|
||||
AIM_LOG_ERROR("The default implementation of onlp_sysi_platform_get() has been called.");
|
||||
AIM_LOG_ERROR("The default implementation of onlp_platformi_get() has been called.");
|
||||
AIM_LOG_ERROR("This can happen for the following reasons, all fatal:");
|
||||
AIM_LOG_ERROR("* The ONLP build configuration is incorrect.");
|
||||
AIM_LOG_ERROR("* The ONLP platform library for this platform does not contain the onlp_sysi_platform_get() symbol.");
|
||||
AIM_LOG_ERROR("* The ONLP platform library for this platform does not contain the onlp_platformi_get() symbol.");
|
||||
AIM_LOG_ERROR("* The ONLP platform shared libraries are not setup properly before we executed.");
|
||||
|
||||
#if ONLP_CONFIG_INCLUDE_PLATFORM_ERROR_CHECK == 1
|
||||
AIM_LOG_ERROR("* The platform cannot continue until this issue is resolved.");
|
||||
abort();
|
||||
#endif
|
||||
|
||||
return ONLP_SYSI_PLATFORM_NAME_DEFAULT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int __ONLP_DEFAULTI
|
||||
onlp_sysi_debug(aim_pvs_t* pvs, int argc, char* argv[])
|
||||
onlp_platformi_debug(aim_pvs_t* pvs, int argc, char* argv[])
|
||||
{
|
||||
aim_printf(pvs, "This platform does not support debug features.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_platform_set(const char* p));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_onie_data_phys_addr_get(void** physaddr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_onie_data_get(uint8_t** data, int* size));
|
||||
__ONLP_DEFAULTI_VIMPLEMENTATION(onlp_sysi_onie_data_free(uint8_t* data));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_onie_info_get(onlp_onie_info_t* onie));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_oids_get(onlp_oid_t* table, int max));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_platform_info_get(onlp_platform_info_t* pi));
|
||||
__ONLP_DEFAULTI_VIMPLEMENTATION(onlp_sysi_platform_info_free(onlp_platform_info_t* pi));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_ioctl(int id, va_list vargs));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_platform_manage_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_platform_manage_fans(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sysi_platform_manage_leds(void));
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_set(const char* p));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_vioctl(int id, va_list vargs));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_manage_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_manage_fans(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_platformi_manage_leds(void));
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -26,8 +26,8 @@
|
||||
#include "onlp_platform_defaults_int.h"
|
||||
#include "onlp_platform_defaults_log.h"
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_psui_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_psui_status_get(onlp_oid_t id, uint32_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_psui_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_psui_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_psui_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_psui_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_psui_ioctl(onlp_oid_t pid, va_list vargs));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* rv));
|
||||
|
||||
@@ -25,13 +25,14 @@
|
||||
#include "onlp_platform_defaults_int.h"
|
||||
#include "onlp_platform_defaults_log.h"
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_sfpi_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_sfpi_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_sfpi_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_type_get(int port, onlp_sfp_type_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_is_present(int port));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_eeprom_read(int port, uint8_t data[256]));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dom_read(int port, uint8_t data[256]));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_post_insert(int port, sff_info_t* sff_info));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_port_map(int port, int* rport));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_denit(void));
|
||||
@@ -40,7 +41,11 @@ __ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_ioctl(int port, va_list vargs));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_read(int port, int devaddr, int addr, uint8_t* dst, int len));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_write(int port, int devaddr, int addr, uint8_t* dst, int len));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_readb(int port, int devaddr, int addr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_writeb(int port, int devaddr, int addr, uint8_t value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_readw(int port, int devaddr, int addr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_dev_writew(int port, int devaddr, int addr, uint16_t value));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_sfpi_info_get(onlp_oid_t port, onlp_sfp_info_t* info));
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
*
|
||||
* Copyright 2014, 2015 Big Switch Networks, Inc.
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -26,7 +26,9 @@
|
||||
#include "onlp_platform_defaults_int.h"
|
||||
#include "onlp_platform_defaults_log.h"
|
||||
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_thermali_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_thermali_sw_init(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_thermali_hw_init(uint32_t flags));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION_OPTIONAL(onlp_thermali_sw_denit(void));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_thermali_status_get(onlp_oid_t id, uint32_t* rv));
|
||||
__ONLP_DEFAULTI_IMPLEMENTATION(onlp_thermali_hdr_get(onlp_oid_t id, onlp_oid_hdr_t* rv));
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Inclusive Makefile for the onlp_platform_defaults module.
|
||||
#
|
||||
# Autogenerated 2018-07-18 22:29:20.551244
|
||||
#
|
||||
###############################################################################
|
||||
onlp_platform_defaults_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||
include $(onlp_platform_defaults_BASEDIR)module/make.mk
|
||||
include $(onlp_platform_defaults_BASEDIR)module/auto/make.mk
|
||||
include $(onlp_platform_defaults_BASEDIR)module/src/make.mk
|
||||
include $(onlp_platform_defaults_BASEDIR)utest/_make.mk
|
||||
|
||||
1
packages/base/any/onlp/src/onlp_platform_sim/.module
Normal file
1
packages/base/any/onlp/src/onlp_platform_sim/.module
Normal file
@@ -0,0 +1 @@
|
||||
name: onlp_platform_sim
|
||||
9
packages/base/any/onlp/src/onlp_platform_sim/Makefile
Normal file
9
packages/base/any/onlp/src/onlp_platform_sim/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
###############################################################################
|
||||
#
|
||||
#
|
||||
#
|
||||
###############################################################################
|
||||
include $(ONL)/make/config.mk
|
||||
MODULE := onlp_platform_sim
|
||||
AUTOMODULE := onlp_platform_sim
|
||||
include $(BUILDER)/definemodule.mk
|
||||
6
packages/base/any/onlp/src/onlp_platform_sim/README
Normal file
6
packages/base/any/onlp/src/onlp_platform_sim/README
Normal file
@@ -0,0 +1,6 @@
|
||||
###############################################################################
|
||||
#
|
||||
# onlp_platform_sim README
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
###############################################################################
|
||||
#
|
||||
# onlp_platform_sim Autogeneration
|
||||
#
|
||||
###############################################################################
|
||||
onlp_platform_sim_AUTO_DEFS := module/auto/onlp_platform_sim.yml
|
||||
onlp_platform_sim_AUTO_DIRS := module/inc/onlp_platform_sim module/src
|
||||
include $(BUILDER)/auto.mk
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
###############################################################################
|
||||
#
|
||||
# onlp_platform_sim Autogeneration Definitions.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
cdefs: &cdefs
|
||||
- ONLP_PLATFORM_SIM_CONFIG_INCLUDE_LOGGING:
|
||||
doc: "Include or exclude logging."
|
||||
default: 1
|
||||
- ONLP_PLATFORM_SIM_CONFIG_LOG_OPTIONS_DEFAULT:
|
||||
doc: "Default enabled log options."
|
||||
default: AIM_LOG_OPTIONS_DEFAULT
|
||||
- ONLP_PLATFORM_SIM_CONFIG_LOG_BITS_DEFAULT:
|
||||
doc: "Default enabled log bits."
|
||||
default: AIM_LOG_BITS_DEFAULT
|
||||
- ONLP_PLATFORM_SIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT:
|
||||
doc: "Default enabled custom log bits."
|
||||
default: 0
|
||||
- ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB:
|
||||
doc: "Default all porting macros to use the C standard libraries."
|
||||
default: 1
|
||||
- ONLP_PLATFORM_SIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS:
|
||||
doc: "Include standard library headers for stdlib porting macros."
|
||||
default: ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB
|
||||
- ONLP_PLATFORM_SIM_CONFIG_INCLUDE_UCLI:
|
||||
doc: "Include generic uCli support."
|
||||
default: 0
|
||||
|
||||
|
||||
definitions:
|
||||
cdefs:
|
||||
ONLP_PLATFORM_SIM_CONFIG_HEADER:
|
||||
defs: *cdefs
|
||||
basename: onlp_platform_sim_config
|
||||
|
||||
portingmacro:
|
||||
ONLP_PLATFORM_SIM:
|
||||
macros:
|
||||
- malloc
|
||||
- free
|
||||
- memset
|
||||
- memcpy
|
||||
- strncpy
|
||||
- vsnprintf
|
||||
- snprintf
|
||||
- strlen
|
||||
@@ -0,0 +1,97 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __ONLP_PLATFORM_SIM__OIDS_H__
|
||||
#define __ONLP_PLATFORM_SIM__OIDS_H__
|
||||
|
||||
#include <onlp/oids.h>
|
||||
#include <onlp/chassis.h>
|
||||
#include <onlp/psu.h>
|
||||
#include <onlp/fan.h>
|
||||
#include <onlp/thermal.h>
|
||||
#include <onlp/led.h>
|
||||
#include <onlp/sfp.h>
|
||||
|
||||
/**
|
||||
* @brief Initialize the OID simulation.
|
||||
* @param fname The OID JSON file.
|
||||
*/
|
||||
int onlp_platform_sim_oids_init(const char* fname);
|
||||
|
||||
/**
|
||||
* @brief Lookup a structure by OID.
|
||||
* @param oid The oid to search for.
|
||||
* @param[out] hdr Receives the pointer to the structure.
|
||||
* @note You would not normally use this function.
|
||||
* Instead use the instances provided below.
|
||||
*/
|
||||
onlp_oid_hdr_t*
|
||||
onlp_platform_sim_oid_lookup(onlp_oid_t oid);
|
||||
|
||||
/**
|
||||
* @brief Get the chassis info structure for the given oid.
|
||||
* @param oid The chassis oid.
|
||||
*/
|
||||
int
|
||||
onlp_platform_sim_chassis_get(onlp_oid_t oid,
|
||||
onlp_oid_hdr_t* hdr,
|
||||
onlp_chassis_info_t* info,
|
||||
onlp_chassis_info_t** pinfo);
|
||||
|
||||
/**
|
||||
* @brief Get the psu info structure for the given oid.
|
||||
* @param oid The psu oid.
|
||||
*/
|
||||
int
|
||||
onlp_platform_sim_psu_get(onlp_oid_t oid,
|
||||
onlp_oid_hdr_t* hdr,
|
||||
onlp_psu_info_t* info,
|
||||
onlp_psu_info_t** pinfo);
|
||||
|
||||
/**
|
||||
* @brief Get the fan info structure for the given oid.
|
||||
* @param oid The fan oid.
|
||||
*/
|
||||
int
|
||||
onlp_platform_sim_fan_get(onlp_oid_t oid,
|
||||
onlp_oid_hdr_t* hdr,
|
||||
onlp_fan_info_t* info,
|
||||
onlp_fan_info_t** pinfo);
|
||||
|
||||
/**
|
||||
* @brief Get the thermal info structure for the given oid.
|
||||
* @param oid The thermal oid.
|
||||
*/
|
||||
int
|
||||
onlp_platform_sim_thermal_get(onlp_oid_t oid,
|
||||
onlp_oid_hdr_t* hdr,
|
||||
onlp_thermal_info_t* info,
|
||||
onlp_thermal_info_t** pinfo);
|
||||
|
||||
/**
|
||||
* @brief Get the led info structure for the given oid.
|
||||
* @param oid The led oid.
|
||||
*/
|
||||
int
|
||||
onlp_platform_sim_led_get(onlp_oid_t oid,
|
||||
onlp_oid_hdr_t* hdr,
|
||||
onlp_led_info_t* info,
|
||||
onlp_led_info_t** pinfo);
|
||||
|
||||
/**
|
||||
* @brief Get the sfp info structure for the given oid.
|
||||
* @param oid The sfp oid.
|
||||
*/
|
||||
int
|
||||
onlp_platform_sim_sfp_get(onlp_oid_t oid,
|
||||
onlp_oid_hdr_t* hdr,
|
||||
onlp_sfp_info_t* info,
|
||||
onlp_sfp_info_t** pinfo);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* __ONLP_PLATFORM_SIM__OIDS_H__ */
|
||||
@@ -0,0 +1,14 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <onlp_platform_sim/onlp_platform_sim_config.h>
|
||||
|
||||
/* <--auto.start.xmacro(ALL).define> */
|
||||
/* <auto.end.xmacro(ALL).define> */
|
||||
|
||||
/* <--auto.start.xenum(ALL).define> */
|
||||
/* <auto.end.xenum(ALL).define> */
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief onlp_platform_sim Configuration Header
|
||||
*
|
||||
* @addtogroup onlp_platform_sim-config
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __ONLP_PLATFORM_SIM_CONFIG_H__
|
||||
#define __ONLP_PLATFORM_SIM_CONFIG_H__
|
||||
|
||||
#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG
|
||||
#include <global_custom_config.h>
|
||||
#endif
|
||||
#ifdef ONLP_PLATFORM_SIM_INCLUDE_CUSTOM_CONFIG
|
||||
#include <onlp_platform_sim_custom_config.h>
|
||||
#endif
|
||||
|
||||
/* <auto.start.cdefs(ONLP_PLATFORM_SIM_CONFIG_HEADER).header> */
|
||||
#include <AIM/aim.h>
|
||||
/**
|
||||
* ONLP_PLATFORM_SIM_CONFIG_INCLUDE_LOGGING
|
||||
*
|
||||
* Include or exclude logging. */
|
||||
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_CONFIG_INCLUDE_LOGGING
|
||||
#define ONLP_PLATFORM_SIM_CONFIG_INCLUDE_LOGGING 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_PLATFORM_SIM_CONFIG_LOG_OPTIONS_DEFAULT
|
||||
*
|
||||
* Default enabled log options. */
|
||||
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_CONFIG_LOG_OPTIONS_DEFAULT
|
||||
#define ONLP_PLATFORM_SIM_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_PLATFORM_SIM_CONFIG_LOG_BITS_DEFAULT
|
||||
*
|
||||
* Default enabled log bits. */
|
||||
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_CONFIG_LOG_BITS_DEFAULT
|
||||
#define ONLP_PLATFORM_SIM_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_PLATFORM_SIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT
|
||||
*
|
||||
* Default enabled custom log bits. */
|
||||
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT
|
||||
#define ONLP_PLATFORM_SIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB
|
||||
*
|
||||
* Default all porting macros to use the C standard libraries. */
|
||||
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB
|
||||
#define ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_PLATFORM_SIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
|
||||
*
|
||||
* Include standard library headers for stdlib porting macros. */
|
||||
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
|
||||
#define ONLP_PLATFORM_SIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_PLATFORM_SIM_CONFIG_INCLUDE_UCLI
|
||||
*
|
||||
* Include generic uCli support. */
|
||||
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_CONFIG_INCLUDE_UCLI
|
||||
#define ONLP_PLATFORM_SIM_CONFIG_INCLUDE_UCLI 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* All compile time options can be queried or displayed
|
||||
*/
|
||||
|
||||
/** Configuration settings structure. */
|
||||
typedef struct onlp_platform_sim_config_settings_s {
|
||||
/** name */
|
||||
const char* name;
|
||||
/** value */
|
||||
const char* value;
|
||||
} onlp_platform_sim_config_settings_t;
|
||||
|
||||
/** Configuration settings table. */
|
||||
/** onlp_platform_sim_config_settings table. */
|
||||
extern onlp_platform_sim_config_settings_t onlp_platform_sim_config_settings[];
|
||||
|
||||
/**
|
||||
* @brief Lookup a configuration setting.
|
||||
* @param setting The name of the configuration option to lookup.
|
||||
*/
|
||||
const char* onlp_platform_sim_config_lookup(const char* setting);
|
||||
|
||||
/**
|
||||
* @brief Show the compile-time configuration.
|
||||
* @param pvs The output stream.
|
||||
*/
|
||||
int onlp_platform_sim_config_show(struct aim_pvs_s* pvs);
|
||||
|
||||
/* <auto.end.cdefs(ONLP_PLATFORM_SIM_CONFIG_HEADER).header> */
|
||||
|
||||
#include "onlp_platform_sim_porting.h"
|
||||
|
||||
#endif /* __ONLP_PLATFORM_SIM_CONFIG_H__ */
|
||||
/* @} */
|
||||
@@ -0,0 +1,26 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* onlp_platform_sim Doxygen Header
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __ONLP_PLATFORM_SIM_DOX_H__
|
||||
#define __ONLP_PLATFORM_SIM_DOX_H__
|
||||
|
||||
/**
|
||||
* @defgroup onlp_platform_sim onlp_platform_sim - onlp_platform_sim Description
|
||||
*
|
||||
|
||||
The documentation overview for this module should go here.
|
||||
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @defgroup onlp_platform_sim-onlp_platform_sim Public Interface
|
||||
* @defgroup onlp_platform_sim-config Compile Time Configuration
|
||||
* @defgroup onlp_platform_sim-porting Porting Macros
|
||||
*
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#endif /* __ONLP_PLATFORM_SIM_DOX_H__ */
|
||||
@@ -0,0 +1,107 @@
|
||||
/**************************************************************************//**
|
||||
*
|
||||
* @file
|
||||
* @brief onlp_platform_sim Porting Macros.
|
||||
*
|
||||
* @addtogroup onlp_platform_sim-porting
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef __ONLP_PLATFORM_SIM_PORTING_H__
|
||||
#define __ONLP_PLATFORM_SIM_PORTING_H__
|
||||
|
||||
|
||||
/* <auto.start.portingmacro(ALL).define> */
|
||||
#if ONLP_PLATFORM_SIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <memory.h>
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_MALLOC
|
||||
#if defined(GLOBAL_MALLOC)
|
||||
#define ONLP_PLATFORM_SIM_MALLOC GLOBAL_MALLOC
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_MALLOC malloc
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_MALLOC is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_FREE
|
||||
#if defined(GLOBAL_FREE)
|
||||
#define ONLP_PLATFORM_SIM_FREE GLOBAL_FREE
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_FREE free
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_FREE is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_MEMSET
|
||||
#if defined(GLOBAL_MEMSET)
|
||||
#define ONLP_PLATFORM_SIM_MEMSET GLOBAL_MEMSET
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_MEMSET memset
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_MEMSET is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_MEMCPY
|
||||
#if defined(GLOBAL_MEMCPY)
|
||||
#define ONLP_PLATFORM_SIM_MEMCPY GLOBAL_MEMCPY
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_MEMCPY memcpy
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_MEMCPY is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_STRNCPY
|
||||
#if defined(GLOBAL_STRNCPY)
|
||||
#define ONLP_PLATFORM_SIM_STRNCPY GLOBAL_STRNCPY
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_STRNCPY strncpy
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_STRNCPY is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_VSNPRINTF
|
||||
#if defined(GLOBAL_VSNPRINTF)
|
||||
#define ONLP_PLATFORM_SIM_VSNPRINTF GLOBAL_VSNPRINTF
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_VSNPRINTF vsnprintf
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_VSNPRINTF is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_SNPRINTF
|
||||
#if defined(GLOBAL_SNPRINTF)
|
||||
#define ONLP_PLATFORM_SIM_SNPRINTF GLOBAL_SNPRINTF
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_SNPRINTF snprintf
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_SNPRINTF is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONLP_PLATFORM_SIM_STRLEN
|
||||
#if defined(GLOBAL_STRLEN)
|
||||
#define ONLP_PLATFORM_SIM_STRLEN GLOBAL_STRLEN
|
||||
#elif ONLP_PLATFORM_SIM_CONFIG_PORTING_STDLIB == 1
|
||||
#define ONLP_PLATFORM_SIM_STRLEN strlen
|
||||
#else
|
||||
#error The macro ONLP_PLATFORM_SIM_STRLEN is required but cannot be defined.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* <auto.end.portingmacro(ALL).define> */
|
||||
|
||||
|
||||
#endif /* __ONLP_PLATFORM_SIM_PORTING_H__ */
|
||||
/* @} */
|
||||
10
packages/base/any/onlp/src/onlp_platform_sim/module/make.mk
Normal file
10
packages/base/any/onlp/src/onlp_platform_sim/module/make.mk
Normal file
@@ -0,0 +1,10 @@
|
||||
###############################################################################
|
||||
#
|
||||
#
|
||||
#
|
||||
###############################################################################
|
||||
THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
onlp_platform_sim_INCLUDES := -I $(THIS_DIR)inc
|
||||
onlp_platform_sim_INTERNAL_INCLUDES := -I $(THIS_DIR)src
|
||||
onlp_platform_sim_DEPENDMODULE_ENTRIES := init:onlp_platform_sim ucli:onlp_platform_sim
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Local source generation targets.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
ucli:
|
||||
@../../../../tools/uclihandlers.py onlp_platform_sim_ucli.c
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <onlp/platformi/attributei.h>
|
||||
#include <onlp/stdattrs.h>
|
||||
#include <onlplib/file.h>
|
||||
|
||||
int
|
||||
onlp_attributei_supported(onlp_oid_t id, const char* attribute)
|
||||
{
|
||||
if(!strcmp(attribute, ONLP_ATTRIBUTE_ONIE_INFO) ||
|
||||
!strcmp(attribute, ONLP_ATTRIBUTE_ASSET_INFO)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_attributei_get(onlp_oid_t id, const char* attribute,
|
||||
void** value)
|
||||
{
|
||||
if(!strcmp(attribute, ONLP_ATTRIBUTE_ONIE_INFO)) {
|
||||
/** TODO: fix this fake data using JSON and onie-sysinfo */
|
||||
onlp_onie_info_t* oip = aim_zmalloc(sizeof(*oip));
|
||||
list_init(&oip->vx_list);
|
||||
oip->product_name = aim_strdup("ONLP Platform Simulation.");
|
||||
extern char* onlp_platform_sim_platform_name;
|
||||
oip->platform_name = aim_strdup(onlp_platform_sim_platform_name);
|
||||
oip->manufacturer = aim_strdup("ONL");
|
||||
*value = oip;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
if(!strcmp(attribute, ONLP_ATTRIBUTE_ASSET_INFO)) {
|
||||
onlp_asset_info_t* aip = aim_zmalloc(sizeof(*aip));
|
||||
aip->oid = id;
|
||||
aip->firmware_revision = aim_fstrdup("1.2.3");
|
||||
*value = aip;
|
||||
return ONLP_STATUS_OK;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int
|
||||
onlp_attributei_free(onlp_oid_t id, const char* attribute, void* value)
|
||||
{
|
||||
if(!strcmp(attribute, ONLP_ATTRIBUTE_ONIE_INFO)) {
|
||||
onlp_onie_info_free(value);
|
||||
aim_free(value);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if(!strcmp(attribute, ONLP_ATTRIBUTE_ASSET_INFO)) {
|
||||
onlp_asset_info_free(value);
|
||||
aim_free(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ONLP_STATUS_E_UNSUPPORTED;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user