Commit dbe5deab authored by sy01.youn's avatar sy01.youn Committed by Madan Lanka

[Enrollee] Implement ESSetDeviceProperty() API

1. Add new data structure & change the name and value of some variables
  . ESDefaultProperty Data Structure is added
  . ESEnrolleeState value is changed (as spec. specified)

2. ESSetDeviceProperty() API is added in easysetup.c

3. Enrollee Sample App. is changed
  . linux based enrollee sample app is changed
   : can test ESInitEnrollee() & ESSetDeviceProperty() API

Change-Id: I57b65bae47fa8b34739e42f8265707b8980c4e31
Signed-off-by: default avatarsy01.youn <sy01.youn@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8961Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent b786f86f
......@@ -55,7 +55,7 @@ typedef struct
* This function Initializes the EasySetup. This API must be called prior to invoking any other API
*
* @param isSecured True if the Enrollee is operating in secured mode.
* @param resourceMask Provisining Resource Type which application wants to make
* @param resourceMask Provisining Resource Type which application wants to make.
* ES_WIFI_RESOURCE = 0x01,
* ES_CLOUD_RESOURCE = 0x02,
* ES_DEVCONF_RESOURCE = 0x04
......@@ -65,6 +65,14 @@ typedef struct
ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvisioningCallbacks callbacks);
/**
* This function Sets Device Information.
*
* @param deviceProperty Contains device information composed of WiFi Structure & DevConf Structure
* @return ::ES_OK on success, some other value upon failure.
*/
ESResult ESSetDeviceProperty(ESDeviceProperty *deviceProperty);
/**
* This function performs termination of Provisioning and Network resources.
* Also terminates the IoTivity core stack.
......
......@@ -27,7 +27,7 @@
#include "easysetup.h"
#include "logger.h"
#include "resourcehandler.h"
#include "easysetupcallbacks.h"
#include "oic_string.h"
/**
* @var ES_ENROLLEE_TAG
......@@ -38,9 +38,33 @@
//-----------------------------------------------------------------------------
// 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 ESEnrolleeEventCallback gEnrolleeStatusCb = NULL;
/**
* @var gIsSecured
* @brief Variable to check if secure mode is enabled or not.
*/
static bool gIsSecured = false;
static ESProvisioningCallbacks gESProvisioningCb;
static ESDeviceProperty gESDeviceProperty;
void ESWiFiRsrcCallback(ESResult esResult, ESWiFiProvData *eventData)
{
......@@ -163,6 +187,33 @@ ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvision
return ES_OK;
}
ESResult ESSetDeviceProperty(ESDeviceProperty *deviceProperty)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetDeviceProperty IN");
if(SetDeviceProperty(deviceProperty) != OC_STACK_OK)
{
return ES_ERROR;
}
int modeIdx = 0;
while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
{
(gESDeviceProperty.WiFi).mode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "WiFi Mode : %d", (gESDeviceProperty.WiFi).mode[modeIdx]);
modeIdx ++;
}
(gESDeviceProperty.WiFi).freq = (deviceProperty->WiFi).freq;
OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "WiFi Freq : %d", (gESDeviceProperty.WiFi).freq);
OICStrcpy((gESDeviceProperty.DevConf).deviceName, MAX_DEVICELEN, (deviceProperty->DevConf).deviceName);
OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "Device Name : %s", (gESDeviceProperty.DevConf).deviceName);
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetDeviceProperty OUT");
return ES_OK;
}
ESResult ESTerminateEnrollee()
{
UnRegisterResourceEventCallBack();
......@@ -177,15 +228,3 @@ ESResult ESTerminateEnrollee()
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESTerminateEnrollee success");
return ES_OK;
}
static bool ESEnrolleeValidateParam(OCConnectivityType networkType, const char *ssid,
const char *passwd, ESEnrolleeEventCallback cb)
{
if (!ssid || !passwd || !cb)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESEnrolleeValidateParam - Invalid parameters");
return false;
}
return true;
}
......@@ -119,8 +119,8 @@ void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
{
if (name != NULL && pass != NULL)
{
OICStrcpy(name, MAXSSIDLEN, gWiFiResource.ssid);
OICStrcpy(pass, MAXNETCREDLEN, gWiFiResource.cred);
OICStrcpy(name, MAX_SSIDLEN, gWiFiResource.ssid);
OICStrcpy(pass, MAX_CREDLEN, gWiFiResource.cred);
}
}
......@@ -128,6 +128,9 @@ OCStackResult initProvResource(bool isSecured)
{
gProvResource.status = NO_PROVISION;
gProvResource.trigger = false;
gProvResource.lastErrCode = ES_ERRCODE_NONE;
OICStrcpy(gProvResource.errorMessage, MAX_ERRMSGLEN, "");
OICStrcpy(gProvResource.ocfWebLinks, MAX_WEBLINKLEN, "");
OCStackResult res = OC_STACK_ERROR;
if (isSecured)
......@@ -256,7 +259,7 @@ OCStackResult initDevConfResource(bool isSecured)
void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
{
OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %lld", gProvResource.status);
OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %d", gProvResource.status);
if(ehRequest->query)
{
......@@ -472,6 +475,9 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
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)
{
......@@ -826,6 +832,29 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
return ehRet;
}
OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
{
OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty IN");
gWiFiResource.supportedFreq = (deviceProperty->WiFi).freq;
OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Freq : %d", gWiFiResource.supportedFreq);
int modeIdx = 0;
while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
{
gWiFiResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Mode : %d", gWiFiResource.supportedMode[modeIdx]);
modeIdx ++;
}
gWiFiResource.numMode = modeIdx;
OICStrcpy(gDevConfResource.devName, MAX_DEVICELEN, (deviceProperty->DevConf).deviceName);
OIC_LOG_V(INFO, ES_RH_TAG, "Device Name : %s", gDevConfResource.devName);
OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty OUT");
return OC_EH_OK;
}
const char *getResult(OCStackResult result)
{
switch (result)
......
......@@ -41,19 +41,21 @@ typedef void (*ESDevConfCB) (ESResult, ESDevConfProvData *);
typedef struct PROVRESOURCE
{
OCResourceHandle handle;
int64_t status; // provisiong status, 1 : need to provisioning, 2 : Connected to Enroller.
ProvStatus status; // provisiong status
bool trigger; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
int64_t errorCode;
ESLastErrCode lastErrCode;
char errorMessage[MAX_ERRMSGLEN];
char ocfWebLinks[MAX_WEBLINKLEN];
} ProvResource;
typedef struct
{
OCResourceHandle handle;
WIFI_MODE supportedMode[NUM_WIFIMODE];
uint8_t numMode;
uint8_t numMode; // the number of device's supported wifi modes
WIFI_FREQ supportedFreq;
char ssid[MAXSSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
char cred[MAXNETCREDLEN]; // credential information.
char ssid[MAX_SSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
char cred[MAX_CREDLEN]; // credential information.
WIFI_AUTHTYPE authType;
WIFI_ENCTYPE encType;
} WiFiResource;
......@@ -69,7 +71,7 @@ typedef struct
typedef struct
{
OCResourceHandle handle;
char devName[OIC_STRING_MAX_VALUE];
char devName[MAX_DEVICELEN];
char language[OIC_STRING_MAX_VALUE];
char country[OIC_STRING_MAX_VALUE];
} DevConfResource;
......@@ -78,6 +80,8 @@ typedef struct
OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask);
OCStackResult DeleteEasySetupResources();
OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty);
void GetTargetNetworkInfoFromProvResource(char *, char *);
void RegisterWifiRsrcEventCallBack(ESWiFiCB);
......
......@@ -28,8 +28,6 @@
#define OIC_STRING_MAX_VALUE 100
#define IPV4_ADDR_SIZE 16
#define IP_PORT 55555
#define NET_WIFI_SSID_SIZE 100
#define NET_WIFI_PWD_SIZE 100
/**
* @brief Mac address length for BT port
......@@ -40,7 +38,9 @@
* Attributes used to form a proper easysetup conforming JSON message.
*/
#define OC_RSRVD_ES_PROVSTATUS "ps"
#define OC_RSRVD_ES_ERRORCODE "ec"
#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"
......@@ -67,11 +67,13 @@
#define OC_RSRVD_ES_RES_TYPE_DEVCONF "ocf.r.devconf"
#define OC_RSRVD_ES_URI_DEVCONF "/.well-known/ocf/prov/devconf"
#define OC_RSRVD_ES_URI_NET "/oic/net"
#define NUM_WIFIMODE 10
#define MAXSSIDLEN 33
#define MAXNETCREDLEN 20
#define MAX_SSIDLEN 33
#define MAX_CREDLEN 20
#define MAX_DEVICELEN 100
#define MAX_ERRMSGLEN 100
#define MAX_WEBLINKLEN 100
typedef enum
{
......@@ -86,7 +88,8 @@ typedef enum
WiFi_11B,
WiFi_11G,
WiFi_11N,
WiFi_11AC
WiFi_11AC,
WiFi_EOF = 999,
} WIFI_MODE;
typedef enum
......@@ -145,6 +148,7 @@ typedef enum
ES_RECVREQOFNETRES,
ES_RECVUPDATEOFPROVRES,
ES_RECVTRIGGEROFPROVRES,
ES_UNAUTHORIZED = 31
} ESResult;
typedef enum
......@@ -156,8 +160,8 @@ typedef enum
typedef struct
{
char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
} ESWiFiProvData;
......@@ -175,62 +179,85 @@ typedef struct
char ciServer[OIC_STRING_MAX_VALUE];
} ESCloudProvData;
typedef struct
{
struct
{
WIFI_MODE mode[NUM_WIFIMODE];
WIFI_FREQ freq;
} WiFi;
struct
{
char deviceName[MAX_DEVICELEN];
} DevConf;
} ESDeviceProperty;
// TODO : Need to be erased
typedef enum
{
/**
* Default state of the device
*/
ES_INIT_STATE,
ES_STATE_INIT = 1,
/**
* Device will move to this state once the on boarding begins
*/
ES_ON_BOARDING_STATE,
* Status indicating successful cnnection to target network
*/
ES_STATE_CONNECTED_TO_ENROLLER,
/**
* Device will move to this state after successful on-boarding of the device
*/
ES_ON_BOARDED_STATE,
* Status indicating failure connection to target network
*/
ES_STATE_CONNECTED_FAIL_TO_ENROLLER,
/**
* Device will move to this state once the on boarding is done
*/
ES_PROVISIONING_STATE,
* Status indicating successful registration to cloud
*/
ES_STATE_REGISTERED_TO_CLOUD,
/**
* Easy setup process is successful.
*/
ES_PROVISIONED_STATE,
* Status indicating failure registeration to cloud
*/
ES_STATE_REGISTRRED_FAIL_TO_CLOUD
} ESEnrolleeState;
typedef enum
{
/**
* Error Code that given WiFi's SSID is not found
*/
ES_ERRCODE_SSID_NOTFOUND = 1,
/**
* This state is arbitrary one, any time device can come into this state
* Device will move to this state if the ownership transfer initiated by the Application
*/
ES_OWNERSHIP_TRANSFERRING_STATE,
* Error Code that given WiFi's Password is wrong
*/
ES_ERRCODE_PW_WRONG,
/**
* This state is arbitrary one, any time device can come into this state
* Device will move to this state if the ownership transfer is completed
*/
ES_OWNERSHIP_TRANSFERRED_STATE,
* Error Code that IP address is not allocated
*/
ES_ERRCODE_IP_NOTALLOCATED,
/**
* This state is arbitrary one, any time device can come into this state
* Device will move to this state once the Application factory reset the device
*/
ES_FACTORY_RESET_STATE,
* Error Code that there is no Internet connection
*/
ES_ERRCODE_NO_INTERNETCONNECTION,
/**
* Enrollee moves to this state after connecting to target network
*/
ES_ON_BOARDED_TARGET_NETWORK_STATE,
}ESEnrolleeState;
* Error Code that Timeout occured
*/
ES_ERRCODE_TIMEOUT,
/**
* Error Code that Unknown error occured
*/
ES_ERRCODE_UNKNOWN,
/**
* No Error Occured
*/
ES_ERRCODE_NONE = 999
} ESLastErrCode;
/**
* Provisioning Device Status
*/
typedef struct
{
// Address of remote server
......@@ -244,10 +271,11 @@ typedef struct
*/
typedef enum
{
DEVICE_PROVISIONED = 0,
DEVICE_NOT_PROVISIONED,
DEVICE_OWNED,
DEVICE_NOT_OWNED
ES_NEED_PROVISION = 1,
ES_CONNECTED_TO_ENROLLER,
ES_CONNECTED_FAIL_TO_ENROLLER,
ES_REGISTERED_TO_CLOUD,
ES_REGISTERED_FAIL_TO_CLOUD
} EasySetupState, ProvStatus;
/**
......@@ -287,8 +315,8 @@ typedef union
*/
struct
{
char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
} WIFI;
} ProvData;
......@@ -313,8 +341,8 @@ typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
// Note : Below structure is not currently used but added for future purpose.
typedef struct {
char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/
char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the onboarding Adhoc wifi network**/
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;
......
......@@ -25,6 +25,7 @@
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <oic_string.h>
#define TAG "ENROLLEE_SAMPLE"
......@@ -106,8 +107,6 @@ void WiFiProvCbInApp(ESWiFiProvData *eventData)
}
printf("WiFiProvCbInApp OUT\n");
PrintMenu();
}
void DevConfProvCbInApp(ESDevConfProvData *eventData)
......@@ -135,8 +134,6 @@ void DevConfProvCbInApp(ESDevConfProvData *eventData)
}
printf("DevConfProvCbInApp OUT\n");
PrintMenu();
}
void CloudDataProvCbInApp(ESCloudProvData *eventData)
......@@ -174,8 +171,6 @@ void CloudDataProvCbInApp(ESCloudProvData *eventData)
}
printf("CloudDataProvCbInApp OUT\n");
PrintMenu();
}
ESProvisioningCallbacks gCallbacks = {
......@@ -228,6 +223,20 @@ void StartEasySetup()
printf("StartEasySetup OUT\n");
}
void SetDeviceInfo()
{
printf("SetDeviceInfo IN\n");
ESDeviceProperty deviceProperty = {
{{WiFi_11G, WiFi_11N, WiFi_11AC, WiFi_EOF}, WiFi_5G}, {"Test Device"}
} ;
if(ESSetDeviceProperty(&deviceProperty) == ES_ERROR)
printf("ESSetDeviceProperty Error\n");
printf("SetDeviceInfo OUT\n");
}
void StopEasySetup()
{
printf("StopEasySetup IN\n");
......@@ -254,7 +263,7 @@ int main()
printf("EasySetup Enrollee SAMPLE\n");
printf("#########################\n");
PrintMenu();
char option = 'T';
char option;
while(true)
{
......@@ -281,24 +290,29 @@ int main()
case 'S': // Enable Security
case 's':
EnableSecurity();
PrintMenu();
break;
case 'I': // Init EasySetup
case 'i':
StartEasySetup();
PrintMenu();
break;
case 'D': // Set Device Info
case 'd':
// TODO
SetDeviceInfo();
PrintMenu();
break;
case 'T': // stop easy setup
case 't':
StopEasySetup();
PrintMenu();
break;
default:
printf("wrong option\n");
PrintMenu();
break;
}
if (option == 'Q' || option == 'q') break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment