Example #1
0
GSN_STATUS_T Gsn_CloudUpdaterStart( GSN_APP_CLOUD_CONTEXT_T* appContext,BOOL separateThread)
{
	
	GSN_STATUS_T retVal;
    UINT16 stackSize = STACK_5K;
    UINT16 allocatesStackSize;

	continueRunning = TRUE;
	updateInterval = appContext->updateInterval;

    printf("Gsn_CloudUpdaterStart +\n");

    Gsn_CloudApiInit( appContext);
    GsnOsal_SemCreate ( &cloudStopWaitSem, 0 );
    //GsnOsal_SemCreate ( &cloudSuspendSem, 0 );
    if(separateThread == TRUE)
    {
    if ((retVal = Gsn_CloudStackAlloc(&threadStack, STACK_5K,&allocatesStackSize)) == GSN_FAILURE)
    {
        printf("[GsnCloudUpdaterStart] Unable to allocate stack\r\n");
        return GSN_FAILURE;
    }
    else
    {
    	// create a new thread and start posting data in
    	// the new thread context
    	retVal = GsnOsal_ThreadCreate((GSN_OSAL_THREAD_ENTRY_T)Gsn_CloudSend,
    			    (VOID *)&cloudStopWaitSem, /* This is the thread parameter */
                    &httpClientTask,
                    "Gsn_CloudSend",
                    CLOUD_UPDATER_THREAD_PRIORITY,
                    threadStack,
                    stackSize ,
                    GSN_OSAL_THREAD_INITIAL_READY);

    	if(retVal != GSN_SUCCESS)
    	{
        	printf("[Gsn_CloudUpdaterStart] Thread creation Failed\r\n");
        	if (threadStack)
        	{
            	gsn_free(threadStack);
        	}
    	}
    }
    }
    else
    {
    // case : tls low power, post in same thread and return
        if(GSN_BOOT_REASON_GET() == GSN_WIF_SYS_BOOT_FIRST_BOOT)
        {
            AppDbg_Printf("Gsn_CloudUpdaterStart before activate\n");
            retVal = Gsn_CloudActivateDevice();
        }  
        AppDbg_Printf("Gsn_CloudUpdaterStart before post\n");
        Gsn_cloudPostUdpates();
    }
    printf("Gsn_CloudUpdaterStart -\r\n");
    return GSN_SUCCESS;
}
Example #2
0
GSN_STATUS
GsnSp_ProcessGetLoadResponse(INT8* pHttpResponseBuffer,CLOUD_CONTEXT_DATA_T *cloudUpdater)
{
	INT8 *a;
	INT8 len = 1;
	INT8 loadStatus[2];
	INT8 loadState;
        char** responseHeader;
	AppDbg_Printf("Gsn_CloudProcessGetResponse response buf = %s\r\n",pHttpResponseBuffer);
    
    responseHeader= cloudUpdater->httpConfInfo.resHeadersPtr;

	if(NULL != pHttpResponseBuffer)
	   {
		if(!(strncmp((const INT8 *)pHttpResponseBuffer,HTTP_RESPONSE_200,3)))
		{
			AppDbg_Printf("[Gsn_CloudProcessGetResponse] Response Message is 200 OK\r\n");

				a = strstr(pHttpResponseBuffer,"lc_request=");
				a = a + 11;
				if(a != NULL)
				{
					AppDbg_Printf("a = %s\r\n",a);
					AppDbg_Printf("strlen(a) = %d \r\n",strlen(a));
					strncpy(loadStatus,a,len);

					AppDbg_Printf("loadStatus = %s\r\n",loadStatus);
					loadState = atoi(loadStatus);
					cloudUpdater->loadStatus = loadState;
					AppDbg_Printf("loadState = %d\r\n",loadState);
					return GSN_SUCCESS;
				}
         }
		if(!(strncmp((const INT8 *)pHttpResponseBuffer,HTTP_RESPONSE_204,3)))
		{
			AppDbg_Printf("[Gsn_CloudProcessGetResponse] Response Message is 204 NO Content\r\n");
			// check for content-length. if 0 then no data
			if(responseHeader[TM_HTTP_HEADER_CONTENT_LENGTH] != NULL)
			{
				AppDbg_Printf("content length = %s\r\n",responseHeader[TM_HTTP_HEADER_CONTENT_LENGTH]);
				if(!(strcmp(responseHeader[TM_HTTP_HEADER_CONTENT_LENGTH],"0")))
				{
					AppDbg_Printf("setting load to -1\r\n");
					cloudUpdater->loadStatus = -1;
					AppDbg_Printf("cloudUpdater->loadStatus = %d\r\n",cloudUpdater->loadStatus);
					return GSN_SUCCESS;
				}
			}
		}
	   }
	   return GSN_FAILURE;
}
Example #3
0
/*
 * Initialize the MDNS services
 */
