Merge duplicated variables used by both of Mediator and Enrollee
authorJihun Ha <jihun.ha@samsung.com>
Mon, 1 Aug 2016 09:19:16 +0000 (18:19 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 1 Aug 2016 12:02:08 +0000 (12:02 +0000)
Duplicated string definition and enum variable are merged into escommon.h.
And Enrollee and Mediator has own common header file.

Change-Id: I5d49d46e267e30260dc1de7520d034e586df705e
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9891
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/easy-setup/enrollee/inc/ESEnrolleeCommon.h [new file with mode: 0755]
service/easy-setup/enrollee/inc/easysetup.h
service/easy-setup/enrollee/src/resourcehandler.c
service/easy-setup/enrollee/src/resourcehandler.h
service/easy-setup/inc/escommon.h
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c

diff --git a/service/easy-setup/enrollee/inc/ESEnrolleeCommon.h b/service/easy-setup/enrollee/inc/ESEnrolleeCommon.h
new file mode 100755 (executable)
index 0000000..911d44b
--- /dev/null
@@ -0,0 +1,105 @@
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef ES_ENROLLEE_COMMON_H_
+#define ES_ENROLLEE_COMMON_H_
+
+#include "ocstack.h"
+#include "octypes.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @brief Data structure delivered from mediator, which provides WiFi information
+ */
+typedef struct
+{
+    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**/
+    void *userdata;                 /**< Vender-specific data**/
+} ESWiFiProvData;
+
+/**
+ * @brief Data structure delivered from mediator, which provides device configuration information
+ */
+typedef struct
+{
+    char language[OIC_STRING_MAX_VALUE];    /**< IETF language tag using ISO 639X **/
+    char country[OIC_STRING_MAX_VALUE];     /**< ISO Country Code (ISO 3166-1 Alpha-2) **/
+    void *userdata;                         /**< Vender-specific data**/
+} ESDevConfProvData;
+
+/**
+ * @brief Data structure delivered from mediator, which provides Cloud server information
+ */
+typedef struct
+{
+    char authCode[OIC_STRING_MAX_VALUE];        /**< Auth code issued by OAuth2.0-compatible account server **/
+    char authProvider[OIC_STRING_MAX_VALUE];    /**< Auth provider ID **/
+    char ciServer[OIC_STRING_MAX_VALUE];        /**< Cloud interface server URL which an Enrollee is going to registered **/
+    void *userdata;                             /**< Vender-specific data**/
+} ESCloudProvData;
+
+/**
+ * @brief Data structure stored for Device property which includes a WiFi and device configuration.
+ */
+typedef struct
+{
+    /**
+     * @brief Data structure indicating WiFi configuration of Enrollee
+     */
+    struct
+    {
+        WIFI_MODE mode[NUM_WIFIMODE];
+        WIFI_FREQ freq;
+    } WiFi;
+
+    /**
+     * @brief Data structure indicating device configuration of Enrollee
+     */
+    struct
+    {
+        char deviceName[MAX_DEVICELEN];
+    } DevConf;
+} ESDeviceProperty;
+
+/**
+ * A set of functions pointers for callback functions which are called after provisioning data is
+ * received from Mediator.
+ */
+typedef struct
+{
+    void (*WiFiProvCb) (ESWiFiProvData *);
+    void (*DevConfProvCb) (ESDevConfProvData *);
+    void (*CloudDataProvCb) (ESCloudProvData *);
+} ESProvisioningCallbacks;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //ES_ENROLLEE_COMMON_H_
+
index ea9f2cb..c85ba32 100755 (executable)
@@ -23,6 +23,7 @@
 #define EASYSETUP_ENROLLEE_H__
 
 #include "escommon.h"
+#include "ESEnrolleeCommon.h"
 
 #include "ocpayload.h"
 
@@ -37,17 +38,6 @@ extern "C" {
 #endif // __cplusplus
 
 /**
- * A set of functions pointers for callback functions which are called after provisioning data is
- * received from Mediator.
- */
-typedef struct
-{
-    void (*WiFiProvCb) (ESWiFiProvData *);
-    void (*DevConfProvCb) (ESDevConfProvData *);
-    void (*CloudDataProvCb) (ESCloudProvData *);
-} ESProvisioningCallbacks;
-
-/**
  * A function pointer for registering a user-defined function to set user-specific properties to a
  * response going back to a client.
  * @param payload Represents a response. You can set a specific value with specific property key
index 3256a71..e7e0f26 100755 (executable)
@@ -163,11 +163,11 @@ OCStackResult initWiFiResource(bool isSecured)
 {
     OCStackResult res = OC_STACK_ERROR;
 
-    gWiFiResource.supportedFreq = WiFi_BOTH;
-    gWiFiResource.supportedMode[0] = WiFi_11A;
-    gWiFiResource.supportedMode[1] = WiFi_11B;
-    gWiFiResource.supportedMode[2] = WiFi_11G;
-    gWiFiResource.supportedMode[3] = WiFi_11N;
+    gWiFiResource.supportedFreq = WIFI_BOTH;
+    gWiFiResource.supportedMode[0] = WIFI_11A;
+    gWiFiResource.supportedMode[1] = WIFI_11B;
+    gWiFiResource.supportedMode[2] = WIFI_11G;
+    gWiFiResource.supportedMode[3] = WIFI_11N;
     gWiFiResource.numMode = 4;
     gWiFiResource.authType = NONE_AUTH;
     gWiFiResource.encType = NONE_ENC;
index 72e5f3e..4715030 100755 (executable)
@@ -24,6 +24,7 @@
 #include "logger.h"
 #include "ocstack.h"
 #include "escommon.h"
+#include "ESEnrolleeCommon.h"
 #include "octypes.h"
 
 #ifndef ES_RESOURCE_HANDLER_H_
index 4694c22..9eb03d9 100755 (executable)
@@ -79,28 +79,29 @@ extern "C"
 #define MAX_WEBLINKLEN  100
 
 /**
- * @brief  Supported WIFI mode like 802.11g and 802.11n
+ * @brief  Supported WIFI frequency like 2.4G and 5G
  */
 typedef enum
 {
-    WiFi_11A = 0,       /**< 802.11a **/
-    WiFi_11B,           /**< 802.11b **/
-    WiFi_11G,           /**< 802.11g **/
-    WiFi_11N,           /**< 802.11n **/
-    WiFi_11AC,          /**< 802.11ac **/
-    WiFi_EOF = 999
-} WIFI_MODE;
+    WIFI_24G = 0,       /**< 2.4G **/
+    WIFI_5G,            /**< 5G **/
+    WIFI_BOTH,          /**< 2.4G and 5G **/
+    WIFI_FREQ_NONE      /**< EOF **/
+} WIFI_FREQ;
 
 /**
- * @brief  Supported WIFI frequency like 2.4G and 5G
+ * @brief  Supported WIFI mode like 802.11g and 802.11n
  */
 typedef enum
 {
-    WiFi_24G = 0,       /**< 2.4G **/
-    WiFi_5G,            /**< 5G **/
-    WiFi_BOTH,          /**< 2.4G and 5G **/
-    WiFi_FREQ_NONE      /**< EOF **/
-} WIFI_FREQ;
+    WIFI_11A = 0,       /**< 802.11a **/
+    WIFI_11B,           /**< 802.11b **/
+    WIFI_11G,           /**< 802.11g **/
+    WIFI_11N,           /**< 802.11n **/
+    WIFI_11AC,          /**< 802.11ac **/
+    WiFi_EOF = 999
+} WIFI_MODE;
+
 
 /**
  * @brief  WIFI Authentication tlype of the Enroller
@@ -152,62 +153,6 @@ typedef enum
 } ESResourceMask;
 
 /**
- * @brief Data structure delivered from mediator, which provides WiFi information
- */
-typedef struct
-{
-    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**/
-    void *userdata;                 /**< Vender-specific data**/
-} ESWiFiProvData;
-
-/**
- * @brief Data structure delivered from mediator, which provides device configuration information
- */
-typedef struct
-{
-    char language[OIC_STRING_MAX_VALUE];    /**< IETF language tag using ISO 639X **/
-    char country[OIC_STRING_MAX_VALUE];     /**< ISO Country Code (ISO 3166-1 Alpha-2) **/
-    void *userdata;                         /**< Vender-specific data**/
-} ESDevConfProvData;
-
-/**
- * @brief Data structure delivered from mediator, which provides Cloud server information
- */
-typedef struct
-{
-    char authCode[OIC_STRING_MAX_VALUE];        /**< Auth code issued by OAuth2.0-compatible account server **/
-    char authProvider[OIC_STRING_MAX_VALUE];    /**< Auth provider ID **/
-    char ciServer[OIC_STRING_MAX_VALUE];        /**< Cloud interface server URL which an Enrollee is going to registered **/
-    void *userdata;                             /**< Vender-specific data**/
-} ESCloudProvData;
-
-/**
- * @brief Data structure stored for Device property which includes a WiFi and device configuration.
- */
-typedef struct
-{
-    /**
-     * @brief Data structure indicating WiFi configuration of Enrollee
-     */
-    struct
-    {
-        WIFI_MODE mode[NUM_WIFIMODE];
-        WIFI_FREQ freq;
-    } WiFi;
-
-    /**
-     * @brief Data structure indicating device configuration of Enrollee
-     */
-    struct
-    {
-        char deviceName[MAX_DEVICELEN];
-    } DevConf;
-} ESDeviceProperty;
-
-/**
  * @brief Indicate enrollee and provisioning status. Provisioning status is shown in "provisioning
  *        status" property in provisioning resource.
  */
