void diva_status_process_events(void) { diva_entity_link_t* link; /* Polling */ for (link = diva_q_get_head(&controller_q); link != 0; link = diva_q_get_next(link)) { diva_status_ifc_t *controllerState = DIVAS_CONTAINING_RECORD(link, diva_status_ifc_t, link); if ((controllerState->ifstateWd < 0) || (controllerState->infoWd < 0)) { int currentState = controllerState->currentState; diva_status_create_wd(&controllerState->ifstateWd, controllerState->idiController, DIVA_STATUS_FILE, 0); diva_status_create_wd(&controllerState->infoWd, controllerState->idiController, DIVA_INFO_FILE, 1); controllerState->currentState = (controllerState->currentState + 1) % 2; diva_status_get_controller_state(controllerState->idiController, &controllerState->state[controllerState->currentState]); diva_status_process_event(controllerState, currentState, controllerState->currentState); } } /* Events */ #ifdef CC_USE_INOTIFY if (inotifyFd >= 0 && divaFsWd >= 0) { unsigned char buffer[1024]; int length; int i; while ((length = read(inotifyFd, buffer, sizeof(buffer))) > 0) { i = 0; while (i < length) { struct inotify_event *event = (struct inotify_event*)&buffer[i]; if ((event->mask & (IN_IGNORED|IN_DELETE_SELF|IN_UNMOUNT|IN_Q_OVERFLOW)) != 0) { diva_status_cleanup_wd((event->mask & IN_IGNORED) == 0 ? event->wd : -1); break; } if (event->wd != divaFsWd) { for (link = diva_q_get_head(&controller_q); link != 0; link = diva_q_get_next(link)) { diva_status_ifc_t *controllerState = DIVAS_CONTAINING_RECORD(link, diva_status_ifc_t, link); if ((controllerState->ifstateWd == event->wd) || (controllerState->infoWd == event->wd)) { int currentState = controllerState->currentState; controllerState->currentState = (controllerState->currentState + 1) % 2; diva_status_get_controller_state(controllerState->idiController, &controllerState->state[controllerState->currentState]); diva_status_process_event(controllerState, currentState, controllerState->currentState); } } } i += sizeof(*event) + event->len; } } } #endif }
void diva_status_cleanup_interface (int controller) { diva_entity_link_t* link; for (link = diva_q_get_head(&controller_q); link != 0; link = diva_q_get_next(link)) { diva_status_ifc_t *controllerState = DIVAS_CONTAINING_RECORD(link, diva_status_ifc_t, link); if (controllerState->capiController == controller) { diva_q_remove(&controller_q, link); #ifdef CC_USE_INOTIFY if (controllerState->ifstateWd >= 0) inotify_rm_watch(inotifyFd, controllerState->ifstateWd); if (controllerState->infoWd >= 0) inotify_rm_watch(inotifyFd, controllerState->infoWd); #endif ast_free (controllerState); break; } } #ifdef CC_USE_INOTIFY if (diva_q_get_head(&controller_q) == 0) { if (divaFsWd >= 0) { inotify_rm_watch(inotifyFd, divaFsWd); divaFsWd = -1; } if (inotifyFd >= 0) { close(inotifyFd); inotifyFd = -1; } } #endif }
int pbxcli_capi_ifc_status(int fd, int argc, char *argv[]) #endif { diva_entity_link_t* link; #ifdef CC_AST_HAS_VERSION_1_6 int fd = a->fd; if (cmd == CLI_INIT) { e->command = CC_MESSAGE_NAME " ifcstate"; e->usage = diva_status_ifc_state_usage; return NULL; } else if (cmd == CLI_GENERATE) return NULL; if (a->argc != e->args) return CLI_SHOWUSAGE; #else if (argc != 2) return RESULT_SHOWUSAGE; #endif if ( diva_q_get_head(&controller_q) == NULL) { ast_cli(fd, "There are no interraces in " CC_MESSAGE_NAME " instance.\n"); return RESULT_SUCCESS; } ast_cli(fd, CC_MESSAGE_NAME " interfaces\n"); ast_cli(fd, "%s %-9s%-4s%-4s%-4s%-7s%-5s%8s%12s%12s%12s%12s\n", "INTERFACE", "State", "L1", "L2", "RED", "YELLOW", "BLUE", "D-Rx-Frames", "D-Rx-Bytes","D-Tx-Frames", "D-Tx-Bytes", "D-Errors"); for (link = diva_q_get_head(&controller_q); link != 0; link = diva_q_get_next(link)) { diva_status_ifc_t *controllerState = DIVAS_CONTAINING_RECORD(link, diva_status_ifc_t, link); diva_status_ifc_state_t* state = &controllerState->state[controllerState->currentState]; ast_cli(fd, "ISDN%-3d%-2s %-9s%-4s%-4s%-4s%-7s%-3s %12d %11d %11d %11d %11d\n", controllerState->capiController, "", pbxcli_get_visual_ifc_state(state), pbxcli_get_visual_ifc_l1_state(state), pbxcli_get_visual_ifc_l2_state(state), ((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ? (state->ifcAlarms.Red != 0 ? "On" : "Off") : "-", ((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ? (state->ifcAlarms.Yellow != 0 ? "On" : "Off") : "-", ((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ? (state->ifcAlarms.Blue != 0 ? "On" : "Off") : "-", state->ifcRxDStatistics.Frames, state->ifcRxDStatistics.Bytes, state->ifcTxDStatistics.Frames, state->ifcTxDStatistics.Bytes, state->ifcRxDStatistics.Errors + state->ifcTxDStatistics.Errors ); } #ifdef CC_AST_HAS_VERSION_1_6 return CLI_SUCCESS; #else return RESULT_SUCCESS; #endif }
static void diva_status_cleanup_wd(int wd) { diva_entity_link_t* link; for (link = diva_q_get_head(&controller_q); link != 0; link = diva_q_get_next(link)) { diva_status_ifc_t *controllerState = DIVAS_CONTAINING_RECORD(link, diva_status_ifc_t, link); if ((controllerState->ifstateWd >= 0) && (wd != controllerState->ifstateWd)) { inotify_rm_watch(inotifyFd, controllerState->ifstateWd); } controllerState->ifstateWd = -1; if ((controllerState->infoWd >= 0) && (wd != controllerState->infoWd)) { inotify_rm_watch(inotifyFd, controllerState->infoWd); } controllerState->infoWd = -1; } if ((divaFsWd >= 0) && (wd != divaFsWd)) { inotify_rm_watch(inotifyFd, divaFsWd); } divaFsWd = -1; }
/* -------------------------------------------------------------------------- Add card to the card list -------------------------------------------------------------------------- */ void *diva_driver_add_card(void *pdev, unsigned long CardOrdinal) { diva_os_spin_lock_magic_t old_irql; diva_os_xdi_adapter_t *pdiva, *pa; int i, j, max, nr; for (i = 0; divas_supported_cards[i].CardOrdinal != -1; i++) { if (divas_supported_cards[i].CardOrdinal == CardOrdinal) { if (!(pdiva = divas_create_pci_card(i, pdev))) { return (0); } switch (CardOrdinal) { case CARDTYPE_DIVASRV_Q_8M_PCI: case CARDTYPE_DIVASRV_VOICE_Q_8M_PCI: case CARDTYPE_DIVASRV_Q_8M_V2_PCI: case CARDTYPE_DIVASRV_VOICE_Q_8M_V2_PCI: max = MAX_ADAPTER - 4; nr = 4; break; default: max = MAX_ADAPTER; nr = 1; } diva_os_enter_spin_lock(&adapter_lock, &old_irql, "add card"); for (i = 0; i < max; i++) { if (!diva_find_free_adapters(i, nr)) { pdiva->controller = i + 1; pdiva->xdi_adapter.ANum = pdiva->controller; IoAdapters[i] = &pdiva->xdi_adapter; diva_os_leave_spin_lock(&adapter_lock, &old_irql, "add card"); create_adapter_proc(pdiva); /* add adapter to proc file system */ DBG_LOG(("add %s:%d", CardProperties [CardOrdinal].Name, pdiva->controller)) diva_os_enter_spin_lock(&adapter_lock, &old_irql, "add card"); pa = pdiva; for (j = 1; j < nr; j++) { /* slave adapters, if any */ pa = (diva_os_xdi_adapter_t *) diva_q_get_next(&pa->link); if (pa && !pa->interface.cleanup_adapter_proc) { pa->controller = i + 1 + j; pa->xdi_adapter.ANum = pa->controller; IoAdapters[i + j] = &pa->xdi_adapter; diva_os_leave_spin_lock(&adapter_lock, &old_irql, "add card"); DBG_LOG(("add slave adapter (%d)", pa->controller)) create_adapter_proc(pa); /* add adapter to proc file system */ diva_os_enter_spin_lock(&adapter_lock, &old_irql, "add card"); } else { DBG_ERR(("slave adapter problem")) break; } } diva_os_leave_spin_lock(&adapter_lock, &old_irql, "add card"); return (pdiva); } } diva_os_leave_spin_lock(&adapter_lock, &old_irql, "add card"); /* Not able to add adapter - remove it and return error */ DBG_ERR(("can not alloc request array")) diva_driver_remove_card(pdiva); return (0); } }