diff --git a/Makefile b/Makefile index 8cbbb24..e8182d1 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ OSNAME=${shell uname} DIVA_STREAMING=0 +DIVA_STATUS=0 USE_OWN_LIBCAPI=yes @@ -84,6 +85,10 @@ ifeq (${DIVA_STREAMING},1) INCLUDE += -I./divastreaming -I./divastreaming/.. endif +ifeq (${DIVA_STATUS},1) +INCLUDE += -I./divastatus -I./divastatus/.. +endif + DEBUG=-g #-pg INCLUDE+= -I$(ASTERISK_HEADER_DIR) ifndef C4B @@ -109,6 +114,9 @@ CFLAGS+=$(shell if uname -m | grep -q "ppc\|arm\|s390"; then echo "-fsigned-char ifeq (${DIVA_STREAMING},1) CFLAGS += -DDIVA_STREAMING=1 endif +ifeq (${DIVA_STATUS},1) +CFLAGS += -DDIVA_STATUS=1 +endif LIBS=-ldl -lpthread -lm CC=gcc @@ -135,6 +143,10 @@ OBJECTS += divastreaming/diva_streaming_idi_host_ifc_impl.o \ divastreaming/runtime.o endif +ifeq (${DIVA_STATUS},1) +OBJECTS += divastatus/divastatus.o +endif + CFLAGS+=-Wno-missing-prototypes -Wno-missing-declarations CFLAGS+=-DCRYPTO @@ -152,6 +164,7 @@ clean: rm -f *.so *.o rm -f libcapi20/*.o rm -f divastreaming/*.o + rm -f divastatus/*.o config.h: ./create_config.sh "$(ASTERISK_HEADER_DIR)" diff --git a/chan_capi.c b/chan_capi.c index c2abdbd..0410a25 100644 --- a/chan_capi.c +++ b/chan_capi.c @@ -51,6 +51,9 @@ struct _diva_streaming_vector* vind; #include "diva_streaming_manager.h" #include "chan_capi_divastreaming_utils.h" #endif +#ifdef DIVA_STATUS +#include "divastatus_ifc.h" +#endif #include "chan_capi_mwi.h" /* #define CC_VERSION "x.y.z" */ diff --git a/divastatus/divastatus.c b/divastatus/divastatus.c new file mode 100644 index 0000000..3f0fc7b --- /dev/null +++ b/divastatus/divastatus.c @@ -0,0 +1,256 @@ +/* + * + Copyright (c) Dialogic(R), 2010 + + * + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + * + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + * + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/*! \file + * \brief Implements to access Diva management file system + * + * \par Access to Diva hardware state + * divalogd captures information from Diva management and exports + * it CVS file format. + * + */ +#include "divastreaming/platform.h" +#include +#include +#include +#include +#include +#include +#include "dlist.h" +#include "divastatus_parameters.h" +#include "divastatus_ifc.h" +#include "divastatus.h" +#ifdef CC_USE_INOTIFY +#include +#endif + +typedef const char* pcchar; + +static pcchar DIVA_STATUS_PATH = "/usr/lib/eicon/divas/registry/ifc"; +static pcchar DIVA_STATUS_FILE = "ifcstate"; +static pcchar DIVA_CONFIG_FILE = "info/Config"; +static pcchar DIVA_SERIAL_FILE = "serial"; +static pcchar DIVA_READ_ALARM_FILE = "info/Red Alarm"; +static pcchar DIVA_YELLOW_ALARM_FILE = "info/Yellow Alarm"; +static pcchar DIVA_BLUE_ALARM_FILE = "info/Blue Alarm"; + +/* + LOCALS + */ +static int diva_status_active(void); +static int diva_status_get_controller_state(int controller, diva_status_ifc_state_t *state); +static char* diva_status_read_file(unsigned int controller, const char* fileName); + +/*! + \brief Check divalogd is available + */ +static int diva_status_active(void) +{ + struct stat v; + + return ((stat(DIVA_STATUS_PATH, &v) == 0 && S_ISDIR(v.st_mode) != 0) ? 0 : -1); +} + +static char* diva_status_read_file(unsigned int controller, const char* fileName) +{ + int name_len = strlen(DIVA_STATUS_PATH) + strlen(fileName) + 32; + char name[name_len]; + struct stat v; + int fd; + int length; + char *data, *p; + + snprintf(name, name_len, "%s/adapter%u/%s", DIVA_STATUS_PATH, controller, fileName); + name[name_len-1] = 0; + + fd = open(name, O_RDONLY); + if (fd < 0) + return 0; + + if (fstat(fd, &v) != 0 || v.st_size == 0) { + close(fd); + return 0; + } + + length = MIN(v.st_size, 16U*1024U); + + data = diva_os_malloc(0, length+1); + if (data == 0) { + close (fd); + return 0; + } + + if (read(fd, data, length) != length) { + diva_os_free(0, data); + close(fd); + return (0); + } + + data[length] = 0; + + while (((p = strchr(data, '\n')) != 0) || ((p = strchr(data, '\r')))) { + *p = 0; + } + + return (data); +} + +static int diva_status_get_controller_state(int controller, diva_status_ifc_state_t *state) +{ + char *data, *p; + int i, pri; + const char* v; + + if (diva_status_active() != 0) + return -1; + + if ((data = diva_status_read_file(controller, DIVA_CONFIG_FILE)) == 0) + return -1; + + for (i = 0, pri = 0, p = data, v = strsep(&p, ","); + v != 0 && i < DivaStateIfcConfig_Max; + v = strsep(&p, ","), i++) { + switch ((diva_state_ifc_config_parameters_t)i) { + case DivaStateIfcConfig_TYPE: + pri += (strcmp ("PRI", v) == 0); + break; + + case DivaStateIfcConfig_PRI: + pri += (strcmp ("'YES'", v) == 0); + break; + + default: + break; + } + } + diva_os_free(0, data); + + if ((data = diva_status_read_file(controller, DIVA_STATUS_FILE)) == 0) + return (-1); + + memset (state, 0x00, sizeof(*state)); + state->ifcType = (pri == 2) ? DivaStatusIfcPri : DivaStatusIfcNotPri; + state->hwState = DivaStatusHwStateUnknown; + state->ifcL1State = DivaStatusIfcL2DoNotApply; + state->ifcL2State = DivaStatusIfcL2DoNotApply; + + for (i = 0, p = data, v = strsep (&p, ","); v != 0 && i < (int)DivaStateIfcState_Max; v = strsep (&p, ","), i++) { + switch ((diva_state_ifcstate_parameters_t)i) { + + case DivaStateIfcState_LAYER1_STATE: + if (state->ifcType == DivaStatusIfcPri) { + state->ifcL1State = (strcmp ("'Activated'", v) == 0) ? DivaStatusIfcL1OK : DivaStatusIfcL1Error; + } + break; + + case DivaStateIfcState_LAYER2_STATE: + if (state->ifcType == DivaStatusIfcPri) { + state->ifcL1State = (strcmp ("'Layer2 UP'", v) == 0) ? DivaStatusIfcL2OK : DivaStatusIfcL2Error; + } + break; + + case DivaStateIfcState_D2_X_FRAMES: + state->ifcTxDStatistics.Frames = (unsigned int)atol(data); + break; + case DivaStateIfcState_D2_X_BYTES: + state->ifcTxDStatistics.Bytes = (unsigned int)atol(data); + break; + case DivaStateIfcState_D2_X_ERRORS: + state->ifcTxDStatistics.Errors = (unsigned int)atol(data); + break; + case DivaStateIfcState_D2_R_FRAMES: + state->ifcRxDStatistics.Frames = (unsigned int)atol(data); + break; + case DivaStateIfcState_D2_R_BYTES: + state->ifcRxDStatistics.Bytes = (unsigned int)atol(data); + break; + case DivaStateIfcState_D2_R_ERRORS: + state->ifcRxDStatistics.Errors = (unsigned int)atol(data); + break; + + case DivaStateIfcState_MAX_TEMPERATURE: + state->maxTemperature = (unsigned int)atoi(data); + break; + case DivaStateIfcState_TEMPERATURE: + state->currentTemperature = (unsigned int)atoi(data); + break; + + case DivaStateIfcState_HARDWARE_STATE: + if (strcmp("'Active'", data) == 0) + state->hwState = DivaStateHwStateActive; + else if (strcmp("'Inactive'", data) == 0) + state->hwState = DivaStateHwStateInactive; + break; + + default: + break; + } + } + diva_os_free (0, data); + + if ((data = diva_status_read_file(controller, DIVA_READ_ALARM_FILE)) != 0) { + state->ifcAlarms.Red = strcmp("TRUE", data); + diva_os_free(0, data); + } + if ((data = diva_status_read_file(controller, DIVA_YELLOW_ALARM_FILE)) != 0) { + state->ifcAlarms.Yellow = strcmp("TRUE", data); + diva_os_free(0, data); + } + if ((data = diva_status_read_file(controller, DIVA_BLUE_ALARM_FILE)) != 0) { + state->ifcAlarms.Blue = strcmp("TRUE", data); + diva_os_free(0, data); + } + if ((data = diva_status_read_file(controller, DIVA_SERIAL_FILE)) != 0) { + state->serialNumber = (unsigned int)(atol(data)) & 0x00ffffff; + diva_os_free(0, data); + } + + return (0); +} + +/* + chan_capi interface + */ +diva_status_interface_state_t diva_status_get_interface_state(int controller) +{ + diva_status_ifc_state_t state; + int ret; + + ret = diva_status_get_controller_state(controller, &state); + + if ((ret != 0) || + (state.ifcType != DivaStatusIfcPri) || + (state.ifcL1State == DivaStatusIfcL2DoNotApply) || + (state.hwState == DivaStatusHwStateUnknown)) { + return (DivaStatusInterfaceStateNotAvailable); + } + + if ((state.ifcAlarms.Red == 0) && + (state.ifcAlarms.Yellow == 0) && + (state.ifcAlarms.Blue == 0) && + (state.hwState == DivaStateHwStateActive) && + (state.ifcL1State == DivaStatusIfcL1OK)) { + return DivaStatusInterfaceStateOK; + } + + return DivaStatusInterfaceStateERROR; +} + diff --git a/divastatus/divastatus.h b/divastatus/divastatus.h new file mode 100644 index 0000000..943c736 --- /dev/null +++ b/divastatus/divastatus.h @@ -0,0 +1,86 @@ +/* + * + Copyright (c) Dialogic(R), 2010 + + * + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + * + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + * + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/*! \file + * \brief Declares interface to access diva management file system + */ + +#ifndef __DIVA_STATUS_H__ +#define __DIVA_STATUS_H__ + +typedef enum _diva_status_ifc_type { + DivaStatusIfcNotPri = 0, + DivaStatusIfcPri, + DivaStatusIfcBri, + DivaStatusIfcAnalog +} diva_status_ifc_type_t; + +typedef struct _diva_status_ifc_alarms { + int Red; + int Blue; + int Yellow; +} diva_status_ifc_alarms_t; + +typedef enum _diva_status_ifc_l1_state { + DivaStatusIfcL1DoNotApply = 0, + DivaStatusIfcL1OK, + DivaStatusIfcL1Error +} diva_status_ifc_l1_state_t; + +typedef enum _diva_status_ifc_l2_state { + DivaStatusIfcL2DoNotApply = 0, + DivaStatusIfcL2OK, + DivaStatusIfcL2Error +} diva_status_ifc_l2_state_t; + +typedef enum _diva_status_ifc_hw_state { + DivaStatusHwStateUnknown = 0, + DivaStateHwStateActive = 1, + DivaStateHwStateInactive = 2 +} diva_status_ifc_hw_state_t; + +typedef struct _diva_status_ifc_statistics { + unsigned int Frames; + unsigned int Bytes; + unsigned int Errors; +} diva_status_ifc_statistics_t; + +typedef struct _diva_status_ifc_state { + diva_status_ifc_type_t ifcType; + diva_status_ifc_hw_state_t hwState; + diva_status_ifc_alarms_t ifcAlarms; + diva_status_ifc_l1_state_t ifcL1State; + diva_status_ifc_l2_state_t ifcL2State; + diva_status_ifc_statistics_t ifcRxDStatistics; + diva_status_ifc_statistics_t ifcTxDStatistics; + unsigned int serialNumber; + unsigned int maxTemperature; + unsigned int currentTemperature; +} diva_status_ifc_state_t; + +#define DIVA_STATUS_EVENT_L1 0x00000001U +#define DIVA_STATUS_EVENT_L2 0x00000002U +#define DIVA_STATUS_EVENT_ALARMS 0x00000004U +#define DIVA_STATUS_EVENT_STATISTICS 0x00000008U + +#endif + + diff --git a/divastatus/divastatus_ifc.h b/divastatus/divastatus_ifc.h new file mode 100644 index 0000000..f377f52 --- /dev/null +++ b/divastatus/divastatus_ifc.h @@ -0,0 +1,65 @@ +/* + * + Copyright (c) Dialogic(R), 2010 + + * + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + * + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + * + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/*! \file + * \brief Interface to chan_capi + */ + +#ifndef __DIVA_STATUS_IFC_H__ +#define __DIVA_STATUS_IFC_H__ + +typedef enum _diva_status_interface_state { + DivaStatusInterfaceStateNotAvailable = -1, + DivaStatusInterfaceStateOK = 0, + DivaStatusInterfaceStateERROR = 1, +} diva_status_interface_state_t; + +/*! + \brief activate event based status notifications + */ +void diva_status_init_interface (int controller); +/*! + \brief deactivate event based status notifications + */ +void diva_status_cleanup_interface (int controller); +/*! + \brief retrieve file handle to be used in async + I/O operations + */ +int diva_status_get_waitable_object (void); +/*! + \brief process status change events + */ +void diva_status_process_events (void); + +/*! + \brief Retrieve state of interface + DivaStatusInterfaceStateNotAvailable - ignore state + DivaStatusInterfaceStateOK - interface state verified and OK + DivaStatusInterfaceStateERROR - interface state verified and + can not be used to create calls + */ +diva_status_interface_state_t diva_status_get_interface_state (int controller); + + + + +#endif diff --git a/divastatus/divastatus_parameters.h b/divastatus/divastatus_parameters.h new file mode 100644 index 0000000..3728d87 --- /dev/null +++ b/divastatus/divastatus_parameters.h @@ -0,0 +1,132 @@ +/* + * + Copyright (c) Dialogic(R), 2010 + + * + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + * + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + * + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __DIVA_STATUS_PARAMETERS_H__ +#define __DIVA_STATUS_PARAMETERS_H__ + +/*! \brief ifcstate + */ +typedef enum _diva_state_ifcstate_parameters { + DivaStateIfcState_LAYER1_STATE = 0, + DivaStateIfcState_LAYER2_STATE, + DivaStateIfcState_INC_CALLS, + DivaStateIfcState_INC_CONNECTED, + DivaStateIfcState_INC_USER_BUSY, + DivaStateIfcState_INC_CALL_REJECTED, + DivaStateIfcState_INC_WRONG_NUMBER, + DivaStateIfcState_INC_INCOMPATIBLE_DST, + DivaStateIfcState_INC_OUT_OF_ORDER, + DivaStateIfcState_INC_IGNORED, + DivaStateIfcState_OUT_CALLS, + DivaStateIfcState_OUT_CONNECTED, + DivaStateIfcState_OUT_USER_BUSY, + DivaStateIfcState_OUT_NO_ANSWER, + DivaStateIfcState_OUT_WRONG_NUMBER, + DivaStateIfcState_OUT_CALL_REJECTED, + DivaStateIfcState_OUT_OTHER_FAILURES, + DivaStateIfcState_MDM_DISC_NORMAL, + DivaStateIfcState_MDM_DISC_UNSPECIFIED, + DivaStateIfcState_MDM_DISC_BUSY_TONE, + DivaStateIfcState_MDM_DISC_CONGESTION, + DivaStateIfcState_MDM_DISC_CARR_WAIT, + DivaStateIfcState_MDM_DISC_TRN_TIMEOUT, + DivaStateIfcState_MDM_DISC_INCOMPAT, + DivaStateIfcState_MDM_DISC_FRAME_REJ, + DivaStateIfcState_MDM_DISC_V42BIS, + DivaStateIfcState_FAX_DISC_NORMAL, + DivaStateIfcState_FAX_DISC_NOT_IDENT, + DivaStateIfcState_FAX_DISC_NO_RESPONSE, + DivaStateIfcState_FAX_DISC_RETRIES, + DivaStateIfcState_FAX_DISC_UNEXP_MSG, + DivaStateIfcState_FAX_DISC_NO_POLLING, + DivaStateIfcState_FAX_DISC_TRAINING, + DivaStateIfcState_FAX_DISC_UNEXPECTED, + DivaStateIfcState_FAX_DISC_APPLICATION, + DivaStateIfcState_FAX_DISC_INCOMPAT, + DivaStateIfcState_FAX_DISC_NO_COMMAND, + DivaStateIfcState_FAX_DISC_LONG_MSG, + DivaStateIfcState_FAX_DISC_SUPERVISOR, + DivaStateIfcState_FAX_DISC_SUB_SEP_PWD, + DivaStateIfcState_FAX_DISC_INVALID_MSG, + DivaStateIfcState_FAX_DISC_PAGE_CODING, + DivaStateIfcState_FAX_DISC_APP_TIMEOUT, + DivaStateIfcState_FAX_DISC_UNSPECIFIED, + DivaStateIfcState_B1_X_FRAMES, + DivaStateIfcState_B1_X_BYTES, + DivaStateIfcState_B1_X_ERRORS, + DivaStateIfcState_B1_R_FRAMES, + DivaStateIfcState_B1_R_BYTES, + DivaStateIfcState_B1_R_ERRORS, + DivaStateIfcState_B2_X_FRAMES, + DivaStateIfcState_B2_X_BYTES, + DivaStateIfcState_B2_X_ERRORS, + DivaStateIfcState_B2_R_FRAMES, + DivaStateIfcState_B2_R_BYTES, + DivaStateIfcState_B2_R_ERRORS, + DivaStateIfcState_D1_X_FRAMES, + DivaStateIfcState_D1_X_BYTES, + DivaStateIfcState_D1_X_ERRORS, + DivaStateIfcState_D1_R_FRAMES, + DivaStateIfcState_D1_R_BYTES, + DivaStateIfcState_D1_R_ERRORS, + DivaStateIfcState_D2_X_FRAMES, + DivaStateIfcState_D2_X_BYTES, + DivaStateIfcState_D2_X_ERRORS, + DivaStateIfcState_D2_R_FRAMES, + DivaStateIfcState_D2_R_BYTES, + DivaStateIfcState_D2_R_ERRORS, + DivaStateIfcState_INITIAL_TEMPERATURE, + DivaStateIfcState_MIN_TEMPERATURE, + DivaStateIfcState_MAX_TEMPERATURE, + DivaStateIfcState_TEMPERATURE, + DivaStateIfcState_DSPSTATE, + DivaStateIfcState_FAX_TX_PAGES_TOTAL, + DivaStateIfcState_FAX_TX_PAGES_RETRAIN, + DivaStateIfcState_FAX_TX_PAGES_REJECT, + DivaStateIfcState_FAX_RX_PAGES_TOTAL, + DivaStateIfcState_FAX_RX_PAGES_RETRAIN, + DivaStateIfcState_FAX_RX_PAGES_REJECT, + DivaStateIfcState_HARDWARE_STATE, + DivaStateIfcState_Max +} diva_state_ifcstate_parameters_t; + +typedef enum diva_state_ifc_config_parameters { + DivaStateIfcConfig_TYPE, + DivaStateIfcConfig_CHANNELS, + DivaStateIfcConfig_PROTOCOL, + DivaStateIfcConfig_NT_MODE, + DivaStateIfcConfig_POINTTOPOINT, + DivaStateIfcConfig_INTERFACENR, + DivaStateIfcConfig_BOARDREVISION, + DivaStateIfcConfig_SUBFUNCTION, + DivaStateIfcConfig_SUBDEVICE, + DivaStateIfcConfig_PROTOCOLBUILD, + DivaStateIfcConfig_DSPCODEBUILD, + DivaStateIfcConfig_ANALOGCHANNELS, + DivaStateIfcConfig_PRI, + DivaStateIfcConfig_PCIDMA, + DivaStateIfcConfig_ADAPTERTYPE, + DivaStateIfcConfig_LAW, + DivaStateIfcConfig_Max +} diva_state_ifc_config_parameters_t; + +#endif +