Merge all changes of easy setup in master branch to 1.2-rel branch
[platform/upstream/iotivity.git] / service / easy-setup / inc / escommon.h
index ea1a650..8ce57b0 100755 (executable)
 #ifndef ES_COMMON_H_
 #define ES_COMMON_H_
 
-#include <iostream>
-#include <string>
-#ifndef WITH_ARDUINO
-#include <memory>
-#endif
-
 #include "ocstack.h"
 #include "octypes.h"
 
-using namespace std;
+#ifdef __cplusplus
+extern "C"
+{
+#endif
 
 // Defines
-#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
- */
-#define NET_MACADDR_SIZE 18
+#define OIC_STRING_MAX_VALUE    64
+#define MAX_WEBLINKLEN          3
+#define NUM_WIFIMODE            5
 
 /**
  * Attributes used to form a proper easysetup conforming JSON message.
  */
-#define OC_RSRVD_ES_PS                     "ps"
-#define OC_RSRVD_ES_TNN                    "tnn"
-#define OC_RSRVD_ES_CD                     "cd"
-#define OC_RSRVD_ES_TR                     "tr"
-#define OC_RSRVD_ES_TNT                    "tnt"
-#define OC_RSRVD_ES_ANT                    "ant"
+#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"
+#define OC_RSRVD_ES_MODELNUMBER            "mnmo"
+#define OC_RSRVD_ES_LOCATION               "loc"
+#define OC_RSRVD_ES_HREF                   "href"
 
 /**
  * Easysetup defined resoruce types and uris.
  */
-#define OC_RSRVD_ES_PROV_RES_TYPE           "oic.r.prov"
-#define OC_RSRVD_ES_URI_PROV               "/oic/prov"
-#define OC_RSRVD_ES_URI_NET                "/oic/net"
+#define OC_RSRVD_ES_RES_TYPE_PROV         "oic.wk.prov"
+#define OC_RSRVD_ES_URI_PROV              "/ProvisioningResURI"
+#define OC_RSRVD_ES_RES_TYPE_WIFI         "oic.wk.wifi"
+#define OC_RSRVD_ES_URI_WIFI              "/WiFiProvisioningResURI"
+#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "oic.wk.cloudserver"
+#define OC_RSRVD_ES_URI_CLOUDSERVER       "/CloudServerProvisioningResURI"
+#define OC_RSRVD_ES_RES_TYPE_DEVCONF      "oic.wk.devconf"
+#define OC_RSRVD_ES_URI_DEVCONF           "/DevConfProvisioningResURI"
+
 
 /**
- * @brief Defines for Provisioning status accepted values
+ * @brief  Supported WIFI frequency like 2.4G and 5G
  */
-#define ES_PS_NEED_PROVISIONING         1
-#define ES_PS_PROVISIONING_COMPLETED    2
-#define ES_PS_TRIGGER_INIT_VALUE        0
-#define ES_PS_TRIGGER_CONNECTION        1
-
+typedef enum
+{
+    WIFI_24G = 0,       /**< 2.4G **/
+    WIFI_5G,            /**< 5G **/
+    WIFI_BOTH,          /**< 2.4G and 5G **/
+    WIFI_FREQ_NONE      /**< EOF **/
+} WIFI_FREQ;
 
 /**
-* Device Roles defined for each device type used in easy setup
-*/
+ * @brief  Supported WIFI mode like 802.11g and 802.11n
+ */
 typedef enum
 {
-    ENROLLEE,
-    MEDIATOR,
-    ENROLLER,
-} DeviceRole;
+    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;
+
 
 /**
-* On-boarding connection to create Adhoc network.
-*/
+ * @brief  WIFI Authentication tlype of the Enroller
+ */
 typedef enum
 {
-    SOFTAP,
-    BLE,
-} OBConnection;
+    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
 {
-    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,
-} ESResult;
+    NONE_ENC = 0,       /**< NO encryption **/
+    WEP_64,             /**< WEP-64 **/
+    WEP_128,            /**< WEP-128**/
+    TKIP,               /**< TKIP **/
+    AES,                /**< AES **/
+    TKIP_AES            /**< TKIP-AES **/
+} WIFI_ENCTYPE;
 
