+#******************************************************************
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
=== Prerequisites ===
* 1. Scons
#******************************************************************
#
-# Copyright 2014 Samsung Electronics All Rights Reserved.
+# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
'../../resource/csdk/stack/include',
'../../extlibs/cjson',
'sdk/enrollee/arduino/wifi',
- 'sdk/enrollee/common/src',
- 'sdk/enrollee/common/inc'])
+ 'sdk/enrollee/api',
+ 'sdk/enrollee/src',
+ 'sdk/enrollee/inc'])
easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
if target_os in ['android','linux']:
easy_setup_env.PrependUnique(CPPPATH = [
if target_os == 'arduino':
es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary',
- ['sdk/enrollee/common/src/easysetup.cpp',
- 'sdk/enrollee/common/src/resourceHandler.cpp',
+ ['sdk/enrollee/src/easysetup.cpp',
+ 'sdk/enrollee/src/resourceHandler.cpp',
'sdk/enrollee/arduino/wifi/networkHandler.cpp'])
easy_setup_env.InstallTarget(es_sdk_static, 'libESSDK')
#******************************************************************
#
-# Copyright 2014 Samsung Electronics All Rights Reserved.
+# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
#******************************************************************
#
-# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
'../../../../../extlibs/cjson',
'../../../sdk/common',
'../../../sdk/enrollee/arduino/wifi',
- '../../../sdk/enrollee/common/inc',
- '../../../sdk/enrollee/common/src'
+ '../../../sdk/enrollee/api',
+ '../../../sdk/enrollee/inc',
+ '../../../sdk/enrollee/src'
])
enrollee_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
//******************************************************************
//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
OC_LOG_INIT();
OC_LOG(DEBUG, TAG, "OCServer is starting...");
- if(InitEasySetup(ES_WIFI, ssid, passwd, EventCallbackInApp) == ES_ERROR)
+ if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, EventCallbackInApp) == ES_ERROR)
{
OC_LOG(ERROR, TAG, "EasySetup Init Failed");
return;
}
- if(InitProvisioning(EventCallbackInApp)== ES_ERROR)
+ if(InitProvisioning()== ES_ERROR)
{
OC_LOG(ERROR, TAG, "Init Provisioning Failed");
return;
#******************************************************************
#
-# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
//******************************************************************
//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
--- /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 SDK APIs for device operating in Enrollee Mode of EasySetup
+ */
+
+#ifndef EASYSETUP_ENROLLEE_H__
+#define EASYSETUP_ENROLLEE_H__
+
+// Do not remove the include below
+#include "Arduino.h"
+#include "networkHandler.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/*
+ * Callback function for updating the Enrollee OnBoarding and Provisioning status result to the application
+ *
+ * @param esResult ESResult provides the current state of the Enrollee Device
+ */
+typedef void (*EventCallback)(ESResult esResult);
+
+/**
+ * This function Initializes the EasySetup. This API must be called prior to invoking any other API
+ *
+ * @param networkType NetworkType on which OnBoarding has to be performed.
+ * @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 eventCallback EventCallback for for updating the Enrollee OnBoarding and Provisioning status
+ * result to the application
+ * @return ::ES_OK on success, some other value upon failure.
+ */
+ESResult InitEasySetup(OCConnectivityType networkType, const char *ssid,
+ const char *passwd,
+ EventCallback eventCallback);
+
+/**
+ * This function performs initialization of Provisioning and Network resources needed for EasySetup process.
+ *
+ * @return ::ES_OK on success, some other value upon failure.
+ */
+ESResult InitProvisioning();
+
+/**
+ * This function performs termination of Provisioning and Network resources.
+ * Also terminates the IoTivity core stack.
+ *
+ * @return ::ES_OK on success, some other value upon failure.
+ */
+ESResult TerminateEasySetup();
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+
+#endif /* EASYSETUP_ENROLLEE_H__ */
+
//******************************************************************
//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
#include "networkHandler.h"
-#define TAG "ES_NH"
+// Arduino WiFi Shield includes
+#include <SPI.h>
+#include <WiFi.h>
+#include <WiFiUdp.h>
+#include <string.h>
+
+#include "logger.h"
+
+/**
+ * @var ES_NH_TAG
+ * @brief Logging tag for module name.
+ */
+#define ES_NH_TAG "ES_NH"
+
+//-----------------------------------------------------------------------------
+// Private variables
+//-----------------------------------------------------------------------------
+static IPAddress myIP;
+
+//-----------------------------------------------------------------------------
+// Private internal function prototypes
+//-----------------------------------------------------------------------------
int findNetwork(const char *ssid);
int ConnectToNetwork(const char *ssid, const char *pass);
void printEncryptionType(int thisType);
// Arduino WiFi Shield
// Note : Arduino WiFi Shield currently does NOT support multicast and therefore
// this server will NOT be listening on 224.0.1.187 multicast address.
-
static const char ARDUINO_WIFI_SHIELD_UDP_FW_VER[] = "1.1.0";
-IPAddress myIP;
-
ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
{
char *fwVersion;
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD)
{
- OC_LOG(ERROR, TAG, "WiFi shield not present");
+ OC_LOG(ERROR, ES_NH_TAG, "WiFi shield not present");
return ES_ERROR;
}
// Verify that WiFi Shield is running the firmware with all UDP fixes
fwVersion = WiFi.firmwareVersion();
- OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion);
+ OC_LOG_V(INFO, ES_NH_TAG, "WiFi Shield Firmware version %s", fwVersion);
if (strncmp(fwVersion, ARDUINO_WIFI_SHIELD_UDP_FW_VER, sizeof(ARDUINO_WIFI_SHIELD_UDP_FW_VER))
!= 0)
{
- OC_LOG(DEBUG, TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!");
+ OC_LOG(DEBUG, ES_NH_TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!");
//return ES_ERROR;
}
- OC_LOG_V(INFO, TAG, "Finding SSID: %s", ssid);
+ OC_LOG_V(INFO, ES_NH_TAG, "Finding SSID: %s", ssid);
while (findNetwork(ssid) == 0) // found
{
// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
- OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
+ OC_LOG_V(INFO, ES_NH_TAG, "Attempting to connect to SSID: %s", ssid);
status = WiFi.begin((char *) ssid, (char *) pass);
// wait 10 seconds for connection:
delay(10000);
}
- OC_LOG(DEBUG, TAG, "Connected to wifi");
+ OC_LOG(DEBUG, ES_NH_TAG, "Connected to wifi");
myIP = WiFi.localIP();
- OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
+ OC_LOG_V(INFO, ES_NH_TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
char buf[50];
sprintf(buf, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
return 0;
}
-int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info)
+ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
{
- if (targetType == ES_WIFI && WiFi.status() == WL_CONNECTED)
+ if (targetType == CT_ADAPTER_IP && WiFi.status() == WL_CONNECTED)
{
- info->type = ES_WIFI;
+ info->type = CT_ADAPTER_IP;
info->ipaddr = WiFi.localIP();
if(strlen(WiFi.SSID())<=MAXSSIDLEN)
- strcpy(info->ssid, WiFi.SSID());
- else return -1;
-
- return 0;
+ {
+ strcpy(info->ssid, WiFi.SSID());
+ return ES_OK;
+ }
+ else
+ {
+ return ES_ERROR;
+ }
}
- return -1;
+ return ES_ERROR;
}
void printEncryptionType(int thisType)
//******************************************************************
//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+/**
+ * @file
+ *
+ * This file contains IP network handling functionality for Enrollee device
+ */
+
+#ifndef ES_NETWORK_HANDLER_H_
+#define ES_NETWORK_HANDLER_H_
+
// Do not remove the include below
#include "Arduino.h"
-#include "logger.h"
-#include "ocstack.h"
-#include <string.h>
-
-// Arduino WiFi Shield
+// Arduino WiFi Shield includes
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
+#include <string.h>
+#include "logger.h"
#include "common.h"
-#ifndef ES_NETWORK_HANDLER_H_
-#define ES_NETWORK_HANDLER_H_
-
#define MAXSSIDLEN 33
#define MAXNETCREDLEN 20
#define MAXNUMTYPE 5
#define MAXADDRLEN 15
-typedef void (*NetworkEventCallback)(ESResult);
+/*
+ * Callback function for updating the Network status to the subscribers
+ *
+ * @param esResult ESResult provides the current state of the network connection status
+ */
+typedef void (*NetworkEventCallback)(ESResult esResult);
-enum NetworkType
+typedef struct
{
- ES_WIFI = 1, ES_BT = 2, ES_BLE = 3, ES_ZIGBEE = 4, ES_ETH = 5
-};
-
-typedef struct NETWORKINFO
-{
- NetworkType type;
-
+ OCConnectivityType type;
// for WiFI
IPAddress ipaddr;
char ssid[MAXSSIDLEN];
-
// for BT, BLE
byte mac[6];
} NetworkInfo;
ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback);
-int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info);
+ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info);
#endif
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2014 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 "Arduino.h"
-
-#include <string.h>
-#include "ocstack.h"
-#include "networkHandler.h"
-
-typedef void (*EventCallback)(ESResult);
-
-#ifdef ESWIFI
-ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,EventCallback cb);
-#endif
-
-#ifdef ESBLE
-ESResult InitEasySetup(NetworkType networkType,EventCallback cb);
-#endif
-
-ESResult InitProvisioning(EventCallback cb);
-ESResult TerminateEasySetup();
-
//******************************************************************
//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Do not remove the include below
#include "Arduino.h"
+#include <string.h>
#include "logger.h"
#include "ocstack.h"
-#include <string.h>
-
#include "common.h"
#include "networkHandler.h"
#include "octypes.h"
//******************************************************************
//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+/**
+ * @file
+ *
+ * This file contains the implementation for EasySetup Enrollee device
+ */
+
#include "easysetup.h"
#include "logger.h"
#include "resourceHandler.h"
-#define TAG "ES"
-
-int g_eventflag = 0;
-int g_cnt = 0;
-char *targetSsid;
-char *targetPass;
-
-EventCallback g_cbForProvisioning = NULL;
-EventCallback g_cbForOnboarding = NULL;
+/**
+ * @var ES_ENROLLEE_TAG
+ * @brief Logging tag for module name.
+ */
+#define ES_ENROLLEE_TAG "ES"
+
+//-----------------------------------------------------------------------------
+// Private variables
+//-----------------------------------------------------------------------------
+
+/**
+ * @var targetSsid
+ * @brief Target SSID of the Soft Access point to which the device has to connect
+ */
+static char *targetSsid;
+
+/**
+ * @var targetPass
+ * @brief Password of the target access point to which the device has to connect
+ */
+static char *targetPass;
+
+/**
+ * @var g_cbForEnrolleeStatus
+ * @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback
+ */
+static EventCallback g_cbForEnrolleeStatus = NULL;
+
+//-----------------------------------------------------------------------------
+// Private internal function prototypes
+//-----------------------------------------------------------------------------
void EventCallbackInOnboarding(ESResult event);
void EventCallbackInProvisioning(ESResult event);
{
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
- if (g_cbForOnboarding != NULL)
+ if (g_cbForEnrolleeStatus != NULL)
{
- g_cbForOnboarding(event);
+ g_cbForEnrolleeStatus(event);
}
}
}
if(TerminateEasySetup() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "Terminating stack failed");
+ OC_LOG(ERROR, ES_ENROLLEE_TAG, "Terminating stack failed");
return;
}
res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning);
- if (g_cbForProvisioning != NULL)
+ if (g_cbForEnrolleeStatus != NULL)
{
- g_cbForProvisioning(res);
+ g_cbForEnrolleeStatus(res);
}
}
}
{
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
- if (g_cbForProvisioning != NULL)
+ if (g_cbForEnrolleeStatus != NULL)
{
- g_cbForProvisioning(event);
+ g_cbForEnrolleeStatus(event);
}
}
}
-ESResult FindNetworkForOnboarding(NetworkType networkType,
+ESResult FindNetworkForOnboarding(OCConnectivityType networkType,
const char *ssid,
const char *passwd,
EventCallback cb)
return ES_ERROR;
}
- if (networkType == ES_WIFI)
+ if (networkType == CT_ADAPTER_IP)
{
- if (g_cbForOnboarding == NULL)
+ if (g_cbForEnrolleeStatus == NULL)
{
- g_cbForOnboarding = cb;
+ g_cbForEnrolleeStatus = cb;
}
if(ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding) != ES_NETWORKCONNECTED)
{
- OC_LOG(ERROR, TAG, "ConnectToWiFiNetwork Failed");
+ OC_LOG(ERROR, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Failed");
+ cb(ES_NETWORKNOTCONNECTED);
return ES_ERROR;
}
else{
- OC_LOG(INFO, TAG, "ConnectToWiFiNetwork Success");
+ OC_LOG(INFO, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Success");
+ cb(ES_NETWORKCONNECTED);
return ES_OK;
}
}
}
-ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,
+ESResult InitEasySetup(OCConnectivityType networkType, const char *ssid, const char *passwd,
EventCallback cb)
{
if(FindNetworkForOnboarding(networkType, ssid, passwd, cb) != ES_OK)
{
- OC_LOG(ERROR, TAG, "OnBoarding Failed");
+ OC_LOG(ERROR, ES_ENROLLEE_TAG, "OnBoarding Failed");
return ES_ERROR;
}
// Initialize the OC Stack in Server mode
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack init error");
+ OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack init error");
return ES_ERROR;
}
else
{
- OC_LOG(DEBUG, TAG, "OCStack init success");
+ OC_LOG(DEBUG, ES_ENROLLEE_TAG, "OCStack init success");
return ES_OK;
}
}
{
if(OCStop() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack stop failed");
+ OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack stop failed");
return ES_ERROR;
}
else
{
- OC_LOG(ERROR, TAG, "OCStack stop success");
+ OC_LOG(ERROR, ES_ENROLLEE_TAG, "OCStack stop success");
return ES_OK;
}
}
-ESResult InitProvisioning(EventCallback cb)
+ESResult InitProvisioning()
{
- if (cb == NULL)
- {
- return ES_ERROR;
- }
- else
- {
- g_cbForProvisioning = cb;
- }
-
if (CreateProvisioningResource() != OC_STACK_OK)
{
return ES_ERROR;
//******************************************************************
//
-// Copyright 2014 Samsung Electronics All Rights Reserved.
+// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
#include "resourceHandler.h"
#include "ocpayload.h"
-#define TAG "ES_RH"
-
-ProvResource g_prov;
-NetResource g_net;
-
+/**
+ * @var ES_RH_TAG
+ * @brief Logging tag for module name.
+ */
+#define ES_RH_TAG "ES_RH"
+
+//-----------------------------------------------------------------------------
+// Private variables
+//-----------------------------------------------------------------------------
+
+/**
+ * @var g_prov
+ * @brief Structure for holding the Provisioning status and target information required to connect to the target network
+ */
+static ProvResource g_prov;
+
+/**
+ * @var g_net
+ * @brief Structure forr holding the Provisioning status of network information
+ */
+static NetResource g_net;
+
+//-----------------------------------------------------------------------------
+// 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);
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
+ OCRepPayload** payload);
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
+ OCRepPayload** payload);
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
+ OCRepPayload** payload);
OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest);
int g_flag = 0;
OCStackResult CreateProvisioningResource()
{
g_prov.ps = 1; // need to provisioning
- g_prov.tnt = ES_WIFI;
+ g_prov.tnt = CT_ADAPTER_IP;
sprintf(g_prov.tnn, "Unknown");
sprintf(g_prov.cd, "Unknown");
OCStackResult res = OCCreateResource(&g_prov.handle, "oic.r.prov", OC_RSRVD_INTERFACE_DEFAULT,
OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb, NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
- OC_LOG_V(INFO, TAG, "Created Prov resource with result: %s", getResult(res));
+ OC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
return res;
}
{
NetworkInfo netInfo;
- if (getCurrentNetworkInfo(ES_WIFI, &netInfo) != 0)
+ if (getCurrentNetworkInfo(CT_ADAPTER_IP, &netInfo) != ES_OK)
{
return OC_STACK_ERROR;
}
- if (netInfo.type != ES_WIFI)
+ if (netInfo.type != CT_ADAPTER_IP)
{
return OC_STACK_ERROR;
}
g_net.cnt = (int) netInfo.type;
- g_net.ant[0] = (int) ES_WIFI;
+ g_net.ant[0] = (int) CT_ADAPTER_IP;
sprintf(g_net.ipaddr, "%d.%d.%d.%d", netInfo.ipaddr[0], netInfo.ipaddr[1], netInfo.ipaddr[2],
netInfo.ipaddr[3]);
sprintf(g_net.cnn, "%s", netInfo.ssid);
- OC_LOG_V(INFO, TAG, "SSID: %s", g_net.cnn);
- OC_LOG_V(INFO, TAG, "IP Address: %s", g_net.ipaddr);
+ OC_LOG_V(INFO, ES_RH_TAG, "SSID: %s", g_net.cnn);
+ OC_LOG_V(INFO, ES_RH_TAG, "IP Address: %s", g_net.ipaddr);
OCStackResult res = OCCreateResource(&g_net.handle, "oic.r.net", OC_RSRVD_INTERFACE_DEFAULT,
OC_RSRVD_ES_URI_NET, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
- OC_LOG_V(INFO, TAG, "Created Net resource with result: %s", getResult(res));
+ OC_LOG_V(INFO, ES_RH_TAG, "Created Net resource with result: %s", getResult(res));
return res;
}
#endif
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
+ OCRepPayload **payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (!ehRequest)
{
- OC_LOG(ERROR, TAG, "Request is Null");
+ OC_LOG(ERROR, ES_RH_TAG, "Request is Null");
return ehResult;
}
if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
- OC_LOG(ERROR, TAG, "Incoming payload not a representation");
+ OC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
return ehResult;
}
OCRepPayload *getResp = constructResponse(ehRequest);
if (!getResp)
{
- OC_LOG(ERROR, TAG, "constructResponse failed");
+ OC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
return OC_EH_ERROR;
}
return ehResult;
}
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
+ OCRepPayload** payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
- OC_LOG(ERROR, TAG, "Incoming payload not a representation");
+ OC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
return ehResult;
}
OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
if (!input)
{
- OC_LOG(ERROR, TAG, "Failed to parse");
+ OC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
return ehResult;
}
OCRepPayload *getResp = constructResponse(ehRequest);
if (!getResp)
{
- OC_LOG(ERROR, TAG, "constructResponse failed");
+ OC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
return OC_EH_ERROR;
}
return ehResult;
}
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
+ OCRepPayload** payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (!ehRequest)
{
- OC_LOG(ERROR, TAG, "Request is Null");
+ OC_LOG(ERROR, ES_RH_TAG, "Request is Null");
return ehResult;
}
if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
- OC_LOG(ERROR, TAG, "Incoming payload not a representation");
+ OC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
return ehResult;
}
OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
if (!input)
{
- OC_LOG(ERROR, TAG, "Failed to parse");
+ OC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
return ehResult;
}
char* tr;
OCRepPayload* payload = OCRepPayloadCreate();
if (!payload)
{
- OC_LOG(ERROR, TAG, "Failed to allocate Payload");
+ OC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
return NULL;
}
{
if (OC_REST_GET == entityHandlerRequest->method)
{
- OC_LOG(INFO, TAG, "Received GET request");
+ OC_LOG(INFO, ES_RH_TAG, "Received GET request");
ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
}
else if (OC_REST_PUT == entityHandlerRequest->method)
{
- OC_LOG(INFO, TAG, "Received PUT request");
+ OC_LOG(INFO, ES_RH_TAG, "Received PUT request");
if (g_prov.handle != NULL && entityHandlerRequest->resource == g_prov.handle)
{
else if (OC_REST_POST == entityHandlerRequest->method)
{
// TODO: As of now, POST request will be not received.
- OC_LOG(INFO, TAG, "Received OC_REST_POST from client");
+ OC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
//ehRet = ProcessPostRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
}
// Send the response
if (OCDoResponse(&response) != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "Error sending response");
+ OC_LOG(ERROR, ES_RH_TAG, "Error sending response");
ehRet = OC_EH_ERROR;
}
}