Commit 1fea5e15 authored by Jay Sharma's avatar Jay Sharma Committed by Madan Lanka

[Easy-Setup] Changed the enrollee's cpp files to c files

	- Updated the enrollee SDK.
	- Updated the Linux Application

Change-Id: Ia7a42011f609870fb2654f2a324213c1fdee5720
Signed-off-by: default avatarJay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/6133Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent d73ee3ad
......@@ -59,7 +59,8 @@ enrollee_env.PrependUnique(CPPPATH = [
enrollee_env.get('SRC_DIR') + '/service/easy-setup/inc',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/inc',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src'])
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino'])
if enrollee_env.get('SECURED') == '1':
enrollee_env.AppendUnique(CPPPATH = [
......@@ -112,12 +113,12 @@ if target_os == 'arduino':
es_enrollee_src = None
if target_os == 'linux':
es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/softapnative.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/networkhandler.cpp']
es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/softapnative.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/networkhandler.c']
enrollee_env.AppendUnique(es_enrollee_src = es_enrollee_common_src)
......@@ -126,21 +127,21 @@ if target_os == 'linux':
if target_os == 'tizen':
enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', [
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/networkhandler.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/softapnative.cpp'])
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/networkhandler.c',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/softapnative.c'])
enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrolleeSDK')
enrollee_env.UserInstallTargetLib(enrollee_sdk_shared, 'libESEnrolleeSDK')
if target_os == 'arduino':
es_sdk_static = enrollee_env.StaticLibrary('ESEnrolleeSDK', [
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/easysetup.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/onboarding.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/softap.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/resourcehandler.cpp',
enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp'])
enrollee_env.InstallTarget(es_sdk_static, 'libESEnrolleeSDK')
......
......@@ -26,7 +26,7 @@
#include "easysetup.h"
#include "oic_string.h"
#define LOG_TAG "TIZEN ES"
#define LOG_TAG "LINUX ES"
const char *gSsid = "DLNA_LISMORE1";
const char *gPass = "dlna@010203";
......
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* @file
*
* This file contains the implementation for EasySetup Enrollee device
*/
#include "easysetup.h"
#include "softap.h"
#include "onboarding.h"
#include "logger.h"
#include "resourcehandler.h"
#include "easysetupcallbacks.h"
/**
* @var ES_ENROLLEE_TAG
* @brief Logging tag for module name.
*/
#define ES_ENROLLEE_TAG "ES"
//-----------------------------------------------------------------------------
// Private variables
//-----------------------------------------------------------------------------
/**
* @var gTargetSsid
* @brief Target SSID of the Soft Access point to which the device has to connect
*/
static char gTargetSsid[MAXSSIDLEN];
/**
* @var gTargetPass
* @brief Password of the target access point to which the device has to connect
*/
static char gTargetPass[MAXNETCREDLEN];
/**
* @var gEnrolleeStatusCb
* @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback
*/
static EventCallback gEnrolleeStatusCb = NULL;
/**
* @var gIsSecured
* @brief Variable to check if secure mode is enabled or not.
*/
static bool gIsSecured = false;
void OnboardingCallback(ESResult esResult)
{
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "OnboardingCallback with result = %d", esResult);
if(esResult == ES_OK)
{
gEnrolleeStatusCb(esResult, ES_ON_BOARDED_STATE);
}
else
{
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
"Onboarding is failed callback result is = %d", esResult);
gEnrolleeStatusCb(esResult, ES_INIT_STATE);
}
}
void ProvisioningCallback(ESResult esResult)
{
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ProvisioningCallback with result = %d", esResult);
if (esResult == ES_RECVTRIGGEROFPROVRES)
{
GetTargetNetworkInfoFromProvResource(gTargetSsid, gTargetPass);
gEnrolleeStatusCb(ES_OK, ES_PROVISIONED_STATE);
OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting with target network");
// Connecting/onboarding to target network
ConnectToWiFiNetwork(gTargetSsid, gTargetPass, OnboardingCallbackTargetNet);
}
else
{
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Provisioning is failed callback result is = %d", esResult);
// Resetting Enrollee to ONBOARDED_STATE as Enrollee is alreday onboarded in previous step
gEnrolleeStatusCb(ES_OK, ES_ON_BOARDED_STATE);
}
}
void OnboardingCallbackTargetNet(ESResult esResult)
{
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "OnboardingCallback on target network with result = %d",
esResult);
if(esResult == ES_OK)
{
gEnrolleeStatusCb(esResult, ES_ON_BOARDED_TARGET_NETWORK_STATE);
}
else
{
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
"Onboarding is failed on target network and callback result is = %d", esResult);
// Resetting Enrollee state to the ES_PROVISIONED_STATE
// as device is already being provisioned with target network creds.
gEnrolleeStatusCb(esResult, ES_PROVISIONED_STATE);
}
}
ESResult InitEasySetup(OCConnectivityType networkType, const char *ssid, const char *passwd,
bool isSecured,
EventCallback cb)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "InitEasySetup IN");
if(!ValidateParam(networkType,ssid,passwd,cb))
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG,
"InitEasySetup::Stopping Easy setup due to invalid parameters");
return ES_ERROR;
}
//Init callback
gEnrolleeStatusCb = cb;
gIsSecured = isSecured;
// TODO : This onboarding state has to be set by lower layer, as they better
// knows when actually on-boarding started.
cb(ES_ERROR,ES_ON_BOARDING_STATE);
OIC_LOG(INFO, ES_ENROLLEE_TAG, "received callback");
OIC_LOG(INFO, ES_ENROLLEE_TAG, "onboarding now..");
if(!ESOnboard(ssid, passwd, OnboardingCallback))
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "InitEasySetup::On-boarding failed");
cb(ES_ERROR, ES_INIT_STATE);
return ES_ERROR;
}
OIC_LOG(INFO, ES_ENROLLEE_TAG, "InitEasySetup OUT");
return ES_OK;
}
ESResult TerminateEasySetup()
{
UnRegisterResourceEventCallBack();
//Delete Prov resource
if (DeleteProvisioningResource() != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "Deleting prov resource error!!");
return ES_ERROR;
}
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "TerminateEasySetup success");
return ES_OK;
}
ESResult InitProvisioning()
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "InitProvisioning <<IN>>");
if (CreateProvisioningResource(gIsSecured) != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CreateProvisioningResource error");
return ES_ERROR;
}
RegisterResourceEventCallBack(ProvisioningCallback);
OIC_LOG(INFO, ES_ENROLLEE_TAG, "InitProvisioning OUT");
return ES_RESOURCECREATED;
}
static bool ValidateParam(OCConnectivityType networkType, const char *ssid, const char *passwd,
EventCallback cb)
{
if (!ssid || !passwd || !cb)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ValidateParam - Invalid parameters");
return false;
}
return true;
}
//******************************************************************
//
// Copyright 2016 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* @file
*
* This file contains private internal callback function
* prototypes for Easy setup [Enrollee]
*/
#ifndef EASYSETUP_ENROLLEE_CALLBACKS_H__
#define EASYSETUP_ENROLLEE_CALLBACKS_H__
#include "escommon.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
//-----------------------------------------------------------------------------
// Private internal callback function prototypes for Easy setup [Enrollee]
//-----------------------------------------------------------------------------
/*
* Callback for on boarding
*/
void OnboardingCallback(ESResult esResult);
/*
* Callback for provisioning
*/
void ProvisioningCallback(ESResult SSSS);
/*
* Callback for on boarding target Network
*/
void OnboardingCallbackTargetNet(ESResult esResult);
/*
* Function for validating the parameter for InitEasySetup API
*/
static bool ValidateParam(OCConnectivityType networkType, const char *ssid, const char *passwd,
EventCallback cb);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* EASYSETUP_ENROLLEE_CALLBACKS_H__ */
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* @file
*
* This file has methods for on-boarding the Enrollee device.
* This will contain template methods that will have core business logic & negotiation algorithm
* on various on-boarding methods.
*/
#include "easysetup.h"
#include "softap.h"
#include "onboarding.h"
#include "logger.h"
#include "resourcehandler.h"
/**
* @var ES_ENROLLEE_TAG
* @brief Logging tag for module name.
*/
#define ES_ENROLLEE_TAG "ES_SOFTAP"
/**
* It will return true on-boarding type is soft AP
*/
bool ESSoftapOnboarding()
{
// TODO: To be changed based on user config. Current version, hardcoded to SoftAp onboarding
return true;
}
/**
* It will return true on-boarding type is BLE
*/
bool ESBleOnboarding()
{
//BLE onboarding is not supported with current version.
return false;
}
/**
* It will do onboarding based on the user's configuration.
*/
bool ESOnboard(const char * ssid, const char* passwd, NetworkEventCallback cb)
{
OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "ESOnboard IN");
if (ESSoftapOnboarding())
{
if (ESSoftapAtEnrollee())
{
OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Create SoftAp at enrollee");
ESCreateSoftap(ssid, passwd, cb);
}
else
{
OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting to Mediator SoftAp");
ConnectToWiFiNetwork(ssid, passwd, cb);
}
return true;
}
else if (ESBleOnboarding())
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Ble onboarding is not supported");
// TODO:
return false;
}
else
{
// TODO:
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Invalid onboarding option");
return false;
}
}
......@@ -18,6 +18,7 @@
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef EASYSETUP_ENROLLEE_ONBOARDING_H__
#define EASYSETUP_ENROLLEE_ONBOARDING_H__
......@@ -28,18 +29,33 @@ extern "C" {
#include "networkhandler.h"
/**
* It will on-board the Enrollee device. This is a template method that has
* core business logic & negotiation algorithm on various on-boarding methods.
* @file
*
* This file contains APIs to on-board ( connect ) Enrollee device into Ad-hoc network
* @Note : Some of the APIs of this file need to be modified by the OEM according to the device configuration
*/
/**
* This function on-board Enrollee device onto ad-hoc network.
* @param ssid SSID of the target SoftAP network to which the Enrollee is connecting.
* @param passwd Password of the target SoftAP network to which the Enrollee is connecting.
* @param NetworkEventCallback Callback function for result update
* @return ::True, if on-boarding is successful.
*/
bool ESOnboard(const char * ssid, const char* passwd, NetworkEventCallback cb);
/**
* It will return true on-boarding type is soft AP.
* This function verify if the on-boarding is through SoftAP.
* @return ::True, if Soft AP on-boarding enabled.
* @Note : This API to be modified by the OEM according to the device configuration
*/
bool ESSoftapOnboarding();
/**
* It will return true on-boarding type is BLE.
* This function verify if the on-boarding is through Ble beacons.
* @return ::True, if Ble beacons enabled.
* @Note : This API to be modified by the OEM according to the device configuration
*/
bool ESBleOnboarding();
......
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "resourcehandler.h"
#include <stdio.h>
#include "ocpayload.h"
#include "oic_string.h"
/**
* @var ES_RH_TAG
* @brief Logging tag for module name.
*/
#define ES_RH_TAG "ES_RH"
//-----------------------------------------------------------------------------
// Private variables
//-----------------------------------------------------------------------------
/**
* @var gProvResource
* @brief Structure for holding the Provisioning status and target information required to
* connect to the target network
*/
static ProvResource gProvResource;
/**
* @var gNetResource
* @brief Structure forr holding the Provisioning status of network information
*/
static NetResource gNetResource;
//-----------------------------------------------------------------------------
// Private internal function prototypes
//-----------------------------------------------------------------------------
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
void *callback);
const char *getResult(OCStackResult result);
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest);
ResourceEventCallback gNetworkInfoProvEventCb = NULL;
void RegisterResourceEventCallBack(ResourceEventCallback cb)
{
gNetworkInfoProvEventCb = cb;
}
void UnRegisterResourceEventCallBack()
{
if (gNetworkInfoProvEventCb)
{
gNetworkInfoProvEventCb = NULL;
}
}
void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
{
if (name != NULL && pass != NULL)
{
OICStrcpy(name, sizeof(name), gProvResource.tnn);
OICStrcpy(pass, sizeof(pass), gProvResource.cd);
}
}
OCStackResult CreateProvisioningResource(bool isSecured)
{
gProvResource.ps = ES_PS_NEED_PROVISIONING;
gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;
gProvResource.tnt = CT_ADAPTER_IP;
OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "Unknown");
OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "Unknown");
OCStackResult res = OC_STACK_ERROR;
if (isSecured)
{
res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
OC_RSRVD_INTERFACE_DEFAULT,
OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
}
else
{
res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
OC_RSRVD_INTERFACE_DEFAULT,
OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
}
OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
return res;
}
OCStackResult DeleteProvisioningResource()
{
OCStackResult res = OCDeleteResource(gProvResource.handle);
if (res != OC_STACK_OK)
{
OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
}
return res;
}
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (!ehRequest)
{
OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
return ehResult;
}
if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
return ehResult;
}
OCRepPayload *getResp = constructResponse(ehRequest);
if (!getResp)