escommon.h 7.28 KB
Newer Older
1 2
//******************************************************************
//
3
// Copyright 2015 Samsung Electronics All Rights Reserved.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// 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_COMMON_H_
#define ES_COMMON_H_

#include "ocstack.h"
#include "octypes.h"

// Defines
28 29 30 31 32
#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
33 34 35 36 37 38 39 40 41

/**
 * @brief Mac address length for BT port
 */
#define NET_MACADDR_SIZE 18

/**
 * Attributes used to form a proper easysetup conforming JSON message.
 */
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#define OC_RSRVD_ES_PROVSTATUS             "ps"
#define OC_RSRVD_ES_ERRORCODE              "ec"
#define OC_RSRVD_ES_TRIGGER                "tr"
#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               "cisurl"
#define OC_RSRVD_ES_DEVNAME                "dn"
#define OC_RSRVD_ES_LANGUAGE               "lang"
#define OC_RSRVD_ES_COUNTRY                "cont"
57 58 59 60

/**
 * Easysetup defined resoruce types and uris.
 */
61 62 63 64 65 66 67 68
#define OC_RSRVD_ES_RES_TYPE_PROV         "ocf.r.prov"
#define OC_RSRVD_ES_URI_PROV              "/.well-known/ocf/prov"
#define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.r.wifi"
#define OC_RSRVD_ES_URI_WIFI              "/.well-known/ocf/prov/wifi"
#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
#define OC_RSRVD_ES_URI_CLOUDSERVER       "/.well-known/ocf/prov/cloudserver"
#define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.r.devconf"
#define OC_RSRVD_ES_URI_DEVCONF           "/.well-known/ocf/prov/devconf"
69

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#define OC_RSRVD_ES_URI_NET               "/oic/net"

#define NUM_WIFIMODE    10

typedef enum
{
    NO_PROVISION = 0,
    CONNECTED_ENROLLER,
    FAILED_CONNECTION
} PROV_STATUS;

typedef enum
{
    WiFi_11A = 0,
    WiFi_11B,
    WiFi_11G,
    WiFi_11N,
    WiFi_11AC
} WIFI_MODE;
89

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
typedef enum
{
    WiFi_24G = 0,
    WiFi_5G,
    WiFi_BOTH
} WIFI_FREQ;

typedef enum
{
    NONE_AUTH = 0,
    WEP,
    WPA_PSK,
    WPA2_PSK
} WIFI_AUTHTYPE;

typedef enum
{
    NONE_ENC = 0,
    WEP_64,
    WEP_128,
    TKIP,
    AES,
    TKIP_AES
} WIFI_ENCTYPE;
114

115 116 117 118 119 120 121 122 123 124 125 126 127
/**
* Device Roles defined for each device type used in easy setup
*/
typedef enum
{
    ENROLLEE,
    MEDIATOR,
    ENROLLER,
} DeviceRole;

/**
* On-boarding connection to create Adhoc network.
*/
128 129
typedef enum
{
130 131 132
    SOFTAP,
    BLE,
} OBConnection;
133

134 135
typedef enum
{
136 137 138 139 140 141 142 143 144 145 146 147
    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;

148 149 150
typedef enum
{
    /**
151 152
     * Default state of the device
     */
153 154 155
    ES_INIT_STATE,

    /**
156 157
     * Device will move to this state once the on boarding begins
     */
158 159 160
    ES_ON_BOARDING_STATE,

    /**
161 162
     * Device will move to this state after successful on-boarding of the device
     */
163 164 165
    ES_ON_BOARDED_STATE,

    /**
166 167
     * Device will move to this state once the on boarding is done
     */
168 169 170
    ES_PROVISIONING_STATE,

    /**
171 172
     * Easy setup process is successful.
     */
173 174 175
    ES_PROVISIONED_STATE,

    /**
176 177 178
     * 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
     */
179 180 181
    ES_OWNERSHIP_TRANSFERRING_STATE,

    /**
182 183 184
     * 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
     */
185 186 187
    ES_OWNERSHIP_TRANSFERRED_STATE,

    /**
188 189 190
     * 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
     */
191 192
    ES_FACTORY_RESET_STATE,

193 194 195 196
    /**
     * Enrollee moves to this state after connecting to target network
     */
    ES_ON_BOARDED_TARGET_NETWORK_STATE,
197
}ESEnrolleeState;
198 199 200 201

/**
 * Provisioning Device Status
 */
202 203 204
typedef struct
{
    // Address of remote server
205
    OCDevAddr * addr;
206
    // Indicates adaptor type on which the response was received
207
    OCConnectivityType connType;
208
} EasySetupDeviceInfo;
209 210 211 212

/**
 * Provosioning Status
 */
213 214 215 216 217 218 219 220
typedef enum
{
    DEVICE_PROVISIONED = 0,
    DEVICE_NOT_PROVISIONED,
    DEVICE_OWNED,
    DEVICE_NOT_OWNED
} EasySetupState, ProvStatus;

221
/**
222
 * Response from queries to remote servers.
223
 */
224 225
typedef struct
{
226 227 228 229 230
    // EasySetup Status
    EasySetupState provStatus;
    // EasySetup Device Info
    EasySetupDeviceInfo provDeviceInfo;
} EasySetupInfo, ProvisioningInfo;
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

/**
 * @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[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
        char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
    } WIFI;
261
} ProvData;
262 263 264 265 266 267

/**
 * @brief Network Information
 */
typedef struct
{
268
    ProvData provData;    /**< Enroller Network Info**/
269
    OCConnectivityType connType;    /**< Connectivity Type**/
270
} ProvConfig;
271 272 273 274

/**
 * Client applications implement this callback to consume responses received from Servers.
 */
275 276
typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);

277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
/**
 * @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[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;

/**
 * @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;

299
#endif //ES_COMMON_H_