+/**
+ * @brief A result of Easy Setup
+ */
 typedef enum
 {
     /**
-     * Default state of the device
+     * Provisioning succeeds.
      */
-    ES_INIT_STATE,
+    ES_OK = 0,
 
     /**
-     * Device will move to this state once the on boarding begins
+     * Enrollee discovery fails in cloud provisioning
      */
-    ES_ON_BOARDING_STATE,
+    ES_ENROLLEE_DISCOVERY_FAILURE = 11,
 
     /**
-     * Device will move to this state after successful on-boarding of the device
+     * Valid GET or POST request fails for some reason.
+     * This failure may happen when it failed to receive any response from Enrollee by a timeout threshold
      */
-    ES_ON_BOARDED_STATE,
+    ES_COMMUNICATION_ERROR,
 
     /**
-     * Device will move to this state once the on boarding is done
+     * Security opertion is not supported because Mediator is built as unsecured mode.
      */
-    ES_PROVISIONING_STATE,
+    ES_SEC_OPERATION_IS_NOT_SUPPORTED = 20,
 
     /**
-     * Easy setup process is successful.
+     * Security resource discovery fails due to loss of discovery packet or absence of the resource in a network
      */
-    ES_PROVISIONED_STATE,
+    ES_SECURE_RESOURCE_DISCOVERY_FAILURE,
 
     /**
-     * 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
+     * Ownership transfer fails because DTLS handshake failure happens
      */
-    ES_OWNERSHIP_TRANSFERRING_STATE,
+    ES_OWNERSHIP_TRANSFER_FAILURE,
 
     /**
-     * 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
+     * ACL provisioning fails in cloud provisioning.
+     * It could be that UUID format of cloud server is wrong.
+     * Or any response for the provisioning request is not arrived at Mediator
      */
-    ES_OWNERSHIP_TRANSFERRED_STATE,
+    ES_ACL_PROVISIONING_FAILURE,
 
     /**
-     * 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
+     * Cert. provisioning fails in cloud provisioning.
+     * It could be that you put a wrong cred ID of which the corresponding certificate does not exist in SVR DB.
+     * Or any response for the provisioning request is not arrived at Mediator
      */
-    ES_FACTORY_RESET_STATE,
+    ES_CERT_PROVISIONING_FAILURE,
 
     /**
-     * Enrollee moves to this state after connecting to target network
+     * Provisioning fails for some reason.
      */
-    ES_ON_BOARDED_TARGET_NETWORK_STATE,
-}EnrolleeState;
+    ES_ERROR = 255
+} ESResult;
 
 /**
- * Provisioning Device Status
+ * @brief Indicate which resource is created in Enrollee
  */
-typedef struct
+typedef enum
 {
-    // Address of remote server
-    OCDevAddr * addr;
-    // Indicates adaptor type on which the response was received
-    OCConnectivityType connType;
-} EasySetupDeviceInfo;
+    ES_WIFI_RESOURCE = 0x01,
+    ES_CLOUD_RESOURCE = 0x02,
+    ES_DEVCONF_RESOURCE = 0x04
+} ESResourceMask;
 
 /**
- * Provosioning Status
+ * @brief Indicate enrollee and provisioning status. Provisioning status is shown in "provisioning
+ *        status" property in provisioning resource.
  */
 typedef enum
 {
-    DEVICE_PROVISIONED = 0,
-    DEVICE_NOT_PROVISIONED,
-    DEVICE_OWNED,
-    DEVICE_NOT_OWNED
-} EasySetupState, ProvStatus;
+    /**
+     * Default state of the device
+     */
+    ES_STATE_INIT = 0,
 
-/**
- * Response from queries to remote servers.
- */
-typedef struct
-{
-    // EasySetup Status
-    EasySetupState provStatus;
-    // EasySetup Device Info
-    EasySetupDeviceInfo provDeviceInfo;
-} EasySetupInfo, ProvisioningInfo;
+    /**
+    * Status indicating being cnnecting to target network
+    */
+    ES_STATE_CONNECTING_TO_ENROLLER,
 
-/**
- * @brief  Network information of the Enroller
- */
-typedef union
-{
     /**
-     * @brief BT Mac Information
-     */
-    struct
-    {
-        char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
-    } BT;
+    * Status indicating successful conection to target network
+    */
+    ES_STATE_CONNECTED_TO_ENROLLER,
 
     /**
-     * @brief LE MAC Information
-     */
-    struct
-    {
-        char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
-    } LE;
+    * Status indicating failure connection to target network
+    */
+    ES_STATE_CONNECTED_FAIL_TO_ENROLLER,
 
     /**
-     * @brief IP Information
-     */
-    struct
-    {
-        char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
-        char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
-    } WIFI;
-} ProvData;
+    * Status indicating successful registration to cloud
+    */
+    ES_STATE_REGISTERED_TO_CLOUD,
+
+    /**
+    * Status indicating failure registeration to cloud
+    */
+    ES_STATE_REGISTRRED_FAIL_TO_CLOUD
+} ESEnrolleeState, ProvStatus;
 
 /**
- * @brief Network Information
+ * @brief Indicate last error code to describe a reason of error during easy setup.
  */
-typedef struct
+typedef enum
 {
-    ProvData provData;    /**< Enroller Network Info**/
-    OCConnectivityType connType;    /**< Connectivity Type**/
-} ProvConfig;
+    /**
+     * Init Error Code
+     */
+    ES_ERRCODE_NO_ERROR = 0,
 
-/**
- * Client applications implement this callback to consume responses received from Servers.
- */
-typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
+    /**
+    * Error Code that given WiFi's SSID is not found
   */
+    ES_ERRCODE_SSID_NOT_FOUND,
 
-/**
- * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
-*/
+    /**
+    * 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,
 
-// 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**/
-    bool isSecured;                 /**< Secure connection**/
-}WiFiOnboardingConfig;
+    /**
+    * Error Code that there is no Internet connection
+    */
+    ES_ERRCODE_NO_INTERNETCONNECTION,
 
-/**
- * @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;
+    /**
+    * Error Code that Timeout occured
+    */
+    ES_ERRCODE_TIMEOUT,
+
+    /**
+    * Error Code that Unknown error occured
+    */
+    ES_ERRCODE_UNKNOWN
+} ESErrorCode;
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif //ES_COMMON_H_