Commit db420230 authored by Jihun Ha's avatar Jihun Ha Committed by Madan Lanka

Fix an faulty logic in resource handler and clean up useless codes

1. In resourcehandler, a logic of encoding array type's property is fixed.
2. Remove a useless logic to send a GET request before a POST request for
   update of WiFi and devConf properties in EnroleeResource
3. Change country property's key --> ctry
4. Clean up old structure and enum variable not used anymore.
5. Remove a csdk for mediator which is not used anymore

Change-Id: I7502e6b33860db1bcc91a67829ac9411ff9cae6d
Signed-off-by: default avatarJihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9241Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent 5785ad24
......@@ -224,7 +224,7 @@ ESResult ESSetState(ESEnrolleeState esState)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState IN");
if(esState <= 0 || esState >= 6)
if(esState < ES_STATE_INIT || esState > ES_STATE_REGISTRRED_FAIL_TO_CLOUD)
{
OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESEnrolleeState : %d", esState);
return ES_ERROR;
......@@ -232,10 +232,11 @@ ESResult ESSetState(ESEnrolleeState esState)
if(SetEnrolleeState(esState) != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetState Error");
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetState ES_ERROR");
return ES_ERROR;
}
OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "Set ESState succesfully : %d", esState);
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState OUT");
return ES_OK;
}
......@@ -244,21 +245,19 @@ ESResult ESSetErrorCode(ESErrorCode esErrCode)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode IN");
if(esErrCode <= 0 || esErrCode >= 7)
if(esErrCode < ES_ERRCODE_NO_ERROR || esErrCode > ES_ERRCODE_UNKNOWN)
{
if(esErrCode != 999)
{
OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESErrorCode : %d", esErrCode);
OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESSetErrorCode : %d", esErrCode);
return ES_ERROR;
}
}
if(SetEnrolleeErrCode(esErrCode) != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetErrorCode Error");
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetErrorCode ES_ERROR");
return ES_ERROR;
}
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Set ESErrorCode succesfully : %d", esErrCode);
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode OUT");
return ES_OK;
}
......
......@@ -126,9 +126,8 @@ void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
OCStackResult initProvResource(bool isSecured)
{
gProvResource.status = NO_PROVISION;
gProvResource.trigger = false;
gProvResource.lastErrCode = ES_ERRCODE_NONE;
gProvResource.status = ES_STATE_INIT;
gProvResource.lastErrCode = ES_ERRCODE_NO_ERROR;
OICStrcpy(gProvResource.errorMessage, MAX_ERRMSGLEN, "");
OICStrcpy(gProvResource.ocfWebLinks, MAX_WEBLINKLEN, "");
......@@ -369,7 +368,7 @@ void updateCloudResource(OCRepPayload* input)
void updateDevConfResource(OCRepPayload* input)
{
char *country = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &country))
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_COUNTRY, &country))
{
OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
OICStrcpy(gDevConfData.country, sizeof(gDevConfData.country), country);
......@@ -377,7 +376,7 @@ void updateDevConfResource(OCRepPayload* input)
}
char *language = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &language))
if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LANGUAGE, &language))
{
OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
OICStrcpy(gDevConfData.language, sizeof(gDevConfData.language), language);
......@@ -413,7 +412,10 @@ OCRepPayload* constructResponseOfWiFi()
OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)gWiFiResource.supportedMode, dimensions);
int64_t *modes_64 = (int64_t *)malloc(gWiFiResource.numMode * sizeof(int64_t));
for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
modes_64[i] = gWiFiResource.supportedMode[i];
OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
......@@ -421,8 +423,6 @@ OCRepPayload* constructResponseOfWiFi()
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
printf("%s\n", gWiFiResource.ssid);
return payload;
}
......@@ -474,9 +474,7 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
OCRepPayloadSetPropBool(payload, OC_RSRVD_ES_TRIGGER, gProvResource.trigger);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_ERRORMESSAGE, gProvResource.errorMessage);
OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LINKS, gProvResource.ocfWebLinks);
if(ehRequest->query)
......@@ -675,6 +673,10 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
return ehResult;
}
// TBD : Discuss about triggering flag (to be existed or not)
// ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
// A new request for provisioning means overriding existing network provisioning information.
if(ehRequest->resource == gProvResource.handle)
updateProvResource(ehRequest, input);
else if(ehRequest->resource == gWiFiResource.handle)
......@@ -682,33 +684,7 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
else if(ehRequest->resource == gCloudResource.handle)
updateCloudResource(input);
else if(ehRequest->resource == gDevConfResource.handle)
updateDevConfResource(input);
// TBD : Discuss about triggering flag (to be existed or not)
// ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
// A new request for provisioning means overriding existing network provisioning information.
// if (gProvResource.trigger)
// {
// 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
// {
// OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
// }
updateDevConfResource(input);
OCRepPayload *getResp = NULL;
if(ehRequest->resource == gProvResource.handle)
......@@ -720,9 +696,6 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
else if(ehRequest->resource == gDevConfResource.handle)
getResp = constructResponseOfDevConf();
if (gProvResource.trigger)// Trigger false should be restored after executed
gProvResource.trigger = false;
if (!getResp)
{
OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
......
......@@ -42,7 +42,6 @@ typedef struct PROVRESOURCE
{
OCResourceHandle handle;
ProvStatus status; // provisiong status
bool trigger; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
ESErrorCode lastErrCode;
char errorMessage[MAX_ERRMSGLEN];
char ocfWebLinks[MAX_WEBLINKLEN];
......
......@@ -24,6 +24,11 @@
#include "ocstack.h"
#include "octypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
// Defines
#define OIC_STRING_MAX_VALUE 100
#define IPV4_ADDR_SIZE 16
......@@ -39,9 +44,7 @@
*/
#define OC_RSRVD_ES_PROVSTATUS "ps"
#define OC_RSRVD_ES_LAST_ERRORCODE "lec"
#define OC_RSRVD_ES_ERRORMESSAGE "em"
#define OC_RSRVD_ES_LINKS "links"
#define OC_RSRVD_ES_TRIGGER "tr"
#define OC_RSRVD_ES_SUPPORTEDWIFIMODE "swmt"
#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ "swf"
#define OC_RSRVD_ES_SSID "tnn"
......@@ -53,7 +56,7 @@
#define OC_RSRVD_ES_CISERVER "cisurl"
#define OC_RSRVD_ES_DEVNAME "dn"
#define OC_RSRVD_ES_LANGUAGE "lang"
#define OC_RSRVD_ES_COUNTRY "cont"
#define OC_RSRVD_ES_COUNTRY "ctry"
/**
* Easysetup defined resoruce types and uris.
......@@ -68,19 +71,12 @@
#define OC_RSRVD_ES_URI_DEVCONF "/.well-known/ocf/prov/devconf"
#define NUM_WIFIMODE 10
#define MAX_SSIDLEN 33
#define MAX_CREDLEN 20
#define MAX_SSIDLEN 33
#define MAX_CREDLEN 20
#define MAX_DEVICELEN 100
#define MAX_ERRMSGLEN 100
#define MAX_WEBLINKLEN 100
typedef enum
{
NO_PROVISION = 0,
CONNECTED_ENROLLER,
FAILED_CONNECTION
} PROV_STATUS;
#define MAX_DEVICELEN 100
#define MAX_ERRMSGLEN 100
#define MAX_WEBLINKLEN 100
typedef enum
{
......@@ -117,25 +113,6 @@ typedef enum
TKIP_AES
} WIFI_ENCTYPE;
/**
* Device Roles defined for each device type used in easy setup
*/
typedef enum
{
ENROLLEE,
MEDIATOR,
ENROLLER,
} DeviceRole;
/**
* On-boarding connection to create Adhoc network.
*/
typedef enum
{
SOFTAP,
BLE,
} OBConnection;
typedef enum
{
ES_ERROR = -1,
......@@ -197,7 +174,7 @@ typedef enum
/**
* Default state of the device
*/
ES_STATE_INIT = 1,
ES_STATE_INIT = 0,
/**
* Status indicating successful cnnection to target network
......@@ -218,14 +195,19 @@ typedef enum
* Status indicating failure registeration to cloud
*/
ES_STATE_REGISTRRED_FAIL_TO_CLOUD
} ESEnrolleeState;
} ESEnrolleeState, ProvStatus;
typedef enum
{
/**
* Init Error Code
*/
ES_ERRCODE_NO_ERROR = 0,
/**
* Error Code that given WiFi's SSID is not found
*/
ES_ERRCODE_SSID_NOT_FOUND = 1,
ES_ERRCODE_SSID_NOT_FOUND,
/**
* Error Code that given WiFi's Password is wrong
......@@ -250,111 +232,11 @@ typedef enum
/**
* Error Code that Unknown error occured
*/
ES_ERRCODE_UNKNOWN,
/**
* No Error Occured
*/
ES_ERRCODE_NONE = 999
ES_ERRCODE_UNKNOWN
} ESErrorCode;
typedef struct
{
// Address of remote server
OCDevAddr * addr;
// Indicates adaptor type on which the response was received
OCConnectivityType connType;
} EasySetupDeviceInfo;
/**
* Provosioning Status
*/
typedef enum
{
ES_NEED_PROVISION = 1,
ES_CONNECTED_TO_ENROLLER,
ES_CONNECTED_FAIL_TO_ENROLLER,
ES_REGISTERED_TO_CLOUD,
ES_REGISTERED_FAIL_TO_CLOUD
} EasySetupState, ProvStatus;
/**
* Response from queries to remote servers.
*/
typedef struct
{
// EasySetup Status
EasySetupState provStatus;
// EasySetup Device Info
EasySetupDeviceInfo provDeviceInfo;
} EasySetupInfo, ProvisioningInfo;
/**
* @brief Network information of the Enroller
*/
typedef union
{
/**
* @brief BT Mac Information
*/
struct
{
char btMacAddress[NET_MACADDR_SIZE]; /**< BT mac address **/
} BT;
/**
* @brief LE MAC Information
*/
struct
{
char leMacAddress[NET_MACADDR_SIZE]; /**< BLE mac address **/
} LE;
/**
* @brief IP Information
*/
struct
{
char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
} WIFI;
} ProvData;
/**
* @brief Network Information
*/
typedef struct
{
ProvData provData; /**< Enroller Network Info**/
OCConnectivityType connType; /**< Connectivity Type**/
} ProvConfig;
/**
* Client applications implement this callback to consume responses received from Servers.
*/
typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
/**
* @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
*/
// Note : Below structure is not currently used but added for future purpose.
typedef struct {
char ssid[MAX_SSIDLEN]; /**< ssid of the onboarding Adhoc Wifi network**/
char pwd[MAX_CREDLEN]; /**< pwd of the onboarding Adhoc wifi network**/
bool isSecured; /**< Secure connection**/
}WiFiOnboardingConfig;
/**
* @brief This structure represent onboarding connection instance.
*/
typedef struct {
/*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
device identification should be based on DeviceID in next release.*/
char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
bool isSecured; /**< Secure connection**/
}WiFiOnboadingConnection;
#ifdef __cplusplus
}
#endif
#endif //ES_COMMON_H_
......@@ -25,9 +25,6 @@ Import('env')
target_os = env.get('TARGET_OS')
# Build easy-setup Mediator C SDK
#SConscript('csdk/SConscript')
# Build easy-setup Mediator Rich [C++] SDK
SConscript('richsdk/SConscript')
......
//******************************************************************
//
// 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 __ES_PROVISIONING_HANDLER_H_
#define __ES_PROVISIONING_HANDLER_H_
#include "octypes.h"
#include "logger.h"
#include "ocstack.h"
#include "escommon.h"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#define EASY_SETUP_DEFAULT_CONTEXT_VALUE 0x99
/**
* List of methods that can be inititated from the client
*/
OCStackResult InitProvisioningHandler();
OCStackResult TerminateProvisioningHandler();
OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
const OCDevAddr *destination);
OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,
WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback,
char *findResQuery);
void StopProvisioningProcess();
/**
* Internal worker functions.
*/
OCStackResult TriggerNetworkConnection(OCQualityOfService qos, const char *query,
const char *resUri, OCDevAddr *destination, int /*pauseBeforeStart*/);
OCStackApplicationResult TriggerNetworkConnectionResponse(void *ctx, OCDoHandle handle,
OCClientResponse *clientResponse);
OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle,
OCClientResponse *clientResponse);
OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri,
OCDevAddr *destination, int pauseBeforeStart);
OCStackApplicationResult GetProvisioningStatusResponse(void *ctx, OCDoHandle handle,
OCClientResponse *clientResponse);
OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDevAddr *dest,
OCQualityOfService qos, OCClientResponseHandler cb, OCRepPayload *payload,
OCHeaderOption *options, uint8_t numOptions);
OCStackApplicationResult FindProvisioningResourceResponse(void *ctx, OCDoHandle handle,
OCClientResponse *clientResponse);
void *FindProvisioningResource(void *data);
ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
ProvStatus provStatus);
/**
* Internal Util functions.
*/
void LogProvisioningResponse(OCRepPayloadValue * val);
bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn);
bool ClearMemory();
void SuccessCallback(OCClientResponse * clientResponse);
void ErrorCallback(ProvStatus status);
bool ValidateEnrolleeResponse(OCClientResponse * clientResponse);
bool ValidateFindResourceResponse(OCClientResponse * clientResponse);
bool ValidateEnrolleeBasicResponse(OCClientResponse * clientResponse);
ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse,
ProvStatus provStatus);
ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status);
ProvisioningInfo *CreateCallBackObject();
bool ResetProgress();
bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback);
bool InProgress();
bool ValidateEasySetupParams(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn,
OCProvisioningStatusCB provisioningStatusCallback);
bool IsSetupStopped();
#endif //__ES_PROVISIONING_HANDLER_H_
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef __EASYSETUP_MGR_H_
#define __EASYSETUP_MGR_H_
#include <string.h>
#include "logger.h"
#include "ocstack.h"
#include "octypes.h"
#include "escommon.h"
#include "provisioning.h"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#ifdef __cplusplus
extern "C"
{
#endif
OCStackResult InitProvProcess();
OCStackResult ResetProvProcess();
OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback);
void UnRegisterCallback();
OCStackResult StartProvisioning(const ProvConfig *netInfo,
WiFiOnboadingConnection *onboardConn);
OCStackResult StopProvisioning(OCConnectivityType connectivityType);
#ifdef __cplusplus
}
#endif
#endif
//******************************************************************
//
// 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 "provisioning.h"
//Standard includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
//EasySetup include files
#include "ocpayload.h"
#include "escommon.h"
// External includes
#include "logger.h"
#include "oic_malloc.h"
#include "oic_string.h"
#define ES_PROV_TAG "EASY_SETUP_PROVISIONING"
bool gProvisioningCondFlag = false;
static ProvConfig *gProvConfig;
static WiFiOnboadingConnection *gOnboardConn;
static char gSzFindResourceQueryUri[64] =
{ 0 };
/**
* @var cbData
* @brief Callback for providing provisioning status callback to application
*/
static OCProvisioningStatusCB cbData = NULL;