void App_MdnsInit(APP_MAIN_CTX_T *pAppCtx)
{
	GSN_MDNS_INIT_PARAM_T initParam;
	//int i;
	GSN_MDNS_T *pMdns = &pAppCtx->if0.mdns;
	UINT32 ipV4Addr = pAppCtx->if0.nwifCtx.ipConfig.ipv4.ipAddr;
	memset((INT8*)&initParam, 0, sizeof(initParam));

	initParam.pNwif = &pAppCtx->if0.nwifCtx;
	initParam.ipV4Addr = ipV4Addr ;
	initParam.msgQueueBuffSize = APP_CFG_MDNS_MSG_HDLR_MAX_MSG_IN_MBOX * sizeof(GSN_MDNS_MSG_T);				  
	initParam.msgQueueBuff = MALLOC(initParam.msgQueueBuffSize);
	if(NULL == initParam.msgQueueBuff)
	{
		while(1);
	}
	initParam.noSeparatetsk = FALSE;
	initParam.blockingOn = FALSE;
	initParam.msgPostCb = App_MdnsMsgPostCb;
	initParam.msgPostCbCtx = NULL;
    if(NULL == pMdns)
    {
        AppDbg_Printf("\nmdns ctxt null....EXIT\n");
    }
	GsnMdns_Init(pMdns, &initParam);
#if 0	
	/* create a mdns task*/
	GsnOsal_ThreadCreate(App_MdnsThreadEntry, &appCtx, &appMdnsThread,
		"App Mdns Ctx", APP_MDNS_THREAD_PRI, (UINT8 *)appMdnsThreadStack,
		sizeof(appMdnsThreadStack), GSN_OSAL_THREAD_INITIAL_READY);
#endif   
    App_MdnsInitValues(pAppCtx);
	App_MdnsHNreg(pMdns, ipV4Addr);
	App_MdnsSrvcReg(pMdns);
}
Example #4
0
PUBLIC VOID AppOtafu_Init(APP_MAIN_CTX_T* pAppCtx)
{
    AppDbg_Printf("[%s] Entered\r\n", __FUNCTION__);
    otafuCtx.cbFn =  AppOtafu_Cb;
    otafuCtx.cbFnCtx = pAppCtx;
    GsnOtafu_Init(&otafuCtx);
}
PUBLIC UINT32 App_NetworkServicesStart(APP_MAIN_CTX_T *pAppCtx)
{
    AppDbg_Printf("[%s] Entered\r\n", __FUNCTION__);
    /* get the ip information by calling geps API */
    GsnNwIf_IpConfigGet(&pAppCtx->if0.nwifCtx, &s_nwParams);

    /* Start HTTP Server */
    App_HttpdStart(pAppCtx);

    /* Start MDNS */
#ifdef APP_MDNS_ENABLE
    App_MdnsInit(pAppCtx);
#endif


    if (pAppCtx->if0.macIfType == GSN_WIF_WLAN_NW_TYPE_STA)
    {
#ifdef ADK_CLOUD_ENABLE
        App_CloudUpdaterInit(pAppCtx);
#endif
#ifdef ADK_IOT_GATEWAY_ENABLE
        App_IotGatewayUpdaterStart(pAppCtx);
#endif
    }

    return GSN_SUCCESS;
}
Example #6
0
/*
 * Callback function for the /gainspan/config handler
 * It is up to the application to deal with the configuration.
 * This function further dispatches GET and POST
 * separately.
 */
