* 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
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.
#include "easysetup.h"
#include "logger.h"
#include "resourcehandler.h"
-#include "easysetupcallbacks.h"
+#include "oic_string.h"
/**
* @var ES_ENROLLEE_TAG
//-----------------------------------------------------------------------------
// 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)
{
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();
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;
-}
-
{
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);
}
}
{
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)
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)
{
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)
{
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)
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;
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;
OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask);
OCStackResult DeleteEasySetupResources();
+OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty);
+
void GetTargetNetworkInfoFromProvResource(char *, char *);
void RegisterWifiRsrcEventCallBack(ESWiFiCB);
#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
* 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"
#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
{
WiFi_11B,
WiFi_11G,
WiFi_11N,
- WiFi_11AC
+ WiFi_11AC,
+ WiFi_EOF = 999,
} WIFI_MODE;
typedef enum
ES_RECVREQOFNETRES,
ES_RECVUPDATEOFPROVRES,
ES_RECVTRIGGEROFPROVRES,
+ ES_UNAUTHORIZED = 31
} ESResult;
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;
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
*/
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;
/**
*/
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;
// 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;
#include <string.h>
#include <stdio.h>
#include <pthread.h>
+#include <oic_string.h>
#define TAG "ENROLLEE_SAMPLE"
}
printf("WiFiProvCbInApp OUT\n");
-
- PrintMenu();
}
void DevConfProvCbInApp(ESDevConfProvData *eventData)
}
printf("DevConfProvCbInApp OUT\n");
-
- PrintMenu();
}
void CloudDataProvCbInApp(ESCloudProvData *eventData)
}
printf("CloudDataProvCbInApp OUT\n");
-
- PrintMenu();
}
ESProvisioningCallbacks gCallbacks = {
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");
printf("EasySetup Enrollee SAMPLE\n");
printf("#########################\n");
PrintMenu();
- char option = 'T';
+ char option;
while(true)
{
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;