static ANSC_STATUS
Local_CosaDmlGetParamValueByPathName
    (
        const char *pathName,
        char *pValue,
        PULONG pulSize
    )
{

    ANSC_STATUS retval = ANSC_STATUS_FAILURE;
    parameterValStruct_t varStruct;
    char outdata[80];
    int size = sizeof(outdata);

    varStruct.parameterName = pathName;
    varStruct.parameterValue = outdata;

    retval = COSAGetParamValueByPathName(bus_handle, &varStruct, &size);
    
    if ( retval != ANSC_STATUS_SUCCESS) 
    {
        return ANSC_STATUS_FAILURE;
    }
    else 
    {
        AnscCopyString(pValue, outdata);
        *pulSize = AnscSizeOfString(pValue);
        return ANSC_STATUS_SUCCESS;
    }
}
int hotspot_update_circuit_ids(int greinst, int queuestart) {
    int retval = 0;
    char localinterfaces[200];
    char paramname[60];
    char circuitid[100];
    char outdata[80];
    char* save = NULL;
    char* curInt = NULL;
    int nameSave = 0;
    int circuitSave = 0;
    int ssidInst = 0;
    int size;
    int inst;
    parameterValStruct_t varStruct;
    varStruct.parameterName = paramname;
    varStruct.parameterValue = outdata;
//     /*if (ppComponents == NULL) {
//         initWifiComp();
//     }*/
    
    //snprintf(paramname, sizeof(paramname), 
    GrePsmGetStr(GRE_PARAM_LOCALIFS, greinst, localinterfaces, sizeof(localinterfaces));
    
    curInt = strtok_r(localinterfaces, ",", &save);
    
    while (curInt) {
        circuitSave=0;
        //Trim off the trailing dot if it exists
        size = strlen(curInt);
        if (curInt[size -1] == '.')
            curInt[size - 1]='\0';
        
        inst = atoi(strrchr(curInt,'.')+1);
        
        size = sizeof(outdata);
        
        if (syscfg_get(NULL, "wan_physical_ifname", paramname, sizeof(paramname)) != 0) {
            AnscTraceWarning(("fail to get wan_physical_ifname\n"));
            snprintf(paramname, sizeof(paramname), "erouter0");
        }
        if (get_if_hwaddr(paramname, circuitid, sizeof(circuitid)) != 0) {
            AnscTraceWarning(("fail to get HW Addr for %s\n", paramname));
            snprintf(circuitid, sizeof(circuitid), "00:00:00:00:00:00");
        }

        circuitSave = strlen(circuitid);
        circuitSave += snprintf(circuitid + circuitSave, sizeof(circuitid) - circuitSave, ";");
#if 0
        snprintf(paramname, sizeof(paramname), "%s.%s", curInt, "BSSID");
        retval = COSAGetParamValueByPathName(bus_handle, &varStruct, &size);
        if ( retval != ANSC_STATUS_SUCCESS)
            return -1;
        circuitSave = snprintf(circuitid, sizeof(circuitid), "%s;", varStruct.parameterValue);
#endif
        
        size = sizeof(outdata);
        snprintf(paramname, sizeof(paramname),"%s.%s", curInt, "SSID");
        retval = COSAGetParamValueByPathName(bus_handle, &varStruct, &size);
        if ( retval != ANSC_STATUS_SUCCESS)
            return -1;
        circuitSave += snprintf(circuitid + circuitSave, sizeof(circuitid) - circuitSave, "%s;", varStruct.parameterValue);
        
        size = sizeof(outdata);
        snprintf(paramname, sizeof(paramname), "Device.WiFi.AccessPoint.%d.Security.ModeEnabled", inst);
        retval = COSAGetParamValueByPathName(bus_handle, &varStruct, &size);
        if ( retval != ANSC_STATUS_SUCCESS)
            return -1;
        if(strcmp("None", varStruct.parameterValue)) {
            snprintf(circuitid + circuitSave, sizeof(circuitid) - circuitSave, "s");
        } else {
            snprintf(circuitid + circuitSave, sizeof(circuitid) - circuitSave, "o");
        }
        
        snprintf(paramname, sizeof(paramname), "snooper-queue%d-circuitID", queuestart);
        
        sysevent_set(sysevent_fd, sysevent_token, paramname, circuitid, 0);
        
        snprintf(paramname, sizeof(paramname), "snooper-ssid%d-index", queuestart++);
        snprintf(outdata, sizeof(outdata), "%d", inst);
        
        sysevent_set(sysevent_fd, sysevent_token, paramname, outdata, 0);
        
        //sysevent set snoopereventforcircuitid_queuestart++ circuitid
        
        curInt = strtok_r(NULL, ",", &save);
    }
    
    return queuestart;
    ////get_wifi_param(dm, buf);
    //get local interfaces
    //foreach
        //read bssid
        //read ssid
        //read security type
        //sysevent set circuit id
    //ef
}
static int load_hs_ssid(void)
{
    struct hs_ssid *hsssid;
    char ssid[128];
    snooper_client_list *sncli;
    struct hs_client *cli;
    int i, j;
    char ifs[1024];
    char *tok, *delim, *sp, *from;

    extern ANSC_HANDLE bus_handle;
    char param[128];
    parameterValStruct_t valStru;
    int valSize;

    if (!g_snstat) {
        AnscTraceError(("Snooper shm not ready\n"));
        return -1;
    }
    //dump_snoop_stat(g_snstat);

    g_num_hs_ssid = 0;
    memset(g_hs_ssids, 0, sizeof(g_hs_ssids));
    
    if (hhs_psm_get("dmsb.hotspot.gre.1.LocalInterfaces", ifs, sizeof(ifs)) != 0) {
        AnscTraceError(("fail to get LocalInterfaces in PSM\n"));
        return -1;
    }

    for (from = ifs, delim = ","; 
            (tok = strtok_r(from, delim, &sp)) != NULL; from = NULL) {
        if (g_num_hs_ssid == MAX_HS_SSIDS) {
            AnscTraceError(("max SSID reached\n", ssid));
            break;
        }

        hsssid = &g_hs_ssids[g_num_hs_ssid];

        snprintf(hsssid->path, sizeof(hsssid->path), "%s", tok);

        /* not using CDM API since this change will be merged to R1.5 */
        snprintf(param, sizeof(param), "%sSSID", tok);
        valStru.parameterName = param;
        valStru.parameterValue = hsssid->ssid;
        valSize = sizeof(hsssid->ssid);
        if (COSAGetParamValueByPathName(bus_handle, &valStru, &valSize) != ANSC_STATUS_SUCCESS) {
            AnscTraceError(("Fail to get DM: %s\n", param));
            continue;
        }
        hsssid->ncli = 0;
        g_num_hs_ssid++;

        for (i = 0; i < g_snstat->snooper_num_clients; i++) {
            if (hsssid->ncli == MAX_HS_CLIS) {
                AnscTraceError(("max client reached\n", ssid));
                break;
            }

            sncli = &g_snstat->snooper_clients[i];

            if (circuit_id_get_ssid(sncli->circuit_id, ssid, sizeof(ssid)) != 0) {
                AnscTraceError(("invalid circuit id: %s\n", sncli->circuit_id));
                continue;
            }

            if (strcmp(ssid, hsssid->ssid) == 0) {
                cli = &hsssid->clis[hsssid->ncli++];

                snprintf(cli->mac, sizeof(cli->mac), "%s", sncli->remote_id);
                snprintf(cli->hostname, sizeof(cli->hostname), "%s", sncli->hostname);
                cli->rssi = sncli->rssi;
                snprintf(cli->v4addr, sizeof(cli->v4addr), "%s", sncli->ipv4_addr);
                snprintf(cli->dh4_status, sizeof(cli->dh4_status), "%s", sncli->dhcp_status);
            }
        }
    }

    /*
    AnscTraceDebug((">>>>>> SSID List:\n"));
    for (i = 0; i < g_num_hs_ssid; i++) {
        AnscTraceDebug(("  [%d] SSID %s, Client Num %d\n",
                    i, g_hs_ssids[i].ssid, g_hs_ssids[i].ncli));
        hsssid = &g_hs_ssids[i];

        for (j = 0; j < hsssid->ncli; j++) {
            cli = &hsssid[i].clis[j];
            AnscTraceDebug(("  client[%d].mac %s\n", j, cli->mac));
            AnscTraceDebug(("  client[%d].hostname %s\n", j, cli->hostname));
            AnscTraceDebug(("  client[%d].v4addr %s\n", j, cli->v4addr));
        }
    }
    */

    return 0;
}
/**********************************************************************

    caller:     owner of this object

    prototype:

        BOOL
        NSLookupDiagnostics_Validate
            (
                ANSC_HANDLE                 hInsContext,
                char*                       pReturnParamName,
                ULONG*                      puLength
            );

    description:

        This function is called to finally commit all the update.

    argument:   ANSC_HANDLE                 hInsContext,
                The instance handle;

                char*                       pReturnParamName,
                The buffer (128 bytes) of parameter name if there's a validation.

                ULONG*                      puLength
                The output length of the param name.

    return:     TRUE if there's no validation.

**********************************************************************/
BOOL
NSLookupDiagnostics_Validate
    (
        ANSC_HANDLE                 hInsContext,
        char*                       pReturnParamName,
        ULONG*                      puLength
    )
{
    char*                           p                  = NULL;
    char*                           pDomainName        = NULL;
    ULONG                           ulDNLength         = DSLH_NS_MAX_STRING_LENGTH_Host;
    ULONG                           i                  = 0;
    PCOSA_DATAMODEL_DIAG            pMyObject          = (PCOSA_DATAMODEL_DIAG)g_pCosaBEManager->hDiag;
    PDSLH_NSLOOKUP_INFO             pNSLookupDiagInfo  = pMyObject->hDiagNSLookInfo;
    char*                           pAddrName          = NULL;

    if ( !pNSLookupDiagInfo )
    {
        return FALSE;
    }

    //COSAValidateHierarchyInterface doesn't work now due to incomplete lan device management
    if ( pNSLookupDiagInfo->DiagnosticState == DSLH_DIAG_STATE_TYPE_Requested || 
         /*COSAValidateHierarchyInterface && */ AnscSizeOfString(pNSLookupDiagInfo->Interface) > 0 )
    {
        // COSAValidateHierarchyInterface depends on the specific target
       if(AnscSizeOfString(pNSLookupDiagInfo->Interface) > 0)
            pAddrName = CosaGetInterfaceAddrByName(pNSLookupDiagInfo->Interface);
       else
           pAddrName = CosaGetInterfaceAddrByName("Device.DeviceInfo.X_COMCAST-COM_WAN_IP");

        if(strcmp(pAddrName,"::") && (isValidIPv4Address(pAddrName) || isValidIPv6Address(pAddrName)))
        {
            AnscCopyString(pNSLookupDiagInfo->IfAddr, pAddrName);
            AnscFreeMemory(pAddrName);
        }
        else
        {
            AnscFreeMemory(pAddrName);
            AnscCopyString(pReturnParamName, "Interface");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }
        /*
        if ( !COSAValidateHierarchyInterface
                (
                    pNSLookupDiagInfo->Interface,
                    DSLH_LAN_LAYER3_INTERFACE | DSLH_WAN_LAYER3_CONNECTION_INTERFACE | DSLH_NULL_STRING_INTERFACE
                ))
        {
            AnscCopyString(pReturnParamName, "Interface");
            return FALSE;
        }
        */
    }

    if ( pNSLookupDiagInfo->DiagnosticState == DSLH_DIAG_STATE_TYPE_Requested || AnscSizeOfString(pNSLookupDiagInfo->HostName) > 0 )
    {
        p = pNSLookupDiagInfo->HostName;

        //check if there is any illegal character
        for(i = 0; i < AnscSizeOfString(p); i++)
        {
            if ( (p[i] >= '0' && p[i] <= '9') || (p[i] >= 'a' && p[i] <= 'z') ||
                (p[i] >= 'A' && p[i] <= 'Z') || p[i] == '$' || p[i] == '-' ||
                p[i] == '_' || p[i] == '.' || p[i] == '+' || p[i] == '!' ||
                p[i] == '*' || p[i] == 39 || p[i] == '(' || p[i] == ')' ||
                p[i] == ',' || p[i] == '"' )
            {
                continue;
            }
            else
            {
                AnscCopyString(pReturnParamName, "HostName");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
        }

        if ( pNSLookupDiagInfo->HostName[0] != '.')
        {
            p = _ansc_strstr(pNSLookupDiagInfo->HostName + 1, "..");

            if ( p )
            {
                for(; p < pNSLookupDiagInfo->HostName + AnscSizeOfString(pNSLookupDiagInfo->HostName); p++)
                {
                    if ( *p != '.' )
                    {
                        AnscCopyString(pReturnParamName, "HostName");
                        pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                        return FALSE;
                    }
                }
            }
        }
        else
        {
            AnscCopyString(pReturnParamName, "HostName");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }

        pDomainName = AnscAllocateMemory(DSLH_NS_MAX_STRING_LENGTH_Host);

        if ( !pDomainName )
        {
            AnscCopyString(pReturnParamName, "HostName");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }

        CosaGetParamValueString
            (
#ifndef     DM_IGD
                "Device.DHCPv4.Server.Pool.1.DomainName",
#else
                "InternetGatewayDevice.LANDevice.1.LANHostConfigManagement.DomainName",
#endif
                pDomainName,
                &ulDNLength
            );

        if ( !AnscSizeOfString(pDomainName) )
        {
            if ( pNSLookupDiagInfo->HostName[0] != '.')
            {
                p = _ansc_strchr(pNSLookupDiagInfo->HostName + 1, '.');

                if ( !p )
                {
                    AnscCopyString(pReturnParamName, "HostName");
                    pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                    return FALSE;
                }
                else if ( p[1] == '0' || p[1] == '.' )
                {
                    AnscCopyString(pReturnParamName, "HostName");
                    pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                    return FALSE;
                }
            }
            else
            {
                AnscCopyString(pReturnParamName, "HostName");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
        }
        else
        {
            if ( pNSLookupDiagInfo->HostName[0] == '.')
            {
                AnscCopyString(pReturnParamName, "HostName");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
        }
    }

    if ( pNSLookupDiagInfo->DiagnosticState == DSLH_DIAG_STATE_TYPE_Requested || AnscSizeOfString(pNSLookupDiagInfo->DNSServer) > 0  )
    {
		/*
		  * if DNSServer is empty then we have to take default DNS Server value Device.DNS.Client.Server.1.DNSServer 
		  */
		if ( 0 == AnscSizeOfString(pNSLookupDiagInfo->DNSServer) )
		{
			parameterValStruct_t varStruct 		= { 0 };
			UCHAR	   ucEntryNameValue[128]	= { 0 };
			UCHAR	   ucEntryParamName[128]	= { 0 };
			int 	   			 ulEntryNameLen = 0;

			AnscCopyString( ucEntryParamName, "Device.DNS.Client.Server.1.DNSServer");

			varStruct.parameterName  = ucEntryParamName;
			varStruct.parameterValue = ucEntryNameValue;

			if ( ANSC_STATUS_SUCCESS == COSAGetParamValueByPathName(  g_MessageBusHandle, 
																	   &varStruct,
																	   &ulEntryNameLen ) 
				)
			{
				AnscCopyString( pNSLookupDiagInfo->DNSServer, varStruct.parameterValue );
			}
		}

        //still not clear how to validate dns server
        // we are only validating if the server ip is v4/v6
        if(!isValidIPv4Address(pNSLookupDiagInfo->DNSServer) && !isValidIPv6Address(pNSLookupDiagInfo->DNSServer))
            {
                AnscCopyString(pReturnParamName, "DNSServer");
                pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
                return FALSE;
            }
    }

    if ( TRUE )
    {
        if ( pNSLookupDiagInfo->Timeout < DSLH_NS_MIN_Timeout )
        {
            AnscCopyString(pReturnParamName, "Timeout");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }
    }

    if ( TRUE )
    {
        if ( pNSLookupDiagInfo->NumberOfRepetitions < DSLH_NS_MIN_NumberOfRepetitions )
        {
            AnscCopyString(pReturnParamName, "NumberOfRepetitions");
            pNSLookupDiagInfo->DiagnosticState = DSLH_DIAG_STATE_TYPE_None;
            return FALSE;
        }
    }

    return TRUE;
}