index 4acb8d2..a3178ff 100755 (executable)
 #include "ocstack.h"
 #include "octypes.h"
 
+#include "escommon.h"
+
 using namespace OC;
 using namespace std;
 
-// Defines
-#define IP_PORT                 55555
-
-/**
- * Attributes used to form a proper easysetup conforming JSON message
- */
-#define OC_RSRVD_ES_PROVSTATUS             "ps"
-#define OC_RSRVD_ES_LAST_ERRORCODE         "lec"
-#define OC_RSRVD_ES_LINKS                  "links"
-#define OC_RSRVD_ES_SUPPORTEDWIFIMODE      "swmt"
-#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ      "swf"
-#define OC_RSRVD_ES_SSID                   "tnn"
-#define OC_RSRVD_ES_CRED                   "cd"
-#define OC_RSRVD_ES_AUTHTYPE               "wat"
-#define OC_RSRVD_ES_ENCTYPE                "wet"
-#define OC_RSRVD_ES_AUTHCODE               "ac"
-#define OC_RSRVD_ES_AUTHPROVIDER           "apn"
-#define OC_RSRVD_ES_CISERVER               "cis"
-#define OC_RSRVD_ES_SERVERID               "sid"
-#define OC_RSRVD_ES_DEVNAME                "dn"
-#define OC_RSRVD_ES_LANGUAGE               "lang"
-#define OC_RSRVD_ES_COUNTRY                "ctry"
-
-/**
- * Easysetup defined resoruce types and uris
- */
-#define OC_RSRVD_ES_RES_TYPE_PROV         "ocf.wk.prov"
-#define OC_RSRVD_ES_URI_PROV              "/ProvisioningResURI"
-#define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.wk.wifi"
-#define OC_RSRVD_ES_URI_WIFI              "/WiFiProvisioningResURI"
-#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.wk.cloudserver"
-#define OC_RSRVD_ES_URI_CLOUDSERVER       "/CloudServerProvisioningResURI"
-#define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.wk.devconf"
-#define OC_RSRVD_ES_URI_DEVCONF           "/DevConfProvisioningResURI"
-
 #ifndef WITH_ARDUINO
 namespace OIC
 {
     namespace Service
     {
-        typedef enum
-        {
-            ES_ERROR = -1,
-            ES_OK = 0,
-            ES_NETWORKFOUND = 1,
-            ES_NETWORKCONNECTED,
-            ES_NETWORKNOTCONNECTED,
-            ES_RESOURCECREATED = 11,
-            ES_RECVREQOFPROVRES = 21,
-            ES_RECVREQOFNETRES,
-            ES_RECVUPDATEOFPROVRES,
-            ES_RECVTRIGGEROFPROVRES,
-            ES_UNAUTHORIZED = 31
-        } ESResult;
-
-        /**
-         * @brief Indicate enrollee and provisioning status. Provisioning status is shown in "provisioning
-         *        status" property in provisioning resource.
-         */
-        typedef enum
-        {
-            /**
-             * Default state of the device
-             */
-            ES_STATE_INIT = 0,
-
-            /**
-            * Status indicating being cnnecting to target network
-            */
-            ES_STATE_CONNECTING_TO_ENROLLER,
-
-            /**
-            * Status indicating successful conection to target network
-            */
-            ES_STATE_CONNECTED_TO_ENROLLER,
-
-            /**
-            * Status indicating failure connection to target network
-            */
-            ES_STATE_CONNECTED_FAIL_TO_ENROLLER,
-
-            /**
-            * Status indicating successful registration to cloud
-            */
-            ES_STATE_REGISTERED_TO_CLOUD,
-
-            /**
-            * Status indicating failure registeration to cloud
-            */
-            ES_STATE_REGISTRRED_FAIL_TO_CLOUD
-        } ProvStatus;
-
-        /**
-         * @brief Indicate last error code to describe a reason of error during easy setup.
-         */
-        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,
-
-            /**
-            * Error Code that given WiFi's Password is wrong
-            */
-            ES_ERRCODE_PW_WRONG,
-
-            /**
-            * Error Code that IP address is not allocated
-            */
-            ES_ERRCODE_IP_NOT_ALLOCATED,
-
-            /**
-            * Error Code that there is no Internet connection
-            */
-            ES_ERRCODE_NO_INTERNETCONNECTION,
-
-            /**
-            * Error Code that Timeout occured
-            */
-            ES_ERRCODE_TIMEOUT,
-
-            /**
-            * Error Code that Unknown error occured
-            */
-            ES_ERRCODE_UNKNOWN
-        } ESErrorCode;
-
-        /**
-         * @brief  WIFI Authentication tlype of the Enroller
-         */
-        typedef enum
-        {
-            NONE_AUTH = 0,      /**< NO authentication **/
-            WEP,                /**< WEP **/
-            WPA_PSK,            /**< WPA-PSK **/
-            WPA2_PSK            /**< WPA2-PSK **/
-        } WIFI_AUTHTYPE;
-
-        /**
-         * @brief  WIFI encryption type of the Enroller
-         */
-        typedef enum
-        {
-            NONE_ENC = 0,       /**< NO encryption **/
-            WEP_64,             /**< WEP-64 **/
-            WEP_128,            /**< WEP-128**/
-            TKIP,               /**< TKIP **/
-            AES,                /**< AES **/
-            TKIP_AES            /**< TKIP-AES **/
-        } WIFI_ENCTYPE;
-
-        /**
-         * @brief  Supported WIFI frequency like 2.4G and 5G
-         */
-        typedef enum
-        {
-            WIFI_24G = 0,       /**< 2.4G **/
-            WIFI_5G,            /**< 5G **/
-            WIFI_BOTH,          /**< 2.4G and 5G **/
-            WIFI_FREQ_NONE      /**< EOF **/
-        } WIFI_FREQ;
-
-        /**
-         * @brief  Supported WIFI mode like 802.11g and 802.11n
-         */
-        typedef enum
-        {
-            WIFI_11A = 0,       /**< 802.11a **/
-            WIFI_11B,           /**< 802.11b **/
-            WIFI_11G,           /**< 802.11g **/
-            WIFI_11N,           /**< 802.11n **/
-            WIFI_11AC           /**< 802.11ac **/
-        } WIFI_MODE;
-
         /**
          * @brief Properties of provisioning resource. It includes a provisioning status and last
          *        error code.
index 8974d6d..749402e 100755 (executable)
@@ -236,7 +236,7 @@ void SetDeviceInfo()
     printf("SetDeviceInfo IN\n");
 
     ESDeviceProperty deviceProperty = {
-        {{WiFi_11G, WiFi_11N, WiFi_11AC, WiFi_EOF}, WiFi_5G}, {"Test Device"}
+        {{WIFI_11G, WIFI_11N, WIFI_11AC, WiFi_EOF}, WIFI_5G}, {"Test Device"}
     };
 
     // Set user properties if needed