ANSC_STATUS CcspCwmpsoDiscardCwmpEvent ( ANSC_HANDLE hThisObject, int EventCode ) { PCCSP_CWMP_SESSION_OBJECT pMyObject = (PCCSP_CWMP_SESSION_OBJECT )hThisObject; PCCSP_CWMP_EVENT pCcspCwmpEvent = (PCCSP_CWMP_EVENT )NULL; ULONG i = 0; ULONG j = 0; /* * According to WT151, only the event "6 CONNECTIONREQUEST" must NOT retry delivery and it's a * single type event. * * Let's find and discard it; */ for( i = 0; i < pMyObject->EventCount; i ++) { pCcspCwmpEvent = (PCCSP_CWMP_EVENT)pMyObject->EventArray[i]; if ( ( EventCode == CCSP_CWMPSO_EVENTCODE_ConnectionRequest && AnscEqualString(pCcspCwmpEvent->EventCode, CCSP_CWMP_INFORM_EVENT_NAME_ConnectionRequest, TRUE) ) || ( EventCode == CCSP_CWMPSO_EVENTCODE_ValueChange && AnscEqualString(pCcspCwmpEvent->EventCode, CCSP_CWMP_INFORM_EVENT_NAME_ValueChange, TRUE) ) ) { if ( EventCode == CCSP_CWMPSO_EVENTCODE_ConnectionRequest ) { CcspTr069PaTraceWarning(("Before the session retry, the event '%s' was discarded.\n", CCSP_CWMP_INFORM_EVENT_NAME_ConnectionRequest)); } else { CcspTr069PaTraceWarning(("The event with code %d was discarded.\n", EventCode)); } CcspCwmpFreeEvent(pCcspCwmpEvent); pMyObject->EventArray[i] = NULL; /* move the reminder event back */ for( j = i; j < pMyObject->EventCount - 1; j ++) { pMyObject->EventArray[j] = pMyObject->EventArray[j + 1]; } pMyObject->EventArray[pMyObject->EventCount - 1] = NULL; pMyObject->EventCount --; } } return ANSC_STATUS_SUCCESS;; }
BOOL CcspCwmppoGetInitialContactFactory ( ANSC_HANDLE hThisObject ) { PCCSP_CWMP_PROCESSOR_OBJECT pMyObject = (PCCSP_CWMP_PROCESSOR_OBJECT )hThisObject; PCCSP_CWMP_CPE_CONTROLLER_OBJECT pCcspCwmpCpeController = (PCCSP_CWMP_CPE_CONTROLLER_OBJECT )pMyObject->hCcspCwmpCpeController; BOOL bInitialContactFactory = FALSE; if ( !s_bICLoaded ) { char* pValue = NULL; char psmKeyPrefixed[CCSP_TR069PA_PSM_NODE_NAME_MAX_LEN + 16]; CcspCwmpPrefixPsmKey(psmKeyPrefixed, pCcspCwmpCpeController->SubsysName, CCSP_TR069PA_PSM_KEY_InitialContactFactory); pValue = pCcspCwmpCpeController->LoadCfgFromPsm ( (ANSC_HANDLE)pCcspCwmpCpeController, psmKeyPrefixed ); bInitialContactFactory = pValue ? _ansc_atoi(pValue) : TRUE; CcspTr069PaTraceWarning(("InitialContact read from PSM is: <%s>\n", bInitialContactFactory ? "TRUE":"FALSE")); if ( pValue ) { CcspTr069PaFreeMemory(pValue); } } return bInitialContactFactory; }
static ANSC_STATUS CcspTr069PaSsp_XML_GetMultipleItemWithSameName ( PANSC_XML_DOM_NODE_OBJECT pRootNode, char* ItemName, char** retVal ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PANSC_XML_DOM_NODE_OBJECT pChildNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; char buffer[512] = {0}; ULONG uLength = 511; if (pRootNode && ItemName && retVal) { if(*retVal) { CcspTr069PaFreeMemory(*retVal); *retVal = NULL; } pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pRootNode, ItemName); while( pChildNode != NULL) { if (AnscEqualString(pChildNode->Name, ItemName, TRUE)) { uLength = 511; // uLength: passes in max buffer length; gets out actual length if (pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength) == ANSC_STATUS_SUCCESS && uLength > 0) { if(*retVal) { char* sptr = (char*)CcspTr069PaAllocateMemory(AnscSizeOfString(*retVal)+1+uLength+1); if(sptr == NULL) { CcspTr069PaTraceWarning(("Failed to reallocate returnCA\n")); CcspTr069PaFreeMemory(*retVal); *retVal = NULL; returnStatus = ANSC_STATUS_RESOURCES; goto EXIT; } _ansc_sprintf(sptr, "%s,%s", *retVal, buffer); CcspTr069PaFreeMemory(*retVal); *retVal = sptr; } else *retVal = CcspTr069PaCloneString(buffer); } } pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetNextChild(pRootNode, pChildNode); } CcspTr069PaTraceDebug(("%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL")); // fprintf(stderr, "%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL"); } EXIT: return returnStatus; }
ANSC_STATUS CcspCwmpsoSaveCwmpEvent ( ANSC_HANDLE hThisObject ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCCSP_CWMP_SESSION_OBJECT pMyObject = (PCCSP_CWMP_SESSION_OBJECT )hThisObject; PCCSP_CWMP_EVENT pCcspCwmpEvent = (PCCSP_CWMP_EVENT )NULL; PCCSP_CWMP_CPE_CONTROLLER_OBJECT pCcspCwmpCpeController = (PCCSP_CWMP_CPE_CONTROLLER_OBJECT)pMyObject->hCcspCwmpCpeController; PCCSP_CWMP_CFG_INTERFACE pCcspCwmpCfgIf = (PCCSP_CWMP_CFG_INTERFACE )pCcspCwmpCpeController->GetCcspCwmpCfgIf((ANSC_HANDLE)pCcspCwmpCpeController); char pSavedEvents[CCSP_CWMP_SAVED_EVENTS_MAX_LEN] = { 0 }; PCHAR pCurBuf = pSavedEvents; ULONG i = 0; ULONG uLength = 0; char* pRootObjName = pCcspCwmpCpeController->GetRootObject((ANSC_HANDLE)pCcspCwmpCpeController); BOOL bRootDevice = AnscEqualString(pRootObjName, DM_ROOTNAME, FALSE); /* * All the undiscarded events will be saved in a string seperated by a ',' and put as * the value of parameter "(InternetGateway)Device.ManagementServer.SavedEvents". */ for( i = 0; i < pMyObject->EventCount; i ++) { pCcspCwmpEvent = (PCCSP_CWMP_EVENT)pMyObject->EventArray[i]; if( CcspCwmpIsUndiscardedEvent(pCcspCwmpEvent->EventCode)) { if( pCurBuf != pSavedEvents) { pCurBuf[0] = ','; pCurBuf ++; } uLength = AnscSizeOfString(pCcspCwmpEvent->EventCode); if( pCurBuf + uLength >= pSavedEvents + CCSP_CWMP_SAVED_EVENTS_MAX_LEN) { CcspTr069PaTraceWarning(("Too many events to save, ignored.\n")); break; } AnscCopyMemory(pCurBuf, pCcspCwmpEvent->EventCode, uLength); pCurBuf += uLength; pCurBuf[0]= '+'; pCurBuf ++; if( pCcspCwmpEvent->CommandKey ) { uLength = AnscSizeOfString(pCcspCwmpEvent->CommandKey); if( uLength > 0) { if( pCurBuf + uLength >= pSavedEvents + CCSP_CWMP_SAVED_EVENTS_MAX_LEN) { CcspTr069PaTraceWarning(("Too many events to save, ignored.\n")); break; } AnscCopyMemory(pCurBuf, pCcspCwmpEvent->EventCode, uLength); pCurBuf += uLength; } } } } if( AnscSizeOfString(pSavedEvents) > 0) { char psmKeyPrefixed[CCSP_TR069PA_PSM_NODE_NAME_MAX_LEN + 16]; CcspCwmpPrefixPsmKey(psmKeyPrefixed, pCcspCwmpCpeController->SubsysName, CCSP_TR069PA_PSM_KEY_SavedEvents); CcspTr069PaTraceDebug(("Save the event to the registry before reboot:\n%s\n", pSavedEvents)); returnStatus = pCcspCwmpCpeController->SaveCfgToPsm ( (ANSC_HANDLE)pCcspCwmpCpeController, psmKeyPrefixed, pSavedEvents ); } return returnStatus; }
ANSC_STATUS CcspCwmpsoAddCwmpEvent ( ANSC_HANDLE hThisObject, ANSC_HANDLE hCwmpEvent, BOOL bConnectNow ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; PCCSP_CWMP_SESSION_OBJECT pMyObject = (PCCSP_CWMP_SESSION_OBJECT )hThisObject; PCCSP_CWMP_PROCESSOR_OBJECT pCcspCwmpProcessor = (PCCSP_CWMP_PROCESSOR_OBJECT )pMyObject->hCcspCwmpProcessor; PCCSP_CWMP_EVENT pCcspCwmpEvent = (PCCSP_CWMP_EVENT )hCwmpEvent; PCCSP_CWMP_EVENT pCcspCwmpEventExist= (PCCSP_CWMP_EVENT )NULL; BOOL bExist = FALSE; ULONG i = 0; if ( pMyObject->EventCount >= CCSP_CWMPSO_MAX_EVENT_NUMBER ) { CcspCwmpFreeEvent(pCcspCwmpEvent); } else { /* * Bin Zhu updated here on 12/18/2006 * According to WT151, for all the single event (starts with a number "0" - "9"), * If there's only already in the array, the new one will be discarded. */ if( pCcspCwmpEvent->EventCode[0] >= '0' && pCcspCwmpEvent->EventCode[0] <= '9') { for( i = 0; i < pMyObject->EventCount; i ++) { pCcspCwmpEventExist = (PCCSP_CWMP_EVENT)pMyObject->EventArray[i]; if( AnscEqualString(pCcspCwmpEvent->EventCode, pCcspCwmpEventExist->EventCode, TRUE)) { bExist = TRUE; CcspTr069PaTraceWarning(("The event '%s' is already there, discarded.\n", pCcspCwmpEvent->EventCode)); break; } } } else if ( pCcspCwmpEvent->EventCode[0] >= 'M' ) { for( i = 0; i < pMyObject->EventCount; i ++) { pCcspCwmpEventExist = (PCCSP_CWMP_EVENT)pMyObject->EventArray[i]; if ( AnscEqualString(pCcspCwmpEvent->EventCode, pCcspCwmpEventExist->EventCode, TRUE) && ( (!pCcspCwmpEvent->CommandKey && !pCcspCwmpEventExist->CommandKey) || (pCcspCwmpEvent->CommandKey && pCcspCwmpEventExist->CommandKey && AnscEqualString(pCcspCwmpEvent->CommandKey, pCcspCwmpEventExist->CommandKey, TRUE)) ) ) { bExist = TRUE; CcspTr069PaTraceWarning (( "The event '%s' with CommandKey '%s' is already there, discarded.\n", pCcspCwmpEvent->EventCode, pCcspCwmpEvent->CommandKey )); break; } } } if( !bExist ) { pMyObject->EventArray[pMyObject->EventCount++] = (ANSC_HANDLE)pCcspCwmpEvent; CcspTr069PaTraceDebug(("<RT> Event '%s' with CommandKey '%s' added at location '%d'\n", pCcspCwmpEvent->EventCode, pCcspCwmpEvent->CommandKey, pMyObject->EventCount)); } else { CcspCwmpFreeEvent(pCcspCwmpEvent); } } if ( bConnectNow ) { PANSC_TIMER_DESCRIPTOR_OBJECT pDelayedActiveNotifTimerObj = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hDelayedActiveNotifTimerObj; PCCSP_CWMP_PROCESSOR_PROPERTY pProperty = (PCCSP_CWMP_PROCESSOR_PROPERTY)&pCcspCwmpProcessor->Property; BOOL bInformDelayed = FALSE; PCCSP_CWMP_EVENT pFirstEvent = (PCCSP_CWMP_EVENT)pMyObject->EventArray[0]; /* Active Notification Throttling */ if ( pMyObject->EventCount == 1 /* "4 VALUE CHANGE" event is the only one to trigger Inform */ && AnscEqualString(pFirstEvent->EventCode, CCSP_CWMP_INFORM_EVENT_NAME_ValueChange, TRUE) && pProperty->DefActiveNotifThrottle != 0 && pProperty->LastActiveNotifTime != 0 ) { /* calculate the delay inform timer interval */ ULONG ulTimeNow = AnscGetTickInSeconds(); ULONG ulDelta = 0; ULONG ulInterval= 0; if ( ulTimeNow >= pProperty->LastActiveNotifTime ) { ulDelta = ulTimeNow - pProperty->LastActiveNotifTime; } else { ulDelta = 0xFFFFFFFF - pProperty->LastActiveNotifTime + ulTimeNow; } if ( ulDelta < pProperty->DefActiveNotifThrottle ) { bInformDelayed = TRUE; ulInterval = pProperty->DefActiveNotifThrottle - ulDelta; CcspTr069PaTraceDebug(("Active notification will be delayed by %u seconds\n", ulInterval)); if ( !pMyObject->bDelayedActiveNotifTimerScheduled ) { pDelayedActiveNotifTimerObj->SetInterval((ANSC_HANDLE)pDelayedActiveNotifTimerObj, ulInterval * 1000); pDelayedActiveNotifTimerObj->Start((ANSC_HANDLE)pDelayedActiveNotifTimerObj); pMyObject->bDelayedActiveNotifTimerScheduled = TRUE; } } } if ( !bInformDelayed ) { ULONG ulActiveSessions = pCcspCwmpProcessor->GetActiveWmpSessionCount((ANSC_HANDLE)pCcspCwmpProcessor, TRUE); if ( ulActiveSessions == 0 ) { pMyObject->SessionState = CCSP_CWMPSO_SESSION_STATE_connectNow; returnStatus = pCcspCwmpProcessor->SignalSession ( (ANSC_HANDLE)pCcspCwmpProcessor, (ANSC_HANDLE)pMyObject ); } else { pMyObject->bInformWhenActive = TRUE; } } } return returnStatus; }
ANSC_STATUS CcspTr069PaSsp_LoadCfgFile ( char* pCfgFileName ) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; char* pXMLContent = NULL; ULONG uBufferSize = 0; char partnerID[128]; /* load configuration file */ { ANSC_HANDLE pFileHandle = NULL; pFileHandle = AnscOpenFile ( pCfgFileName, ANSC_FILE_O_BINARY | ANSC_FILE_O_RDONLY, ANSC_FILE_S_IREAD ); if( pFileHandle == NULL) { CcspTr069PaTraceWarning(("Failed to open file %s\n", pCfgFileName)); return ANSC_STATUS_FAILURE; } uBufferSize = AnscGetFileSize(pFileHandle) + 8; pXMLContent = (char*)AnscAllocateMemory(uBufferSize); if (pXMLContent == NULL) { CcspTr069PaTraceWarning(("Failed to allocate buffer\n")); AnscCloseFile(pFileHandle); return ANSC_STATUS_RESOURCES; } if ( AnscReadFile(pFileHandle, pXMLContent, &uBufferSize) != ANSC_STATUS_SUCCESS ) { CcspTr069PaTraceWarning(("Failed to read file %s\n", pCfgFileName)); AnscFreeMemory(pXMLContent); AnscCloseFile(pFileHandle); return ANSC_STATUS_FAILURE; } AnscCloseFile(pFileHandle); } /* * Parse the XML content */ { PANSC_XML_DOM_NODE_OBJECT pRootNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; PANSC_XML_DOM_NODE_OBJECT pChildNode = (PANSC_XML_DOM_NODE_OBJECT)NULL; char* pXMLIterator = pXMLContent; pRootNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomParseString((ANSC_HANDLE)NULL, (PCHAR*)&pXMLIterator, uBufferSize); if ( pRootNode == NULL ) { CcspTr069PaTraceWarning(("Failed to parse the file to retrieve the root node!\n")); returnStatus = ANSC_STATUS_FAILURE; goto EXIT; } #ifdef _ANSC_USE_OPENSSL_ pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetChildByName(pRootNode, CCSP_TR069PA_CFG_Name_Certificates); if ( pChildNode != NULL) { CcspTr069PaSsp_XML_GetMultipleItemWithSameName(pChildNode, CCSP_TR069PA_CERTIFICATE_CFG_Name_ca, &openssl_client_ca_certificate_files); CcspTr069PaSsp_XML_GetOneItemByName(pChildNode, CCSP_TR069PA_CERTIFICATE_CFG_Name_dev, &openssl_client_dev_certificate_file); CcspTr069PaSsp_XML_GetOneItemByName(pChildNode, CCSP_TR069PA_CERTIFICATE_CFG_Name_pkey, &openssl_client_private_key_file); } #endif CcspTr069PaSsp_XML_GetOneItemByName(pRootNode, CCSP_TR069PA_CFG_Name_Outbound_If, &g_Tr069PaOutboundIfName); CcspTr069PaSsp_GetPartnerID(partnerID); if (strcmp(partnerID,"comcast")==0) { CcspTr069PaSsp_XML_GetOneItemByName(pRootNode, CCSP_TR069PA_CFG_Name_AcsDefAddr, &g_Tr069PaAcsDefAddr); } else { CcspTr069PaSsp_XML_GetOneItemByName(pRootNode, partnerID, &g_Tr069PaAcsDefAddr); } returnStatus = ANSC_STATUS_SUCCESS; } EXIT: AnscFreeMemory(pXMLContent); return returnStatus; }
/********************************************************************** prototype: ULONG CcspCwmpSoappoUtilGetCwmpMethod ( PCHAR pMethodName, BOOL bFromServer ); description: This function is called to find method value based on the name. argument: PCHAR pMethodName The method name BOOL bFromServer It's a server side method or not; return: the method name; **********************************************************************/ ULONG CcspCwmpSoappoUtilGetCwmpMethod ( PCHAR pMethodName, BOOL bFromServer ) { if(AnscEqualString(pMethodName,"GetRPCMethods",TRUE)) { return CCSP_CWMP_METHOD_GetRPCMethods; } if( !bFromServer) { if(AnscEqualString(pMethodName,"SetParameterValues",TRUE)) { return CCSP_CWMP_METHOD_SetParameterValues; } else if(AnscEqualString(pMethodName,"GetParameterValues",TRUE)) { return CCSP_CWMP_METHOD_GetParameterValues; } else if(AnscEqualString(pMethodName,"GetParameterNames",TRUE)) { return CCSP_CWMP_METHOD_GetParameterNames; } else if(AnscEqualString(pMethodName,"SetParameterAttributes",TRUE)) { return CCSP_CWMP_METHOD_SetParameterAttributes; } else if(AnscEqualString(pMethodName,"GetParameterAttributes",TRUE)) { return CCSP_CWMP_METHOD_GetParameterAttributes; } else if(AnscEqualString(pMethodName,"AddObject",TRUE)) { return CCSP_CWMP_METHOD_AddObject; } else if(AnscEqualString(pMethodName,"DeleteObject",TRUE)) { return CCSP_CWMP_METHOD_DeleteObject; } else if(AnscEqualString(pMethodName,"Reboot",TRUE)) { return CCSP_CWMP_METHOD_Reboot; } else if(AnscEqualString(pMethodName,"Download",TRUE)) { return CCSP_CWMP_METHOD_Download; } else if(AnscEqualString(pMethodName,"Upload",TRUE)) { return CCSP_CWMP_METHOD_Upload; } else if(AnscEqualString(pMethodName,"FactoryReset",TRUE)) { return CCSP_CWMP_METHOD_FactoryReset; } else if(AnscEqualString(pMethodName,"ChangeDUState",TRUE)) { return CCSP_CWMP_METHOD_ChangeDUState; } else if(AnscEqualString(pMethodName,"GetQueuedTransfers",TRUE)) { return CCSP_CWMP_METHOD_GetQueuedTransfers; } else if(AnscEqualString(pMethodName,"ScheduleInform",TRUE)) { return CCSP_CWMP_METHOD_ScheduleInform; } else if(AnscEqualString(pMethodName,"SetVouchers",TRUE)) { return CCSP_CWMP_METHOD_SetVouchers; } else if(AnscEqualString(pMethodName,"GetOptions",TRUE)) { return CCSP_CWMP_METHOD_GetOptions; } else { CcspTr069PaTraceWarning(("Unknown CWMP Client Method name: '%s'\n", pMethodName)); return 0; } } else { if(AnscEqualString(pMethodName,"Inform",TRUE)) { return CCSP_CWMP_METHOD_Inform; } else if(AnscEqualString(pMethodName,"TransferComplete",TRUE)) { return CCSP_CWMP_METHOD_TransferComplete; } else if(AnscEqualString(pMethodName,"AutonomousTransferComplete",TRUE)) { return CCSP_CWMP_METHOD_AutonomousTransferComplete; } else if(AnscEqualString(pMethodName, "DUStateChangeComplete",TRUE)) { return CCSP_CWMP_METHOD_DUStateChangeComplete; } else if(AnscEqualString(pMethodName, "AutonomousDUStateChangeComplete",TRUE)) { return CCSP_CWMP_METHOD_AutonomousDUStateChangeComplete; } else if(AnscEqualString(pMethodName,"RequestDownload",TRUE)) { return CCSP_CWMP_METHOD_RequestDownload; } else if(AnscEqualString(pMethodName,"Kicked",TRUE)) { return CCSP_CWMP_METHOD_Kicked; } else { CcspTr069PaTraceWarning(("Unknown CWMP Server Method name: '%s'\n", pMethodName)); return 0; } } }