- Updated the enrollee SDK.
- Updated the Linux Application
Change-Id: Ia7a42011f609870fb2654f2a324213c1fdee5720
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/6133
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
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 = [
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)
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')
--- /dev/null
+//******************************************************************
+//
+// 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"
+
+/**
+ * @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;
+
+//-----------------------------------------------------------------------------
+// Private internal function prototypes
+//-----------------------------------------------------------------------------
+void OnboardingCallback(ESResult esResult);
+void ProvisioningCallback(ESResult esResult);
+void OnboardingCallbackTargetNet(ESResult esResult);
+static bool ValidateParam(OCConnectivityType networkType, const char *ssid, const char *passwd,
+ EventCallback cb);
+
+
+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;
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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;
+ }
+}
+
--- /dev/null
+//******************************************************************
+//
+// 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)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
+ return OC_EH_ERROR;
+ }
+
+ *payload = getResp;
+ ehResult = OC_EH_OK;
+
+ return ehResult;
+}
+
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
+{
+ OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+ if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
+ return ehResult;
+ }
+
+ OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
+ if (!input)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
+ return ehResult;
+ }
+
+ int64_t tr;
+ if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr))
+ {
+ // Triggering
+ gProvResource.tr = tr;
+ }
+
+ //ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
+ // A new request for provisioning means overriding existing network provisioning information.
+ if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED && tr == ES_PS_TRIGGER_CONNECTION)
+ {
+ OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
+ "Tiggering the network connection");
+
+ if (gNetworkInfoProvEventCb)
+ {
+ gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
+ ehResult = OC_EH_OK;
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
+ "Network handler not registered. Failed to connect to the network");
+ ehResult = OC_EH_ERROR;
+ }
+
+ return ehResult;
+ }
+ else if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED)
+ {
+ OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed. "
+ "This a request to override the existing the network provisioning information");
+ }
+ else
+ {
+ OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
+ }
+
+ OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "");
+ OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "");
+
+ char* tnn;
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
+ {
+ OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn);
+ OIC_LOG(INFO, ES_RH_TAG, "got ssid");
+ }
+
+ OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn);
+
+ char* cd;
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
+ {
+ OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd);
+ OIC_LOG(INFO, ES_RH_TAG, "got password");
+ }OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
+
+ gProvResource.ps = ES_PS_PROVISIONING_COMPLETED;
+
+ OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps);
+
+ OCRepPayload *getResp = constructResponse(ehRequest);
+ if (!getResp)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
+ return OC_EH_ERROR;
+ }
+
+ *payload = getResp;
+ ehResult = OC_EH_OK;
+
+ return ehResult;
+}
+
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * /*ehRequest*/,
+ OCRepPayload** /*payload*/)
+{
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+
+ return ehResult;
+}
+
+OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
+{
+ OCRepPayload* payload = OCRepPayloadCreate();
+ if (!payload)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+ return NULL;
+ }
+
+ if (ehRequest->resource == gProvResource.handle)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+ OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
+ OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, gProvResource.ps);
+ OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, gProvResource.tnt);
+ }
+ else if (ehRequest->requestHandle == gNetResource.handle)
+ {
+
+ OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET);
+ OCRepPayloadSetPropInt(payload, "ant", gNetResource.ant[0]);
+ }
+ return payload;
+}
+
+/**
+ * This is the entity handler for the registered resource.
+ * This is invoked by OCStack whenever it recevies a request for this resource.
+ */
+OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest* entityHandlerRequest, void *callback)
+{
+ (void) callback;
+ OCEntityHandlerResult ehRet = OC_EH_OK;
+ OCEntityHandlerResponse response =
+ { 0, 0, OC_EH_ERROR, 0, 0,
+ { },
+ { 0 }, false };
+ OCRepPayload* payload = NULL;
+
+ if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
+ {
+ if (OC_REST_GET == entityHandlerRequest->method)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
+ ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
+ }
+ else if (OC_REST_PUT == entityHandlerRequest->method)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
+
+ //PUT request will be handled in the internal implementation
+ if (gProvResource.handle != NULL
+ && entityHandlerRequest->resource == gProvResource.handle)
+ {
+ ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
+ ehRet = OC_EH_ERROR;
+ }
+ }
+ else if (OC_REST_POST == entityHandlerRequest->method)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
+ if (gProvResource.handle != NULL
+ && entityHandlerRequest->resource == gProvResource.handle)
+ {
+ ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
+ ehRet = OC_EH_ERROR;
+ }
+ }
+
+ if (ehRet == OC_EH_OK)
+ {
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = entityHandlerRequest->requestHandle;
+ response.resourceHandle = entityHandlerRequest->resource;
+ response.ehResult = ehRet;
+ //response uses OCPaylod while all get,put methodes use OCRepPayload
+ response.payload = (OCPayload*) (payload);
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof(response.sendVendorSpecificHeaderOptions));
+ memset(response.resourceUri, 0, sizeof(response.resourceUri));
+ // Indicate that response is NOT in a persistent buffer
+ response.persistentBufferFlag = 0;
+
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
+ ehRet = OC_EH_ERROR;
+ }
+ }
+ }
+
+ return ehRet;
+}
+
+const char *getResult(OCStackResult result)
+{
+ switch (result)
+ {
+ case OC_STACK_OK:
+ return "OC_STACK_OK";
+ case OC_STACK_INVALID_URI:
+ return "OC_STACK_INVALID_URI";
+ case OC_STACK_INVALID_QUERY:
+ return "OC_STACK_INVALID_QUERY";
+ case OC_STACK_INVALID_IP:
+ return "OC_STACK_INVALID_IP";
+ case OC_STACK_INVALID_PORT:
+ return "OC_STACK_INVALID_PORT";
+ case OC_STACK_INVALID_CALLBACK:
+ return "OC_STACK_INVALID_CALLBACK";
+ case OC_STACK_INVALID_METHOD:
+ return "OC_STACK_INVALID_METHOD";
+ case OC_STACK_NO_MEMORY:
+ return "OC_STACK_NO_MEMORY";
+ case OC_STACK_COMM_ERROR:
+ return "OC_STACK_COMM_ERROR";
+ case OC_STACK_INVALID_PARAM:
+ return "OC_STACK_INVALID_PARAM";
+ case OC_STACK_NOTIMPL:
+ return "OC_STACK_NOTIMPL";
+ case OC_STACK_NO_RESOURCE:
+ return "OC_STACK_NO_RESOURCE";
+ case OC_STACK_RESOURCE_ERROR:
+ return "OC_STACK_RESOURCE_ERROR";
+ case OC_STACK_SLOW_RESOURCE:
+ return "OC_STACK_SLOW_RESOURCE";
+ case OC_STACK_NO_OBSERVERS:
+ return "OC_STACK_NO_OBSERVERS";
+ case OC_STACK_ERROR:
+ return "OC_STACK_ERROR";
+ default:
+ return "UNKNOWN";
+ }
+}
+
--- /dev/null
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * These are adapter APIs will make caller modules agnostic to platform.
+ */
+
+#include "softapnative.h"
+#include "easysetup.h"
+#include "softap.h"
+#include "networkhandler.h"
+
+void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
+ const char* device_name );
+
+NetworkEventCallback gCallback;
+
+/**
+ * It will return Device which is creating Soft AP.
+ * i.e.Enrollee or Mediator.
+ * This decesion is based on, what is the value set for ES_SOFTAP_MODE in build command as well as
+ * in iotivity.spec file.
+ */
+DeviceRole ESSoftapHost()
+{
+#ifdef ENROLLEE_SOFTAP
+ //SoftAp at enrollee
+ return ENROLLEE;
+#else
+ //SoftAp at mediator
+ return MEDIATOR;
+#endif
+}
+
+/**
+ * It will return true if the Soft AP is created at Enrollee device
+ */
+bool ESSoftapAtEnrollee()
+{
+ return ( ESSoftapHost() == ENROLLEE) ? true : false;
+}
+
+/**
+ * It will return true if the Soft AP is created at Mediator device
+ */
+bool ESSoftapAtMediator()
+{
+ return (ESSoftapHost() == MEDIATOR) ? true : false;
+}
+
+/**
+ * This API will map result returned from the native to the caller.
+ * Callback API's signature needs to be modified under build switch according
+ * to the underline platform.
+ */
+void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
+ const char* device_name)
+{
+ if(SOFTAP_SUCCESS == result) //on Success
+ {
+ gCallback(ES_OK);
+ }
+ else //on Failure
+ {
+ gCallback(ES_ERROR);
+ }
+}
+
+/**
+ * This API will create the softap at enrollee
+ */
+void ESCreateSoftap(const char * ssid, const char* passwd, NetworkEventCallback cb)
+{
+ gCallback = cb;
+
+ // TODO: To be implemented
+ // Create Soft AP through native APIs -- start
+ // native API call by and pass ESCreateSoftapCallback() as callback
+ ESCreateSoftapNative(ssid, passwd,ESCreateSoftapCallback);
+ // Create Soft AP through native APIs -- end
+}
+
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef EASYSETUP_ENROLLEE_ONBOARDING_H__
-#define EASYSETUP_ENROLLEE_ONBOARDING_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus:$
-
-#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.
- */
-bool ESOnboard(const char * ssid, const char* passwd, NetworkEventCallback cb);
-
-/**
- * It will return true on-boarding type is soft AP.
- */
-bool ESSoftapOnboarding();
-
-/**
- * It will return true on-boarding type is BLE.
- */
-bool ESBleOnboarding();
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-
-#endif /* EASYSETUP_ENROLLEE_ONBOARDING_H__ */
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-// Do not remove the include below
-
-#include <string.h>
-#include "logger.h"
-#include "ocstack.h"
-#include "escommon.h"
-#include "networkhandler.h"
-#include "octypes.h"
-
-#ifndef ES_RESOURCE_HANDLER_H_
-#define ES_RESOURCE_HANDLER_H_
-
-typedef void (*ResourceEventCallback)(ESResult);
-
-/* Structure to represent a Light resource */
-typedef struct PROVRESOURCE
-{
- OCResourceHandle handle;
- int64_t ps; // provisiong status, 1 : need to provisioning, 2 : Connected to Enroller.
- int64_t tr; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
- int64_t tnt; // target network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
- char tnn[MAXSSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
- char cd[MAXNETCREDLEN]; // credential information.
-} ProvResource;
-
-/* Structure to represent a Light resource */
-typedef struct NETRESOURCE
-{
- OCResourceHandle handle;
- int64_t cnt; // current network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
- int64_t ant[MAXNUMTYPE]; // available network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
- char ipaddr[MAXADDRLEN]; // ip address.
- char cnn[MAXSSIDLEN]; // current network name.
-} NetResource;
-
-OCStackResult CreateProvisioningResource(bool isSecured);
-OCStackResult DeleteProvisioningResource();
-
-void GetTargetNetworkInfoFromProvResource(char *, char *);
-void RegisterResourceEventCallBack(ResourceEventCallback);
-void UnRegisterResourceEventCallBack(void);
-
-#endif
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#ifndef EASYSETUP_ENROLLEE_SOFTAP_H__
-#define EASYSETUP_ENROLLEE_SOFTAP_H__
-
-#include "escommon.h"
-#include "networkhandler.h"
-
-//#ifdef __cplusplus
-//extern "C" {
-//#endif // __cplusplus
-
-/**
- * @file
- *
- * This file contains the configuration for SoftAP
- */
-
-/**
- * It will return true if the Soft AP is created at Enrollee device
- */
-bool ESSoftapAtEnrollee();
-
-
-/**
- * It will return true if the Soft AP is created at Mediator device
- */
-
-bool ESSoftapAtMediator();
-
-/**
- * It will return Device which is creating Soft AP ; Devices are identified by their role
- * i.e. Enrollee or Mediator.
- */
-DeviceRole ESSoftapHost();
-
-/**
- * Handle Soft AP creation
- */
-void ESCreateSoftap(const char * ssid, const char* passwd, NetworkEventCallback cb);
-
-
-//#ifdef __cplusplus
-//}
-//#endif // __cplusplus
-
-
-#endif /* EASYSETUP_ENROLLEE_SOFTAP_H__ */
-
-
-
--- /dev/null
+/******************************************************************
+ *
+ * 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 "networkhandler.h"
+
+#include <unistd.h>
+
+#include "logger.h"
+#include "easysetup.h"
+#include "oic_string.h"
+
+#define LOG_TAG "LINUX ES"
+
+const char *gSsid = "DLNA_LISMORE1";
+const char *gPass = "dlna@010203";
+char *gIpAddress;
+NetworkEventCallback gNetworkEventCb;
+
+/*
+ * All the functions defined in this file are stub functions to be implemented by the end user of
+ * Easysetup Enrollee applications.
+ */
+static void ESActivateWifi()
+{
+
+}
+
+static void start()
+{
+ OIC_LOG(INFO, LOG_TAG, "START");
+ ESActivateWifi();
+}
+
+void ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
+{
+ OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
+ gPass = pass;
+ gSsid = ssid;
+ gNetworkEventCb = cb;
+ start();
+}
+
+ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
+{
+ if (targetType == CT_ADAPTER_IP)
+ {
+ info->type = CT_ADAPTER_IP;
+ info->ipaddr = gIpAddress;
+ if (strlen(gSsid) <= MAXSSIDLEN)
+ {
+ OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
+ return ES_OK;
+ }
+ else
+ {
+ return ES_ERROR;
+ }
+ }
+
+ return ES_ERROR;
+}
+
+++ /dev/null
-/******************************************************************
- *
- * 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 "networkhandler.h"
-
-#include <unistd.h>
-
-#include "logger.h"
-#include "easysetup.h"
-#include "oic_string.h"
-
-#define LOG_TAG "TIZEN ES"
-
-const char *gSsid = "DLNA_LISMORE1";
-const char *gPass = "dlna@010203";
-char *gIpAddress;
-NetworkEventCallback gNetworkEventCb;
-
-/*
- * All the functions defined in this file are stub functions to be implemented by the end user of
- * Easysetup Enrollee applications.
- */
-static void ESActivateWifi()
-{
-
-}
-
-static void start()
-{
- OIC_LOG(INFO, LOG_TAG, "START");
- ESActivateWifi();
-}
-
-void ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
-{
- OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
- gPass = pass;
- gSsid = ssid;
- gNetworkEventCb = cb;
- start();
-}
-
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
-{
- if (targetType == CT_ADAPTER_IP)
- {
- info->type = CT_ADAPTER_IP;
- info->ipaddr = gIpAddress;
- if (strlen(gSsid) <= MAXSSIDLEN)
- {
- OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
- return ES_OK;
- }
- else
- {
- return ES_ERROR;
- }
- }
-
- return ES_ERROR;
-}
-
--- /dev/null
+//******************************************************************
+//
+// 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 "softapnative.h"
+
+/**
+ * This API will create the Soft AP at Enrollee device.
+ */
+void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb)
+{
+ const char *ip, *macaddr, *devicename;
+
+ // Soft is created successfully. This callback may be send from other cascaded callbacks
+ cb(SOFTAP_SUCCESS, ip, macaddr, devicename);
+
+ // TODO: Use below code to indicate failed on-boarding / softap creation
+ // Soft creation is failed. This callback may be send from other cascaded callbacks
+ //cb(SOFTAP_FAILED, nullptr,nullptr,nullptr);
+}
+
+++ /dev/null
-//******************************************************************
-//
-// 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 "softapnative.h"
-
-/**
- * This API will create the Soft AP at Enrollee device.
- */
-void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb)
-{
- const char *ip, *macaddr, *devicename;
-
- // Soft is created successfully. This callback may be send from other cascaded callbacks
- cb(SOFTAP_SUCCESS, ip, macaddr, devicename);
-
- // TODO: Use below code to indicate failed on-boarding / softap creation
- // Soft creation is failed. This callback may be send from other cascaded callbacks
- //cb(SOFTAP_FAILED, nullptr,nullptr,nullptr);
-}
-
--- /dev/null
+//******************************************************************
+//
+// 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;
+}
+
+++ /dev/null
-//******************************************************************
-//
-// 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"
-
-/**
- * @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;
-
-//-----------------------------------------------------------------------------
-// Private internal function prototypes
-//-----------------------------------------------------------------------------
-void OnboardingCallback(ESResult esResult);
-void ProvisioningCallback(ESResult esResult);
-void OnboardingCallbackTargetNet(ESResult esResult);
-static bool ValidateParam(OCConnectivityType networkType, const char *ssid, const char *passwd,
- EventCallback cb);
-
-
-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;
-}
-
--- /dev/null
+//******************************************************************
+//
+// 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__ */
+
+
--- /dev/null
+//******************************************************************
+//
+// 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;
+ }
+}
+
+++ /dev/null
-//******************************************************************
-//
-// 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;
- }
-}
-
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+
+#ifndef EASYSETUP_ENROLLEE_ONBOARDING_H__
+#define EASYSETUP_ENROLLEE_ONBOARDING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus:$
+
+#include "networkhandler.h"
+
+/**
+ * @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);
+
+/**
+ * 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();
+
+/**
+ * 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();
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+
+#endif /* EASYSETUP_ENROLLEE_ONBOARDING_H__ */
--- /dev/null
+//******************************************************************
+//
+// 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)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
+ return OC_EH_ERROR;
+ }
+
+ *payload = getResp;
+ ehResult = OC_EH_OK;
+
+ return ehResult;
+}
+
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
+{
+ OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+ if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
+ return ehResult;
+ }
+
+ OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
+ if (!input)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
+ return ehResult;
+ }
+
+ int64_t tr;
+ if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr))
+ {
+ // Triggering
+ gProvResource.tr = tr;
+ }
+
+ //ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
+ // A new request for provisioning means overriding existing network provisioning information.
+ if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED && tr == ES_PS_TRIGGER_CONNECTION)
+ {
+ OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
+ "Tiggering the network connection");
+
+ if (gNetworkInfoProvEventCb)
+ {
+ gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
+ ehResult = OC_EH_OK;
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
+ "Network handler not registered. Failed to connect to the network");
+ ehResult = OC_EH_ERROR;
+ }
+
+ return ehResult;
+ }
+ else if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED)
+ {
+ OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed. "
+ "This a request to override the existing the network provisioning information");
+ }
+ else
+ {
+ OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
+ }
+
+ OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "");
+ OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "");
+
+ char* tnn;
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
+ {
+ OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn);
+ OIC_LOG(INFO, ES_RH_TAG, "got ssid");
+ }
+
+ OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn);
+
+ char* cd;
+ if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
+ {
+ OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd);
+ OIC_LOG(INFO, ES_RH_TAG, "got password");
+ }OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
+
+ gProvResource.ps = ES_PS_PROVISIONING_COMPLETED;
+
+ OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps);
+
+ OCRepPayload *getResp = constructResponse(ehRequest);
+ if (!getResp)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
+ return OC_EH_ERROR;
+ }
+
+ *payload = getResp;
+ ehResult = OC_EH_OK;
+
+ return ehResult;
+}
+
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
+ OCRepPayload** payload)
+{
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+
+ return ehResult;
+}
+
+OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
+{
+ OCRepPayload* payload = OCRepPayloadCreate();
+ if (!payload)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+ return NULL;
+ }
+
+ if (ehRequest->resource == gProvResource.handle)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+ OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
+ OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, gProvResource.ps);
+ OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, gProvResource.tnt);
+ }
+ else if (ehRequest->requestHandle == gNetResource.handle)
+ {
+
+ OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET);
+ OCRepPayloadSetPropInt(payload, "ant", gNetResource.ant[0]);
+ }
+ return payload;
+}
+
+/**
+ * This is the entity handler for the registered resource.
+ * This is invoked by OCStack whenever it recevies a request for this resource.
+ */
+OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest* entityHandlerRequest, void *callback)
+{
+ (void) callback;
+ OCEntityHandlerResult ehRet = OC_EH_OK;
+ OCEntityHandlerResponse response =
+ { 0, 0, OC_EH_ERROR, 0, 0,
+ { },
+ { 0 }, false };
+ OCRepPayload* payload = NULL;
+
+ if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
+ {
+ if (OC_REST_GET == entityHandlerRequest->method)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
+ ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
+ }
+ else if (OC_REST_PUT == entityHandlerRequest->method)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
+
+ //PUT request will be handled in the internal implementation
+ if (gProvResource.handle != NULL
+ && entityHandlerRequest->resource == gProvResource.handle)
+ {
+ ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
+ ehRet = OC_EH_ERROR;
+ }
+ }
+ else if (OC_REST_POST == entityHandlerRequest->method)
+ {
+ OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
+ if (gProvResource.handle != NULL
+ && entityHandlerRequest->resource == gProvResource.handle)
+ {
+ ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
+ }
+ else
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
+ ehRet = OC_EH_ERROR;
+ }
+ }
+
+ if (ehRet == OC_EH_OK)
+ {
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = entityHandlerRequest->requestHandle;
+ response.resourceHandle = entityHandlerRequest->resource;
+ response.ehResult = ehRet;
+ //response uses OCPaylod while all get,put methodes use OCRepPayload
+ response.payload = (OCPayload*) (payload);
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof(response.sendVendorSpecificHeaderOptions));
+ memset(response.resourceUri, 0, sizeof(response.resourceUri));
+ // Indicate that response is NOT in a persistent buffer
+ response.persistentBufferFlag = 0;
+
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
+ ehRet = OC_EH_ERROR;
+ }
+ }
+ }
+
+ return ehRet;
+}
+
+const char *getResult(OCStackResult result)
+{
+ switch (result)
+ {
+ case OC_STACK_OK:
+ return "OC_STACK_OK";
+ case OC_STACK_INVALID_URI:
+ return "OC_STACK_INVALID_URI";
+ case OC_STACK_INVALID_QUERY:
+ return "OC_STACK_INVALID_QUERY";
+ case OC_STACK_INVALID_IP:
+ return "OC_STACK_INVALID_IP";
+ case OC_STACK_INVALID_PORT:
+ return "OC_STACK_INVALID_PORT";
+ case OC_STACK_INVALID_CALLBACK:
+ return "OC_STACK_INVALID_CALLBACK";
+ case OC_STACK_INVALID_METHOD:
+ return "OC_STACK_INVALID_METHOD";
+ case OC_STACK_NO_MEMORY:
+ return "OC_STACK_NO_MEMORY";
+ case OC_STACK_COMM_ERROR:
+ return "OC_STACK_COMM_ERROR";
+ case OC_STACK_INVALID_PARAM:
+ return "OC_STACK_INVALID_PARAM";
+ case OC_STACK_NOTIMPL:
+ return "OC_STACK_NOTIMPL";
+ case OC_STACK_NO_RESOURCE:
+ return "OC_STACK_NO_RESOURCE";
+ case OC_STACK_RESOURCE_ERROR:
+ return "OC_STACK_RESOURCE_ERROR";
+ case OC_STACK_SLOW_RESOURCE:
+ return "OC_STACK_SLOW_RESOURCE";
+ case OC_STACK_NO_OBSERVERS:
+ return "OC_STACK_NO_OBSERVERS";
+ case OC_STACK_ERROR:
+ return "OC_STACK_ERROR";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+++ /dev/null
-//******************************************************************
-//
-// 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)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
- return OC_EH_ERROR;
- }
-
- *payload = getResp;
- ehResult = OC_EH_OK;
-
- return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
-{
- OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
- OCEntityHandlerResult ehResult = OC_EH_ERROR;
- if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
- return ehResult;
- }
-
- OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
- if (!input)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
- return ehResult;
- }
-
- int64_t tr;
- if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr))
- {
- // Triggering
- gProvResource.tr = tr;
- }
-
- //ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
- // A new request for provisioning means overriding existing network provisioning information.
- if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED && tr == ES_PS_TRIGGER_CONNECTION)
- {
- OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
- "Tiggering the network connection");
-
- if (gNetworkInfoProvEventCb)
- {
- gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
- ehResult = OC_EH_OK;
- }
- else
- {
- OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
- "Network handler not registered. Failed to connect to the network");
- ehResult = OC_EH_ERROR;
- }
-
- return ehResult;
- }
- else if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED)
- {
- OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed. "
- "This a request to override the existing the network provisioning information");
- }
- else
- {
- OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
- }
-
- OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "");
- OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "");
-
- char* tnn;
- if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
- {
- OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn);
- OIC_LOG(INFO, ES_RH_TAG, "got ssid");
- }
-
- OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn);
-
- char* cd;
- if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
- {
- OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd);
- OIC_LOG(INFO, ES_RH_TAG, "got password");
- }OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
-
- gProvResource.ps = ES_PS_PROVISIONING_COMPLETED;
-
- OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps);
-
- OCRepPayload *getResp = constructResponse(ehRequest);
- if (!getResp)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
- return OC_EH_ERROR;
- }
-
- *payload = getResp;
- ehResult = OC_EH_OK;
-
- return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * /*ehRequest*/,
- OCRepPayload** /*payload*/)
-{
- OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
- return ehResult;
-}
-
-OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
-{
- OCRepPayload* payload = OCRepPayloadCreate();
- if (!payload)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
- return NULL;
- }
-
- if (ehRequest->resource == gProvResource.handle)
- {
- OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
- OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
- OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, gProvResource.ps);
- OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, gProvResource.tnt);
- }
- else if (ehRequest->requestHandle == gNetResource.handle)
- {
-
- OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET);
- OCRepPayloadSetPropInt(payload, "ant", gNetResource.ant[0]);
- }
- return payload;
-}
-
-/**
- * This is the entity handler for the registered resource.
- * This is invoked by OCStack whenever it recevies a request for this resource.
- */
-OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest* entityHandlerRequest, void *callback)
-{
- (void) callback;
- OCEntityHandlerResult ehRet = OC_EH_OK;
- OCEntityHandlerResponse response =
- { 0, 0, OC_EH_ERROR, 0, 0,
- { },
- { 0 }, false };
- OCRepPayload* payload = NULL;
-
- if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
- {
- if (OC_REST_GET == entityHandlerRequest->method)
- {
- OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
- ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
- }
- else if (OC_REST_PUT == entityHandlerRequest->method)
- {
- OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
-
- //PUT request will be handled in the internal implementation
- if (gProvResource.handle != NULL
- && entityHandlerRequest->resource == gProvResource.handle)
- {
- ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
- }
- else
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
- ehRet = OC_EH_ERROR;
- }
- }
- else if (OC_REST_POST == entityHandlerRequest->method)
- {
- OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
- if (gProvResource.handle != NULL
- && entityHandlerRequest->resource == gProvResource.handle)
- {
- ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
- }
- else
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
- ehRet = OC_EH_ERROR;
- }
- }
-
- if (ehRet == OC_EH_OK)
- {
- // Format the response. Note this requires some info about the request
- response.requestHandle = entityHandlerRequest->requestHandle;
- response.resourceHandle = entityHandlerRequest->resource;
- response.ehResult = ehRet;
- //response uses OCPaylod while all get,put methodes use OCRepPayload
- response.payload = (OCPayload*) (payload);
- response.numSendVendorSpecificHeaderOptions = 0;
- memset(response.sendVendorSpecificHeaderOptions, 0,
- sizeof(response.sendVendorSpecificHeaderOptions));
- memset(response.resourceUri, 0, sizeof(response.resourceUri));
- // Indicate that response is NOT in a persistent buffer
- response.persistentBufferFlag = 0;
-
- // Send the response
- if (OCDoResponse(&response) != OC_STACK_OK)
- {
- OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
- ehRet = OC_EH_ERROR;
- }
- }
- }
-
- return ehRet;
-}
-
-const char *getResult(OCStackResult result)
-{
- switch (result)
- {
- case OC_STACK_OK:
- return "OC_STACK_OK";
- case OC_STACK_INVALID_URI:
- return "OC_STACK_INVALID_URI";
- case OC_STACK_INVALID_QUERY:
- return "OC_STACK_INVALID_QUERY";
- case OC_STACK_INVALID_IP:
- return "OC_STACK_INVALID_IP";
- case OC_STACK_INVALID_PORT:
- return "OC_STACK_INVALID_PORT";
- case OC_STACK_INVALID_CALLBACK:
- return "OC_STACK_INVALID_CALLBACK";
- case OC_STACK_INVALID_METHOD:
- return "OC_STACK_INVALID_METHOD";
- case OC_STACK_NO_MEMORY:
- return "OC_STACK_NO_MEMORY";
- case OC_STACK_COMM_ERROR:
- return "OC_STACK_COMM_ERROR";
- case OC_STACK_INVALID_PARAM:
- return "OC_STACK_INVALID_PARAM";
- case OC_STACK_NOTIMPL:
- return "OC_STACK_NOTIMPL";
- case OC_STACK_NO_RESOURCE:
- return "OC_STACK_NO_RESOURCE";
- case OC_STACK_RESOURCE_ERROR:
- return "OC_STACK_RESOURCE_ERROR";
- case OC_STACK_SLOW_RESOURCE:
- return "OC_STACK_SLOW_RESOURCE";
- case OC_STACK_NO_OBSERVERS:
- return "OC_STACK_NO_OBSERVERS";
- case OC_STACK_ERROR:
- return "OC_STACK_ERROR";
- default:
- return "UNKNOWN";
- }
-}
-
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+
+#include <string.h>
+#include "logger.h"
+#include "ocstack.h"
+#include "escommon.h"
+#include "networkhandler.h"
+#include "octypes.h"
+
+#ifndef ES_RESOURCE_HANDLER_H_
+#define ES_RESOURCE_HANDLER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*ResourceEventCallback)(ESResult);
+
+/* Structure to represent a Light resource */
+typedef struct PROVRESOURCE
+{
+ OCResourceHandle handle;
+ int64_t ps; // provisiong status, 1 : need to provisioning, 2 : Connected to Enroller.
+ int64_t tr; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
+ int64_t tnt; // target network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
+ char tnn[MAXSSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
+ char cd[MAXNETCREDLEN]; // credential information.
+} ProvResource;
+
+/* Structure to represent a Light resource */
+typedef struct NETRESOURCE
+{
+ OCResourceHandle handle;
+ int64_t cnt; // current network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
+ int64_t ant[MAXNUMTYPE]; // available network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
+ char ipaddr[MAXADDRLEN]; // ip address.
+ char cnn[MAXSSIDLEN]; // current network name.
+} NetResource;
+
+OCStackResult CreateProvisioningResource(bool isSecured);
+OCStackResult DeleteProvisioningResource();
+
+void GetTargetNetworkInfoFromProvResource(char *, char *);
+void RegisterResourceEventCallBack(ResourceEventCallback);
+void UnRegisterResourceEventCallBack(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //ES_RESOURCE_HANDLER_H_
\ No newline at end of file
--- /dev/null
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * These are adapter APIs will make caller modules agnostic to platform.
+ */
+
+#include "softapnative.h"
+#include "easysetup.h"
+#include "softap.h"
+#include "networkhandler.h"
+
+void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
+ const char* device_name );
+
+NetworkEventCallback gCallback;
+
+/**
+ * It will return Device which is creating Soft AP.
+ * i.e.Enrollee or Mediator.
+ * This decesion is based on, what is the value set for ES_SOFTAP_MODE in build command as well as
+ * in iotivity.spec file.
+ */
+DeviceRole ESSoftapHost()
+{
+#ifdef ENROLLEE_SOFTAP
+ //SoftAp at enrollee
+ return ENROLLEE;
+#else
+ //SoftAp at mediator
+ return MEDIATOR;
+#endif
+}
+
+/**
+ * It will return true if the Soft AP is created at Enrollee device
+ */
+bool ESSoftapAtEnrollee()
+{
+ return ( ESSoftapHost() == ENROLLEE) ? true : false;
+}
+
+/**
+ * It will return true if the Soft AP is created at Mediator device
+ */
+bool ESSoftapAtMediator()
+{
+ return (ESSoftapHost() == MEDIATOR) ? true : false;
+}
+
+/**
+ * This API will map result returned from the native to the caller.
+ * Callback API's signature needs to be modified under build switch according
+ * to the underline platform.
+ */
+void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
+ const char* device_name)
+{
+ if(SOFTAP_SUCCESS == result) //on Success
+ {
+ gCallback(ES_OK);
+ }
+ else //on Failure
+ {
+ gCallback(ES_ERROR);
+ }
+}
+
+/**
+ * This API will create the softap at enrollee
+ */
+void ESCreateSoftap(const char * ssid, const char* passwd, NetworkEventCallback cb)
+{
+ gCallback = cb;
+
+ // TODO: To be implemented
+ // Create Soft AP through native APIs -- start
+ // native API call by and pass ESCreateSoftapCallback() as callback
+ ESCreateSoftapNative(ssid, passwd,ESCreateSoftapCallback);
+ // Create Soft AP through native APIs -- end
+}
+
+++ /dev/null
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * These are adapter APIs will make caller modules agnostic to platform.
- */
-
-#include "softapnative.h"
-#include "easysetup.h"
-#include "softap.h"
-#include "networkhandler.h"
-
-void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
- const char* device_name );
-
-NetworkEventCallback gCallback;
-
-/**
- * It will return Device which is creating Soft AP.
- * i.e.Enrollee or Mediator.
- * This decesion is based on, what is the value set for ES_SOFTAP_MODE in build command as well as
- * in iotivity.spec file.
- */
-DeviceRole ESSoftapHost()
-{
-#ifdef ENROLLEE_SOFTAP
- //SoftAp at enrollee
- return ENROLLEE;
-#else
- //SoftAp at mediator
- return MEDIATOR;
-#endif
-}
-
-/**
- * It will return true if the Soft AP is created at Enrollee device
- */
-bool ESSoftapAtEnrollee()
-{
- return ( ESSoftapHost() == ENROLLEE) ? true : false;
-}
-
-/**
- * It will return true if the Soft AP is created at Mediator device
- */
-bool ESSoftapAtMediator()
-{
- return (ESSoftapHost() == MEDIATOR) ? true : false;
-}
-
-/**
- * This API will map result returned from the native to the caller.
- * Callback API's signature needs to be modified under build switch according
- * to the underline platform.
- */
-void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
- const char* device_name)
-{
- if(SOFTAP_SUCCESS == result) //on Success
- {
- gCallback(ES_OK);
- }
- else //on Failure
- {
- gCallback(ES_ERROR);
- }
-}
-
-/**
- * This API will create the softap at enrollee
- */
-void ESCreateSoftap(const char * ssid, const char* passwd, NetworkEventCallback cb)
-{
- gCallback = cb;
-
- // TODO: To be implemented
- // Create Soft AP through native APIs -- start
- // native API call by and pass ESCreateSoftapCallback() as callback
- ESCreateSoftapNative(ssid, passwd,ESCreateSoftapCallback);
- // Create Soft AP through native APIs -- end
-}
-
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+
+#ifndef EASYSETUP_ENROLLEE_SOFTAP_H__
+#define EASYSETUP_ENROLLEE_SOFTAP_H__
+
+#include "escommon.h"
+#include "networkhandler.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file
+ *
+ * This file contains platform agnostic API for creation of Soft AP
+ * @Note : Some of the APIs of this file need to be modified by the OEM according to the device configuration
+ */
+
+/**
+ * This function verify if the Soft AP is created at Enrollee device.
+ * @return ::True, if Soft AP is created at Enrollee device.
+ * @Note : This API needs to be modified by the OEM according to the device configuration
+ */
+
+bool ESSoftapAtEnrollee();
+
+/**
+ * This function verify if the Soft AP is created at Mediator device.
+ * @return ::True, if Soft AP is created at Mediator device.
+ * @Note : This API needs to be modified by the OEM according to the device configuration
+ */
+
+bool ESSoftapAtMediator();
+
+
+/**
+ * This function finds which Device (Enrollee or Mediator) is creating Soft AP.
+ * @return ::DeviceRole (ENROLLEE or MEDIATOR)
+ * @Note : This API needs to be modified by the OEM according to the device configuration
+ */
+
+DeviceRole ESSoftapHost();
+
+/**
+ * This function Initializes the EasySetup. This API must be called prior to invoking any other API
+ *
+ * @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 ::void.
+ */
+void ESCreateSoftap(const char * ssid, const char* passwd, NetworkEventCallback cb);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* EASYSETUP_ENROLLEE_SOFTAP_H__ */
+
+
+
--- /dev/null
+/******************************************************************
+ *
+ * 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 "networkhandler.h"
+
+#include <wifi.h>
+#include <unistd.h>
+
+#include "logger.h"
+#include "easysetup.h"
+#include "oic_string.h"
+
+#define LOG_TAG "TIZEN ES"
+
+const char *gSsid = "DLNA_LISMORE1";
+const char *gPass = "dlna@010203";
+char *gIpAddress = NULL;
+wifi_ap_h connectedWifi;
+NetworkEventCallback gNetworkEventCb;
+static void ESActivateWifi();
+
+static const char*
+print_state(wifi_connection_state_e state)
+{
+ switch (state)
+ {
+ case WIFI_CONNECTION_STATE_DISCONNECTED:
+ return "Disconnected";
+ case WIFI_CONNECTION_STATE_ASSOCIATION:
+ return "Association";
+ case WIFI_CONNECTION_STATE_CONNECTED:
+ return "Connected";
+ case WIFI_CONNECTION_STATE_CONFIGURATION:
+ return "Configuration";
+ }
+}
+
+void __wifi_connected_cb(wifi_error_e error_code, void *user_data)
+{
+ OIC_LOG(INFO,LOG_TAG,"#### __connected ");
+
+ if (gIpAddress)
+ free(gIpAddress);
+
+ wifi_ap_get_ip_address(connectedWifi, WIFI_ADDRESS_FAMILY_IPV4, &gIpAddress);
+ OIC_LOG_V(INFO,LOG_TAG,"#### __connected, Ipaddress=%s", gIpAddress);
+ gNetworkEventCb(ES_OK);
+
+}
+
+bool __wifi_found_ap_cb(wifi_ap_h ap, void *user_data)
+{
+ OIC_LOG(INFO,LOG_TAG,"#### __wifi_found_ap_cb received ");
+
+ int error_code = 0;
+ char *ap_name = NULL;
+ wifi_connection_state_e state;
+
+ error_code = wifi_ap_get_essid(ap, &ap_name);
+ if (error_code != WIFI_ERROR_NONE)
+ {
+ OIC_LOG(ERROR,LOG_TAG,"#### Fail to get AP name.");
+
+ return false;
+ }
+ error_code = wifi_ap_get_connection_state(ap, &state);
+ if (error_code != WIFI_ERROR_NONE)
+ {
+ OIC_LOG(ERROR,LOG_TAG,"#### Fail to get state.");
+ free(ap_name);
+
+ return false;
+ }
+ OIC_LOG_V(INFO,LOG_TAG,"#### AP name : %s, state : %s", ap_name, print_state(state));
+
+ if (strcmp(ap_name, gSsid) == 0)
+ {
+ OIC_LOG(INFO,LOG_TAG,"#### network found");
+ wifi_ap_set_passphrase(ap, gPass);
+ connectedWifi = ap;
+ error_code = wifi_connect(ap, __wifi_connected_cb, NULL);
+ OIC_LOG_V(INFO,LOG_TAG,"Code=%d", error_code);
+ }
+ OIC_LOG(INFO,LOG_TAG,"#### __wifi_found_ap_cb received ");
+ free(ap_name);
+ return true;
+}
+void __scan_request_cb(wifi_error_e error_code, void *user_data)
+{
+ OIC_LOG(INFO, LOG_TAG, "__scan_request_cb");
+ int error_code1;
+ error_code1 = wifi_foreach_found_aps(__wifi_found_ap_cb, NULL);
+ if (error_code1 != WIFI_ERROR_NONE)
+ OIC_LOG(INFO,LOG_TAG,"#### Fail to scan");
+
+ OIC_LOG(INFO, LOG_TAG,"#### __scan_request_cb exit ");
+}
+
+static void __wifi_activated_cb(wifi_error_e result, void *user_data)
+{
+ OIC_LOG(INFO, LOG_TAG, "__wifi_activated_cb");
+ if (result == WIFI_ERROR_NONE)
+ {
+ OIC_LOG(INFO,LOG_TAG,"#### Success to activate Wi-Fi device!");
+ }
+ wifi_scan(__scan_request_cb, NULL);
+
+}
+static void ESActivateWifi()
+{
+ int error_code;
+ error_code = wifi_initialize();
+ OIC_LOG_V(INFO,LOG_TAG,"#### WIFI INITIALIZED WITH STATUS :%d", error_code);
+
+ error_code = wifi_activate(__wifi_activated_cb, NULL);
+ OIC_LOG_V(INFO,LOG_TAG,"#### WIFI ACTIVATED WITH STATUS :%d", error_code);
+
+ bool wifi_activated = false;
+ wifi_is_activated(&wifi_activated);
+ if (wifi_activated)
+ {
+ OIC_LOG(INFO,LOG_TAG,"#### Success to get Wi-Fi device state.");
+ int scan_result = wifi_scan(__scan_request_cb, NULL);
+ OIC_LOG_V(INFO,LOG_TAG,"#### Wifi scan result:%d", scan_result);
+ }
+ else
+ {
+ OIC_LOG(ERROR,LOG_TAG, "#### Fail to get Wi-Fi device state.");
+ }
+}
+
+static void start()
+{
+ OIC_LOG(INFO, LOG_TAG, "START");
+ ESActivateWifi();
+}
+
+void ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
+{
+ OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
+ gPass = pass;
+ gSsid = ssid;
+ gNetworkEventCb = cb;
+ start();
+}
+
+ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
+{
+ if (targetType == CT_ADAPTER_IP)
+ {
+ info->type = CT_ADAPTER_IP;
+ info->ipaddr = gIpAddress;
+ if (strlen(gSsid) <= MAXSSIDLEN)
+ {
+ OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
+ return ES_OK;
+ }
+ else
+ {
+ return ES_ERROR;
+ }
+ }
+
+ return ES_ERROR;
+}
+
+++ /dev/null
-/******************************************************************
- *
- * 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 "networkhandler.h"
-
-#include <wifi.h>
-#include <unistd.h>
-
-#include "logger.h"
-#include "easysetup.h"
-#include "oic_string.h"
-
-#define LOG_TAG "TIZEN ES"
-
-const char *gSsid = "DLNA_LISMORE1";
-const char *gPass = "dlna@010203";
-char *gIpAddress = NULL;
-wifi_ap_h connectedWifi;
-NetworkEventCallback gNetworkEventCb;
-static void ESActivateWifi();
-
-static const char*
-print_state(wifi_connection_state_e state)
-{
- switch (state)
- {
- case WIFI_CONNECTION_STATE_DISCONNECTED:
- return "Disconnected";
- case WIFI_CONNECTION_STATE_ASSOCIATION:
- return "Association";
- case WIFI_CONNECTION_STATE_CONNECTED:
- return "Connected";
- case WIFI_CONNECTION_STATE_CONFIGURATION:
- return "Configuration";
- }
-}
-
-void __wifi_connected_cb(wifi_error_e error_code, void *user_data)
-{
- OIC_LOG(INFO,LOG_TAG,"#### __connected ");
-
- if (gIpAddress)
- free(gIpAddress);
-
- wifi_ap_get_ip_address(connectedWifi, WIFI_ADDRESS_FAMILY_IPV4, &gIpAddress);
- OIC_LOG_V(INFO,LOG_TAG,"#### __connected, Ipaddress=%s", gIpAddress);
- gNetworkEventCb(ES_OK);
-
-}
-
-bool __wifi_found_ap_cb(wifi_ap_h ap, void *user_data)
-{
- OIC_LOG(INFO,LOG_TAG,"#### __wifi_found_ap_cb received ");
-
- int error_code = 0;
- char *ap_name = NULL;
- wifi_connection_state_e state;
-
- error_code = wifi_ap_get_essid(ap, &ap_name);
- if (error_code != WIFI_ERROR_NONE)
- {
- OIC_LOG(ERROR,LOG_TAG,"#### Fail to get AP name.");
-
- return false;
- }
- error_code = wifi_ap_get_connection_state(ap, &state);
- if (error_code != WIFI_ERROR_NONE)
- {
- OIC_LOG(ERROR,LOG_TAG,"#### Fail to get state.");
- free(ap_name);
-
- return false;
- }
- OIC_LOG_V(INFO,LOG_TAG,"#### AP name : %s, state : %s", ap_name, print_state(state));
-
- if (strcmp(ap_name, gSsid) == 0)
- {
- OIC_LOG(INFO,LOG_TAG,"#### network found");
- wifi_ap_set_passphrase(ap, gPass);
- connectedWifi = ap;
- error_code = wifi_connect(ap, __wifi_connected_cb, NULL);
- OIC_LOG_V(INFO,LOG_TAG,"Code=%d", error_code);
- }
- OIC_LOG(INFO,LOG_TAG,"#### __wifi_found_ap_cb received ");
- free(ap_name);
- return true;
-}
-void __scan_request_cb(wifi_error_e error_code, void *user_data)
-{
- OIC_LOG(INFO, LOG_TAG, "__scan_request_cb");
- int error_code1;
- error_code1 = wifi_foreach_found_aps(__wifi_found_ap_cb, NULL);
- if (error_code1 != WIFI_ERROR_NONE)
- OIC_LOG(INFO,LOG_TAG,"#### Fail to scan");
-
- OIC_LOG(INFO, LOG_TAG,"#### __scan_request_cb exit ");
-}
-
-static void __wifi_activated_cb(wifi_error_e result, void *user_data)
-{
- OIC_LOG(INFO, LOG_TAG, "__wifi_activated_cb");
- if (result == WIFI_ERROR_NONE)
- {
- OIC_LOG(INFO,LOG_TAG,"#### Success to activate Wi-Fi device!");
- }
- wifi_scan(__scan_request_cb, NULL);
-
-}
-static void ESActivateWifi()
-{
- int error_code;
- error_code = wifi_initialize();
- OIC_LOG_V(INFO,LOG_TAG,"#### WIFI INITIALIZED WITH STATUS :%d", error_code);
-
- error_code = wifi_activate(__wifi_activated_cb, NULL);
- OIC_LOG_V(INFO,LOG_TAG,"#### WIFI ACTIVATED WITH STATUS :%d", error_code);
-
- bool wifi_activated = false;
- wifi_is_activated(&wifi_activated);
- if (wifi_activated)
- {
- OIC_LOG(INFO,LOG_TAG,"#### Success to get Wi-Fi device state.");
- int scan_result = wifi_scan(__scan_request_cb, NULL);
- OIC_LOG_V(INFO,LOG_TAG,"#### Wifi scan result:%d", scan_result);
- }
- else
- {
- OIC_LOG(ERROR,LOG_TAG, "#### Fail to get Wi-Fi device state.");
- }
-}
-
-static void start()
-{
- OIC_LOG(INFO, LOG_TAG, "START");
- ESActivateWifi();
-}
-
-void ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
-{
- OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
- gPass = pass;
- gSsid = ssid;
- gNetworkEventCb = cb;
- start();
-}
-
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
-{
- if (targetType == CT_ADAPTER_IP)
- {
- info->type = CT_ADAPTER_IP;
- info->ipaddr = gIpAddress;
- if (strlen(gSsid) <= MAXSSIDLEN)
- {
- OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
- return ES_OK;
- }
- else
- {
- return ES_ERROR;
- }
- }
-
- return ES_ERROR;
-}
-
--- /dev/null
+//******************************************************************
+//
+// 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 "softapnative.h"
+
+/**
+ * This API will create the Soft AP at Enrollee device.
+ */
+void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb)
+{
+ const char *ip, *macaddr, *devicename;
+
+ // Soft is created successfully. This callback may be send from other cascaded callbacks
+ cb(SOFTAP_SUCCESS, ip, macaddr, devicename);
+
+ // TODO: Use below code to indicate failed on-boarding / softap creation
+ // Soft creation is failed. This callback may be send from other cascaded callbacks
+ //cb(SOFTAP_FAILED, nullptr,nullptr,nullptr);
+}
+
+++ /dev/null
-//******************************************************************
-//
-// 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 "softapnative.h"
-
-/**
- * This API will create the Soft AP at Enrollee device.
- */
-void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb)
-{
- const char *ip, *macaddr, *devicename;
-
- // Soft is created successfully. This callback may be send from other cascaded callbacks
- cb(SOFTAP_SUCCESS, ip, macaddr, devicename);
-
- // TODO: Use below code to indicate failed on-boarding / softap creation
- // Soft creation is failed. This callback may be send from other cascaded callbacks
- //cb(SOFTAP_FAILED, nullptr,nullptr,nullptr);
-}
-
#include "onboarding.h"
#include "resourcehandler.h"
#include "softap.h"
+#include "easysetupcallbacks.h"
#include "gtesthelper.h"
char ssid[] = "EasySetup123";
char passwd[] = "EasySetup123";
-void OnboardingCallback(ESResult esResult);
-
//-----------------------------------------------------------------------------
// Callback functions
//-----------------------------------------------------------------------------
#ifndef ES_COMMON_H_
#define ES_COMMON_H_
-#include <iostream>
-#include <string>
-#ifndef WITH_ARDUINO
-#include <memory>
-#endif
-
#include "ocstack.h"
#include "octypes.h"
-using namespace std;
-
// Defines
#define OIC_STRING_MAX_VALUE 100
#define IPV4_ADDR_SIZE 16
if enrollee_env.get('SECURED') == '1':
enrollee_env.PrependUnique(LIBS = ['ocpmapi', 'ocprovision'])
-enrollee = enrollee_env.Program('enrollee', 'enrolleewifi.cpp')
+enrollee = enrollee_env.Program('enrollee', 'enrolleewifi.c')
i_enrollee = enrollee_env.Install(env.get('BUILD_DIR'), enrollee)
--- /dev/null
+//******************************************************************
+//
+// 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 "easysetup.h"
+
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#define TAG "TS"
+
+void *listeningFunc(void *);
+
+/**
+ * @var ssid
+ * @brief Target SSID of the Soft Access point to which the device has to connect
+ */
+static char ssid[] = "EasySetup123";
+
+/**
+ * @var passwd
+ * @brief Password of the Soft Access point to which the device has to connect
+ */
+static char passwd[] = "EasySetup123";
+
+/**
+ * Secure Virtual Resource database for Iotivity Server
+ * It contains Server's Identity and the PSK credentials
+ * of other devices which the server trusts
+ */
+static char CRED_FILE[] = "oic_svr_db_server.json";
+
+OCPersistentStorage ps ;
+
+
+/**
+ * @var gIsSecured
+ * @brief Variable to check if secure mode is enabled or not.
+ */
+static bool gIsSecured = false;
+
+void PrintMenu()
+{
+ printf("============\n");
+ printf("S: Enabled Security\n");
+ printf("I: Init easy setup\n");
+ printf("P: start provisioning resources\n");
+ printf("T: terminate\n");
+ printf("Q: quit\n");
+ printf("============\n");
+}
+
+void EventCallbackInApp(ESResult esResult, EnrolleeState enrolleeState)
+{
+ printf("Easy setup event callback\n");
+
+ if(esResult == ES_OK)
+ {
+ if(enrolleeState == ES_ON_BOARDED_STATE)
+ {
+ printf("Device is successfully OnBoared on Adhoc network\n");
+ }
+ else if (enrolleeState == ES_PROVISIONED_STATE)
+ {
+ printf("Device is provisioned with target network's credentials\n");
+ }
+ else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
+ {
+ printf("Device is onboarded/connected with target network\n");
+ }
+ else
+ {
+ printf("Wrong state !! Easy setup is failed at Enrollee state = %d\n",enrolleeState);
+ }
+ }
+ else
+ {
+ printf("Easy stup is failed at Enrollee state = %d\n",enrolleeState);;
+ }
+
+ PrintMenu();
+}
+
+FILE* server_fopen(const char *path, const char *mode)
+{
+ (void) path;
+ return fopen(CRED_FILE, mode);
+}
+
+void EnableSecurity()
+{
+ printf("Inside EnableSecurity API..\n");
+
+ gIsSecured = true;
+
+ // Initialize Persistent Storage for SVR database
+ ps = (OCPersistentStorage){ server_fopen, fread, fwrite, fclose, unlink };
+ OCRegisterPersistentStorageHandler(&ps);
+}
+
+void StartEasySetup()
+{
+ printf("StartEasySetup and onboarding started..\n");
+
+ if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, gIsSecured, EventCallbackInApp) == ES_ERROR)
+ {
+ printf("StartEasySetup and onboarding Fail!!\n");
+ return;
+ }
+}
+
+void StartOICStackAndStartResources()
+{
+ printf("Starting Enrollee Provisioning\n");
+
+ // Initialize the OC Stack in Server mode
+ if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
+ {
+ printf("OCStack init error!!\n");
+ return;
+ }
+
+ if (InitProvisioning() == ES_ERROR)
+ {
+ printf("Init Provisioning Failed!!\n");
+ return;
+ }
+
+ pthread_t thread_handle;
+ if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
+ {
+ printf("Thread creation failed\n");
+ }
+
+ printf("InitProvisioning Success\n");
+}
+
+void StopEasySetup()
+{
+ printf("StopEasySetup IN\n");
+
+ if (TerminateEasySetup() == ES_ERROR)
+ {
+ printf("TerminateEasySetup Failed!!\n");
+ return;
+ }
+
+ //stop OC Stack
+ if (OCStop() != OC_STACK_OK)
+ {
+ printf("OCStack stop failed!!\n");
+ return;
+ }
+
+ printf("StopEasySetup OUT\n");
+}
+
+int main()
+{
+ printf("#########################\n");
+ printf("EasySetup Enrollee SAMPLE\n");
+ printf("#########################\n");
+ PrintMenu();
+ char option = 'T';
+
+ while(true)
+ {
+ scanf("%c",&option);
+
+ if(option!= '\n')
+ {
+ switch (option)
+ {
+ case 'H': // help
+ case 'h':
+ PrintMenu();
+ break;
+
+ case 'Q': // quit
+ case 'q':
+ printf("quit");
+ break;
+
+ case 'S': // Enable Security
+ case 's':
+ EnableSecurity();
+ break;
+
+ case 'I': // Init EasySetup
+ case 'i':
+ StartEasySetup();
+ break;
+
+ case 'P': // start provisioning
+ case 'p':
+ StartOICStackAndStartResources();
+ break;
+
+ case 'T': // stop easy setup
+ case 't':
+ StopEasySetup();
+ break;
+
+ default:
+ printf("wrong option\n");
+ break;
+ }
+ if (option == 'Q' || option == 'q') break;
+ }
+ }
+ return 0;
+}
+
+void *listeningFunc(void * a)
+{
+ OCStackResult result;
+
+ while (true)
+ {
+ result = OCProcess();
+ if (result != OC_STACK_OK)
+ {
+ printf("OCStack stop error");
+ }
+ }
+ return NULL;
+}
+
+++ /dev/null
-//******************************************************************
-//
-// 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 "easysetup.h"
-
-#include <unistd.h>
-#include <string.h>
-#include <iostream>
-#include <pthread.h>
-
-#define TAG "TS"
-
-using namespace std;
-
-void *listeningFunc(void*);
-
-/**
- * @var ssid
- * @brief Target SSID of the Soft Access point to which the device has to connect
- */
-static char ssid[] = "EasySetup123";
-
-/**
- * @var passwd
- * @brief Password of the Soft Access point to which the device has to connect
- */
-static char passwd[] = "EasySetup123";
-
-/**
- * Secure Virtual Resource database for Iotivity Server
- * It contains Server's Identity and the PSK credentials
- * of other devices which the server trusts
- */
-static char CRED_FILE[] = "oic_svr_db_server.json";
-
-OCPersistentStorage ps ;
-
-
-/**
- * @var gIsSecured
- * @brief Variable to check if secure mode is enabled or not.
- */
-static bool gIsSecured = false;
-
-void PrintMenu()
-{
- cout<<"============"<<endl;
- cout<<"S: Enabled Security"<<endl;
- cout<<"I: Init easy setup"<<endl;
- cout<<"P: start provisioning resources"<<endl;
- cout<<"T: terminate"<<endl;
- cout<<"Q: quit"<<endl;
- cout<<"============"<<endl;
-}
-
-void EventCallbackInApp(ESResult esResult, EnrolleeState enrolleeState)
-{
- cout<<"Easy setup event callback"<<endl;
-
- if(esResult == ES_OK)
- {
- if(enrolleeState == ES_ON_BOARDED_STATE)
- {
- cout<<"Device is successfully OnBoared on Adhoc network"<<endl;
- }
- else if (enrolleeState == ES_PROVISIONED_STATE)
- {
- cout<<"Device is provisioned with target network's credentials"<<endl;
- }
- else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
- {
- cout<<"Device is onboarded/connected with target network"<<endl;
- }
- else
- {
- cout<<"Wrong state !! Easy setup is failed at Enrollee state = "<<enrolleeState<<endl;
- }
- }
- else
- {
- cout<<"Easy stup is failed at Enrollee state = "<<enrolleeState<<endl;
- }
-
- PrintMenu();
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
- (void) path;
- return fopen(CRED_FILE, mode);
-}
-
-void EnableSecurity()
-{
- cout << "Inside EnableSecurity API.." << endl;
-
- gIsSecured = true;
-
- // Initialize Persistent Storage for SVR database
- ps = { server_fopen, fread, fwrite, fclose, unlink };
- OCRegisterPersistentStorageHandler(&ps);
-}
-
-void StartEasySetup()
-{
- cout<<"StartEasySetup and onboarding started.."<<endl;
-
- if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, gIsSecured, EventCallbackInApp) == ES_ERROR)
- {
- cout<<"StartEasySetup and onboarding Fail!!"<<endl;
- return;
- }
-}
-
-void StartOICStackAndStartResources()
-{
- cout<<"Starting Enrollee Provisioning"<<endl;
-
- // Initialize the OC Stack in Server mode
- if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
- {
- cout<<"OCStack init error!!"<<endl;
- return;
- }
-
- if (InitProvisioning() == ES_ERROR)
- {
- cout<<"Init Provisioning Failed!!"<<endl;
- return;
- }
-
- pthread_t thread_handle;
- if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
- {
- cout<<"Thread creation failed"<<endl;
- }
-
- cout<<"InitProvisioning Success"<<endl;
-}
-
-void StopEasySetup()
-{
- cout<<"StopEasySetup IN"<<endl;
-
- if (TerminateEasySetup() == ES_ERROR)
- {
- cout<<"TerminateEasySetup Failed!!"<<endl;
- return;
- }
-
- //stop OC Stack
- if (OCStop() != OC_STACK_OK)
- {
- cout<<"OCStack stop failed!!"<<endl;
- return;
- }
-
- cout<<"StopEasySetup OUT"<<endl;
-}
-
-int main()
-{
- cout<<"#########################"<<endl;
- cout<<"EasySetup Enrollee SAMPLE"<<endl;
- cout<<"#########################"<<endl;
- PrintMenu();
- char option;
-
- while(true)
- {
- cin>>option;
- switch (option)
- {
- case 'H': // help
- case 'h':
- PrintMenu();
- break;
-
- case 'Q': // quit
- case 'q':
- cout<<"quit";
- break;
-
- case 'S': // Enable Security
- case 's':
- EnableSecurity();
- break;
-
- case 'I': // Init EasySetup
- case 'i':
- StartEasySetup();
- break;
-
- case 'P': // start provisioning
- case 'p':
- StartOICStackAndStartResources();
- break;
-
- case 'T': // stop easy setup
- case 't':
- StopEasySetup();
- break;
-
- default:
- cout<<"wrong option"<<endl;
- break;
- }
- if (option == 'Q' || option == 'q') break;
- }
- return 0;
-}
-
-void *listeningFunc(void*)
-{
- OCStackResult result;
-
- while (true)
- {
- result = OCProcess();
- if (result != OC_STACK_OK)
- {
- cout<<"OCStack stop error";
- }
- }
- return NULL;
-}
-