VOID App_ConfigCb(GSN_SYS_CONFIG_T *pConfig, UINT8 method)
{
    AppDbg_Printf("[%s] Entered\r\n", __FUNCTION__);

    // TODO - Is this the correct place to do this? Revisit
    f_chdrive(0);

	/*copy the passed structure and store it in the flash memory*/
	if(method == GSN_HTTPD_URI_METHOD_GET)
	{
        AppConfig_Load(pConfig);
        pConfig->networkConfig.ipConfig.ipAddr = htonl(s_nwParams.ipv4.ipAddr);
	}

	if (method == GSN_HTTPD_URI_METHOD_POST)
	{
		AppConfig_Save(pConfig);
        /* Apply System configuration, if necesary */
        App_ApplySysConfig(pConfig);
	}

    // TODO - Is this the correct place to do this? Revisit
    f_chdrive(1);


	return;
}
Example #7
0
VOID App_serviceDiscoveryCallback(void *pData, const GSN_MDNS_SRVC_INFO_T *srvinfo,
                                  UINT32 status)
{
    // call back funtion
    //gets called back with service discovery data and signal the semaphore
    PROXY_UPDATER_DATA *ctx;
    int i;
    APP_RTC_LATCH_MEM_INFO_T *pAppRtcLtchInfo = App_RtcLatchMemInfoPtrGet();
    AppDbg_Printf("App_serviceDiscoveryCallback +\r\n");
    ctx = (PROXY_UPDATER_DATA*)pData;
    if(status !=  GSN_MDNS_SD_NO_SRVC_INFO)
    {
        if(ctx != NULL && srvinfo->txtInfo != NULL)
        {
            if((memcmp(TEXT_RECORD_DATA,srvinfo->txtInfo,tm_strlen(TEXT_RECORD_DATA))) == 0)
            {
                printf("text record matched\r\n");
                printf("AppServiceDiscover_RrRegCb ip address = %d.%d.%d.%d\r\n",srvinfo->ipAddr[0],srvinfo->ipAddr[1],srvinfo->ipAddr[2],srvinfo->ipAddr[3]);

                printf("srvinfo->textRecord = %s\r\n",srvinfo->textRecord);

                // copy the IP address and port
                for(i = 0; i < 4; i++)
                {
                    ctx->IPAddress[i] = ( srvinfo->ipAddr >> (i*8) ) & 0xFF;
                    pAppRtcLtchInfo->IotGatewayIpAddress[i] = ctx->IPAddress[i];
                }
                ctx->portNo = srvinfo->port;
                AppDbg_Printf("srvinfo->port = %d\r\n",srvinfo->port);

                (pAppRtcLtchInfo->IotGatewayPort) = srvinfo->port;
                AppDbg_Printf("pAppRtcLtchInfo->IotGatewayPort = %d\r\n",pAppRtcLtchInfo->IotGatewayPort);
                AppDbg_Printf("sizeof(APP_RTC_LATCH_MEM_INFO_T) = %d\r\n",sizeof(APP_RTC_LATCH_MEM_INFO_T));
                serviceDiscovered = TRUE;

            }
        }
    }
Example #8
0
PUBLIC VOID
GsnRtsp_ClientSessionInit(INT32 clientSocket, struct sockaddr_in clientAddr)
{
    rtspServerCtx.RTSPClientSession.RtspSessionId = 1;                       

    rtspServerCtx.RTSPClientSession.RtspDataSocketId = clientSocket;
    AppDbg_Printf("\r\nGsnRtsp_ClientSessionInit:clientSocket:%d\r\n",clientSocket);
    rtspServerCtx.RTSPClientSession.RtspClientAddress = clientAddr;          

    rtspServerCtx.RTSPClientSession.RtspSessionActive  = FALSE;
       
    GsnRtsp_RstReqBuffer();
  
}
Example #9
0
void Gsn_SpFormatData(CLOUD_CONTEXT_DATA_T* cloudUpdater)
{
    INT8* reqBuf;
    UINT8 rssi;
    int rssiInt;
    GSN_SP_ADK_DATA_T *data;

    printf("Gsn_SpFormatData +\r\n");
    if (cloudUpdater->cbFn)
	(*cloudUpdater->cbFn)(GET_DATA, &cloudUpdater->cloudCallbackData);

    data = (GSN_SP_ADK_DATA_T*)cloudUpdater->cloudCallbackData.adkData;
    rssi = ~data->signalstrength +1;
    rssiInt = -rssi;
    AppDbg_Printf(" current = %s,freq = %s, power = %s,powerfactor = %s,volts = %s,rssiInt = %d load = %s\r\n",data->currentStr,data->freqStr,data->powerStr,data->powerFactorStr,data->voltsStr,rssiInt,data->loadStateStr);
    reqBuf = cloudUpdater->httpRequestBuf;
    cloudUpdater->requestBufLen = sprintf(reqBuf,"freq=%s&power=%s&voltage=%s&current=%s&energy=%s&powerfactor=%s&sig=%d&load_control=%s",data->freqStr,data->powerStr,data->voltsStr,data->currentStr,data->eUnitStr,data->powerFactorStr,rssiInt, data->loadStateStr);

    printf("Gsn_SpFormatData -\r\n");
}
Example #10
0
PRIVATE INT32
AppTls_CreateXmlResp(APP_MAIN_CTX_T *pAppCtx, INT8* buffer, ttHttpdUserConHandle conHandle)
{
    int errorCode;
    UINT32 battery = 0, TLSdata[2] = {0,0};
    GSN_WIF_WLAN_RSSI_T    wRssi;

	UINT8 LEDStatus;
    INT8 *LEDstsPtr;

    AppTls_TempOrLightGet( TLSdata );
    GsnWdd_RSSIGet(&pAppCtx->if0.wddCtx, (INT8*) &wRssi, sizeof(wRssi));
    AppDbg_Printf("### Get ## adc data temp : %d , lux : %d RSSI %d \r\n", TLSdata[0], TLSdata[1], (signed char)wRssi.rssi);
#if 0
    AppTls_TempSensorDataGet(pAppCtx, &temp);
    AppTls_LightSensorDataGet(pAppCtx, &light);
    AppTls_BatteryValueGet(pAppCtx, &battery);
	
    rssi1 = AppNcm_RSSIValueGet(&pTlsAppSmCtx->ncm);
    rssi2 = ~rssi1 + 1;
    rssiInt = -rssi2;
    battery = battery;
#endif
#ifdef APP_API_JSON
    sprintf(buffer, "{\"version\":\"%s\",\"lux\":%d,\"temp\":%d,"
            "\"battery\":%d,\"rssi\":%d}",
            TLS_HTTP_API_VERSION, light, temp, battery, rssiInt);
#else
	LEDStatus = App_GetLedStatus();
	LEDstsPtr = LEDStatus==1?"on":"off";
	
sprintf(buffer, "<tls><version>%s</version><lux>%d</lux><temp>%d</temp>"
            "<battery>%d</battery><rssi>%d</rssi><leds>%s</leds></tls>",
            TLS_HTTP_API_VERSION, TLSdata[1], TLSdata[0], battery, (signed char)wRssi.rssi, LEDstsPtr );
#endif
    GsnHttpd_SendBufferAndLastChunk(conHandle, buffer, strlen(buffer), TM_BLOCKING_ON, &errorCode);
    return 0;
}
Example #11
0
/*
 * This is the entry point for the HTTP Server
 */
PUBLIC GSN_STATUS 
App_HttpdStart(APP_MAIN_CTX_T *pAppCtx)
{
    UINT32 wlanVer = 0;
    GSN_HTTPD_CONFIG_T config;	
	GSN_NWIF_IP_CONFIG_T ipConfig;

#ifdef ADK_PROV_ENABLE	
    GSN_HTTPD_PROV_CONFIG_T provConfig;	
	GSN_WLAN_REG_DOMAIN_T appWlanRegDomain = GSN_WLAN_REG_DOMAIN_UNKNOWN;
#endif

    AppDbg_Printf("[%s] Entered\r\n", __FUNCTION__);

    /* get the ip information by calling geps API */
    GsnNwIf_IpConfigGet(&pAppCtx->if0.nwifCtx, &ipConfig);

	/* Initialize web parameters */
    memset(&config, 0, sizeof(GSN_HTTPD_CONFIG_T));

    /* store user mane and passwd*/
    strcpy(config.username, (const INT8 *)pAppCtx->config.httpdConfig.username);
    strcpy(config.password, (const INT8 *)pAppCtx->config.httpdConfig.password);
    config.port = APP_HTTPD_PORT;
    config.maxConnPerIp = APP_HTTPD_MAX_PER_IP_CONN;
    config.maxConnTotal = APP_HTTPD_MAX_TOTAL_CONN;
    config.blockingState = APP_HTTPD_BLOCKING_STATE;
    config.threadPriority = APP_CFG_WEB_SRVR_THREAD_PRIORITY;
    config.idleTimeout = APP_HTTPD_IDLE_TIMEOUT;
	
    config.ip_flag = GSN_USE_IPV4;
    config.ipAddr = ipConfig.ipv4.ipAddr;

    config.rootCgiDir = NULL;
    config.rootDir = "/";
    config.defaultFileName = "index.html";
	config.mallocTimeout = 2 *1000; /* 2 Sec. */

    config.stack = (UINT8 *)MALLOC(APP_CFG_WEB_SRVR_STACK_SIZE);	 
	if(NULL == config.stack)
	{
		return GSN_FAILURE;
	}
    config.stackSize  = APP_CFG_WEB_SRVR_STACK_SIZE;
    config.pool_hdl = GsnNw_PktPoolHndlGet(&pAppCtx->nwCtx, GSN_NW_LBUF_PKT_POOL);
	config.sysQualTskID = APP_CFG_SQ_HTTPD_TASK_ID;
	config.sysQualTicks = APP_CFG_SQ_TICKS_FOR_HTTPD_TASK;
    /* Start httpd */
    GsnHttpd_Start(config, NULL);
	
#ifdef ADK_PROV_ENABLE
    /* System Configuration URI Handler  */
    GsnHttpdApi_ConfigInit(App_ConfigCb);

	/* Scan Configuration URI Handler */
    memset(&provConfig, 0x0, sizeof(provConfig));
    provConfig.pWdd = &pAppCtx->if0.wddCtx;
    provConfig.domain = appWlanRegDomain;

#ifdef ADK_PROV_WPS_ENABLE
    provConfig.pWpsCbFn = (GSN_HTTPD_PROV_WPS_CB_FN_T) AppWps_CbFn;
#endif /* ADK_PROV_WPS_ENABLE */
    GsnHttpdApi_ProvInit(&provConfig);
#endif /* ADK_PROV_ENABLE */

    /* API Configuration URI Handler */
    GsnHttpdApi_ApiInit();

#ifdef ADK_API_SYS_DEBUG_ENABLE
    GsnHttpdApi_SysDebugInit();
#endif /*ADK_API_SYS_DEBUG_ENABLE */

    /*Get Wlan Version*/
    GsnSysCtl_WlanFwVerGet(&pAppCtx->sysCtlCtx,&wlanVer);
    GsnHttpdApi_FwInit(wlanVer, (UINT8*)AppConfig_GetAppNameAndVersion());

    /* Application's URI Handler*/
    AppHttp_ApiInit();

	/* File Upload App Configuration Handler */
#ifdef ADK_FILE_UPLOAD_API
	GsnHttpd_FileApiInit();
#ifdef ADK_FILE_UPLOAD_APP_CONTENT_DISPLAY
	GsnHttpd_FileApiConfig("/gainspan/system/fileupload", AppFileUpload_FilesPrintCb, GSN_HTTPD_URI_METHOD_POST);
#endif

#ifdef ADK_OTAFU_ENABLE
	AppOtafu_Init(pAppCtx);
#endif
#endif /*ADK_FILE_UPLOAD_API*/

    return GSN_SUCCESS;
}
Example #12
0
BOOL
AppCertUpload_SslCertUploadCb(GSN_HTTPD_ELEMENT_INFO_T fileInfo, INT8 *buffer, 
	UINT32 bufferLen, GSN_HTTPD_ELEMENT_EVENTS_T event, 
	GSN_HTTPD_STATUS_INFO_T *statusInfo)
{
	UINT8 len;
	INT8 tagName[APP_CERT_MAX_NAME_LENGTH+8];
	INT32 status;
	AppDbg_Printf("\n\rIn file upload CB: %x\n\r", event);
	switch(event)
	{
		case START_UPLOAD:
			AppFileUploadStatus=0;
			AppFileuploadCnt=0;
			break;
		case START_FILE:
			AppDbg_Printf("TagNameLen: %d", fileInfo.nameLen);
			if(fileInfo.nameLen)
			{
				f_chdrive(0);	
				status = f_mkdir("certs");
				memset(tagName, 0, APP_CERT_MAX_NAME_LENGTH+8);
				if(status != F_NO_ERROR || status != F_ERR_DUPLICATED )
				{
					if(strncmp(fileInfo.name,TAG_SSLCERT,fileInfo.nameLen) == 0)
					{
						if(fileInfo.filenameLen > APP_CERT_MAX_NAME_LENGTH)
							fileInfo.filenameLen = APP_CERT_MAX_NAME_LENGTH-1;
												
						len= sprintf(tagName,"certs/");
						memcpy(tagName + len, fileInfo.filename, fileInfo.filenameLen);
						certFd= f_open((const char *)tagName, "w");
					}
					else /*EAP Certificates*/
					{
						len= sprintf(tagName,"certs/");
						memcpy(tagName + len, fileInfo.filename, fileInfo.filenameLen);
						certFd= f_open((const char *)tagName, "w");
					}
					if(certFd == NULL)
					{				
						f_chdrive(1);	
						AppFileUploadStatus = 1;
						return 0;
					}
					AppFileuploadCnt++;
				}
				else
					AppFileUploadStatus = 1;
				
				f_chdrive(1);	
				AppDbg_Printf("\r\nFile Name is = %s:%d \r\n", tagName,fileInfo.filenameLen);
			}
			break;
		case CONTINUE_FILE:
			AppDbg_Printf("\r\nBufferLength=%d\r\n",bufferLen);
			f_chdrive(0);	
			if(certFd != NULL)
			{
				len = f_write(buffer, 1, bufferLen , certFd);
				if(len != bufferLen)
					AppFileUploadStatus = 1;	
			}
			f_chdrive(1);	
			break;
		case END_FILE:
			f_chdrive(0);
			if(certFd != NULL)
			{
				f_close(certFd);
			}
			f_chdrive(1);	
			break;
		case END_UPLOAD:
			AppDbg_Printf("END UPLOAD:%d\n\r",AppFileUploadStatus);
			if(AppFileUploadStatus != 0)
			{
				sprintf(statusInfo->pMsg,"<Response><status>SUCCESS</status><msg>");
				statusInfo->msgLength =	sprintf(statusInfo->pMsg, "%s %d files Uploaded</msg></Response>", \
										statusInfo->pMsg, AppFileuploadCnt);
			}
			else
			{
				sprintf(statusInfo->pMsg,"<Response><status>FAILED</status><msg>");
				statusInfo->msgLength =	sprintf(statusInfo->pMsg, "%s %d file Uploaded</msg></Response>",\
										statusInfo->pMsg, AppFileuploadCnt);
			}
			AppFileuploadCnt=0;
			break;
		case CONNEC_LOST:
			AppDbg_Printf("END CONNEC_LOST\n\r");
			break;
	}
	
	return 0;
}
Example #13
0
PUBLIC GSN_STATUS
App_NcmStart(APP_MAIN_CTX_T *pAppCtx, APP_IF_INFO_T * pIfInfo)
{
	GSN_NCM_CONFIG_T* pNcmCfg = &pIfInfo->ncmCtx.config;
	UINT8 *pAddr;
	APP_CONFIG_T *pAppCfg = &pAppCtx->config;
	APP_RTC_SECNDRY_MEM_INFO_T *pAppRtcSecMemInfo = App_RtcSecMemInfoPtrGet();

	memset(pNcmCfg, 0, sizeof(GSN_NCM_CONFIG_T));
	if(GSN_WIF_WLAN_NW_TYPE_STA == pIfInfo->macIfType)
	{
		APP_CLIENT_CONFIG_T *pCliCfg = &pAppCfg->networkConfig.clientConfig;
		/* NCM WLAN config set*/
		GSN_WDD_SSID_CPY(&pNcmCfg->wlanCfg.ssid,&pCliCfg->ssid);

		pNcmCfg->wlanCfg.channel[0]	= pCliCfg->channel;
		pNcmCfg->wlanCfg.channel[1] = 0;

		if (pCliCfg->securityType == GSN_WLAN_WPA_PERSONAL)
		{
            pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_ANY;
		    if (pCliCfg->passphrase.Len)
		    {
                pNcmCfg->wlanCfg.securityCfg.pskConfig.passPhrase.Len =
                            pCliCfg->passphrase.Len;
                memcpy(pNcmCfg->wlanCfg.securityCfg.pskConfig.passPhrase.Passphrase,
                        pCliCfg->passphrase.Passphrase,
                        pCliCfg->passphrase.Len);
		    }
		    // TODO - compute PSK so that next time we can use it directly
            pNcmCfg->wlanCfg.securityCfg.pskConfig.pskValid = 0;
            pNcmCfg->wlanCfg.securityCfg.pskConfig.wpaAlgo =
                    GSN_WDD_WPA_ALGO_MIXED;
		}
		else if (pCliCfg->securityType == GSN_WLAN_WEP)
		{
            pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_WEP;
		    if (pCliCfg->wepKeyConfig.KeyLen)
		    {
                pNcmCfg->wlanCfg.securityCfg.wepConfig.KeyLen =
                        pCliCfg->wepKeyConfig.KeyLen;
                pNcmCfg->wlanCfg.securityCfg.wepConfig.KeyId =
                        pCliCfg->wepKeyConfig.KeyId - 1;
                memcpy(pNcmCfg->wlanCfg.securityCfg.wepConfig.Key,
                        pCliCfg->wepKeyConfig.Key, pCliCfg->wepKeyConfig.KeyLen);
                if (pCliCfg->wepAuthType == GSN_MAC_AUTH_SHARED)
                        pNcmCfg->wlanCfg.securityCfg.wepConfig.authType = GSN_WDD_SEC_WEP_SHARED;
                else
                        pNcmCfg->wlanCfg.securityCfg.wepConfig.authType = GSN_WDD_SEC_WEP_OPEN;
		    }
		}
		else if (pCliCfg->securityType == GSN_WLAN_WPA_ENTERPRISE)
		{
		    // NOTE: This is NOT supported. So setting to "No Security"
            pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_DISABLE;
		}
		else
		{
            pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_DISABLE;
		}
		pNcmCfg->regDomain = GSN_NCM_REG_DOMAIN_FCC;

		/*NCM IP config*/
		pNcmCfg->ipConfig.flag = GSN_NWIF_IPCONFIG_FLAG_IPV4_INIT;
		pNcmCfg->ipConfig.ipv4.staticIp = !pCliCfg->dhcpFlag;
		if(pNcmCfg->ipConfig.ipv4.staticIp == 1)
		{
			pNcmCfg->ipConfig.ipv4.ipAddr = ntohl(pCliCfg->ipAddress);
			pNcmCfg->ipConfig.ipv4.subnetMask = ntohl(pCliCfg->subnetmask);
			pNcmCfg->ipConfig.ipv4.gatewayIpAddr = ntohl(pCliCfg->gateway);
			pNcmCfg->ipConfig.ipv4.dnsPriSrvrIp = ntohl(pCliCfg->dnsServer);
			pNcmCfg->ipConfig.ipv4.dnsSecSrvrIp = ntohl(pCliCfg->dnsServer);
		}
		AppDbg_Printf("APP NCM ipaddr = %x\r\n", pNcmCfg->ipConfig.ipv4.ipAddr);
		pNcmCfg->dhcpV4Cfg.dhcpMaxRetryCnt = DEFAULT_CLI_DHCP_MAX_RETRYCNT;
		pNcmCfg->dhcpV4Cfg.sysQualTskID = APP_CFG_SQ_DHCPV4_TASK_ID;
		pNcmCfg->dhcpV4Cfg.sysQualTicks = APP_CFG_SQ_TICKS_FOR_DHCPV4_TASK;
		pNcmCfg->dhcpV4Cfg.pDhcpCliRecord = &pAppRtcSecMemInfo->dhcpClientRecord;
		pNcmCfg->dhcpV4Cfg.timeElapsed = pAppRtcSecMemInfo->sleepTime/10;
		pAppRtcSecMemInfo->sleepTime = 0;
		/*NCM retry config*/	
		pNcmCfg->retryPeriodConfig.scanKnownChRetryIntrvl = 0;
		pNcmCfg->retryPeriodConfig.scanSpecChRetryIntrvl = 0;
		pNcmCfg->retryPeriodConfig.scanAllChRetryIntrvl = 0;
		pNcmCfg->retryPeriodConfig.cpuWaitPeriod = CPU_WAIT_PERIOD;
		
		pNcmCfg->retryCountsConfig.maxScanKnownChCnt = 0;
		pNcmCfg->retryCountsConfig.maxScanSpecChCnt = 0;
		pNcmCfg->retryCountsConfig.maxScanAllChCnt = MAX_SCAN_CH_COUNT;
		pNcmCfg->retryCountsConfig.maxL3ConnectCnt = MAX_L3_CONNECT_COUNT;
		
		/*Set Sync Loss threshold*/
		
		GsnWdd_BeaconMissThresholdSet(&pAppCtx->if0.wddCtx, 0,100);
	}	
	else if(GSN_WIF_WLAN_NW_TYPE_AP == pIfInfo->macIfType)
	{
		APP_AP_CONFIG_T *pApCfg = &pAppCfg->networkConfig.apConfig;

		/* NCM WLAN config set*/
		GSN_WDD_SSID_CPY(&pNcmCfg->wlanCfg.ssid,&pApCfg->ssid);

		pNcmCfg->wlanCfg.channel[0]	= pApCfg->channel;
		pNcmCfg->wlanCfg.channel[1] = 0;
		pNcmCfg->regDomain = GSN_NCM_REG_DOMAIN_FCC;

		if (pApCfg->securityType == GSN_WLAN_WPA_PERSONAL)
		{
            pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_WPA2_PERSONAL;
		}
		else if (pApCfg->securityType == GSN_WLAN_WEP)
		{
		    // TODO - WEP support needs to be added. As of now fallback to no security
            pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_DISABLE;
            //pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_WEP;
		}
		else
		{
            pNcmCfg->wlanCfg.securityCfg.mode = GSN_WDD_SEC_MODE_DISABLE;
		}

		pNcmCfg->wlanCfg.securityCfg.pskConfig.wpaAlgo = GSN_WDD_WPA_ALGO_AES;
		pNcmCfg->wlanCfg.securityCfg.pskConfig.pskValid = 0;
		pNcmCfg->wlanCfg.securityCfg.pskConfig.passPhrase.Len = strlen(DEFAULT_AP_PASSPHRASE);
		memcpy( pNcmCfg->wlanCfg.securityCfg.pskConfig.passPhrase.Passphrase, DEFAULT_AP_PASSPHRASE,
		pNcmCfg->wlanCfg.securityCfg.pskConfig.passPhrase.Len );

		pNcmCfg->ipConfig.flag = GSN_NWIF_IPCONFIG_FLAG_IPV4_INIT;
		pNcmCfg->ipConfig.ipv4.staticIp = TRUE;
		pNcmCfg->ipConfig.ipv4.ipAddr = ntohl(pApCfg->ipAddress);
		pNcmCfg->ipConfig.ipv4.subnetMask = ntohl(pApCfg->subnetmask);
		pNcmCfg->ipConfig.ipv4.gatewayIpAddr = ntohl(pApCfg->gateway);

		/*AP mode connect needs BSSID*/
		memcpy((INT8 *)pNcmCfg->wlanCfg.bssid.array, pAppCfg->networkConfig.macAddr, 6);
	}
	/* start NCM*/
	return GsnNcm_Start(&pAppCtx->if0.ncmCtx, AppNcm_NcmNotifCb, pAppCtx);
}
Example #14
0
VOID
App_NcmStop(APP_MAIN_CTX_T *pAppCtx)
{
	AppDbg_Printf("Stop Ncm\r\n");
	GsnNcm_Stop(&pAppCtx->if0.ncmCtx, 0);
}
Example #15
0
PRIVATE VOID
AppNcm_NcmNotifCb(VOID *cbCtx, VOID* pNcm, GSN_NCM_NOTIF_ID_T notifId)
{
	APP_MAIN_CTX_T *pAppCtx = cbCtx;
	INT32 msgId;	
	APP_RTC_LATCH_MEM_INFO_T *pAppRtcLtchInfo = App_RtcLatchMemInfoPtrGet();
	APP_CLIENT_CONFIG_T *pCliCfg;
	pCliCfg = &pAppCtx->config.networkConfig.clientConfig;
	
	switch(notifId)
	{
		case GSN_NCM_NOTIF_ID_L2_CONNECTED:{msgId = APP_EVENT_INVALID ;break;}
		case GSN_NCM_NOTIF_ID_L2_DISCONNECTED:
		{
			msgId = APP_EVENT_INVALID ;
			{
				if(pAppCtx->nwConnected )
				{
					pAppCtx->nwConnected  = FALSE;
					msgId = APP_EVENT_NW_DISCONNECT_DONE ;
				}
			}
			break;
		}
		case GSN_NCM_NOTIF_ID_L3_CONNECTED:
		{
			pAppCtx->nwConnected = TRUE;
			msgId = APP_EVENT_NW_CONNECT_DONE ;			
		}
		break;
		case GSN_NCM_NOTIF_ID_L3_DISCONNECTED:
		{
			msgId = APP_EVENT_INVALID ;
			if(pAppCtx->nwConnected )
			{
				pAppCtx->nwConnected  = FALSE;
				msgId = APP_EVENT_NW_DISCONNECT_DONE ;
			}
			break;
		}
		case GSN_NCM_NOTIF_ID_L2_CONNECT_FAIL:
		{
			msgId = APP_EVENT_INVALID ;
			break;
		}
		case GSN_NCM_NOTIF_ID_STOP:
		{
			AppDbg_Printf("NCM Stopped!!!!!\r\n");
			pAppCtx->nwConnected = FALSE;
			/* Reset stored information*/
			pCliCfg->dhcpFlag = TRUE;
			pCliCfg->ipAddress = 0;
			msgId = APP_EVENT_NW_START_NCM ;			
		}
	}
	if(APP_EVENT_INVALID != msgId)
	{
		//AppDbg_Printf("*****[APP] NcmNotifCb: mainTaskNotify event = %d\r\n", msgId);
		AppMainCtx_TaskNotify(msgId, 0);
	}
}