1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
33 #define OIC_STRING_MAX_VALUE 100
34 #define IPV4_ADDR_SIZE 16
36 #define NET_WIFI_SSID_SIZE 100
37 #define NET_WIFI_PWD_SIZE 100
40 * @brief Mac address length for BT port
42 #define NET_MACADDR_SIZE 18
45 * Attributes used to form a proper easysetup conforming JSON message.
47 #define OC_RSRVD_ES_PS "ps"
48 #define OC_RSRVD_ES_TNN "tnn"
49 #define OC_RSRVD_ES_CD "cd"
50 #define OC_RSRVD_ES_TR "tr"
51 #define OC_RSRVD_ES_TNT "tnt"
52 #define OC_RSRVD_ES_ANT "ant"
53 #define OC_RSRVD_ES_URI_PROV "/oic/prov"
54 #define OC_RSRVD_ES_URI_NET "/oic/net"
57 * @brief Defines for Provisioning status accepted values
59 #define ES_PS_NEED_PROVISIONING 1
60 #define ES_PS_PROVISIONING_COMPLETED 2
63 * Device Roles defined for each device type used in easy setup
73 * On-boarding connection to create Adhoc network.
87 ES_NETWORKNOTCONNECTED,
88 ES_RESOURCECREATED = 11,
89 ES_RECVREQOFPROVRES = 21,
91 ES_RECVUPDATEOFPROVRES,
92 ES_RECVTRIGGEROFPROVRES,
98 * Default state of the device
103 * Device will move to this state once the on boarding begins
105 ES_ON_BOARDING_STATE,
108 * Device will move to this state after successful on-boarding of the device
113 * Device will move to this state once the on boarding is done
115 ES_PROVISIONING_STATE,
118 * Easy setup process is successful.
120 ES_PROVISIONED_STATE,
123 * This state is arbitrary one, any time device can come into this state
124 * Device will move to this state if the ownership transfer initiated by the Application
126 ES_OWNERSHIP_TRANSFERRING_STATE,
129 * This state is arbitrary one, any time device can come into this state
130 * Device will move to this state if the ownership transfer is completed
132 ES_OWNERSHIP_TRANSFERRED_STATE,
135 * This state is arbitrary one, any time device can come into this state
136 * Device will move to this state once the Application factory reset the device
138 ES_FACTORY_RESET_STATE,
141 * Enrollee moves to this state after connecting to target network
143 ES_ON_BOARDED_TARGET_NETWORK_STATE,
147 * Provisioning Device Status
151 // Address of remote server
153 // Indicates adaptor type on which the response was received
154 OCConnectivityType connType;
155 } EasySetupDeviceInfo;
158 * Provosioning Status
162 DEVICE_PROVISIONED = 0,
163 DEVICE_NOT_PROVISIONED,
166 } EasySetupState, ProvStatus;
169 * Response from queries to remote servers.
174 EasySetupState provStatus;
175 // EasySetup Device Info
176 EasySetupDeviceInfo provDeviceInfo;
177 } EasySetupInfo, ProvisioningInfo;
180 * @brief Network information of the Enroller
185 * @brief BT Mac Information
189 char btMacAddress[NET_MACADDR_SIZE]; /**< BT mac address **/
193 * @brief LE MAC Information
197 char leMacAddress[NET_MACADDR_SIZE]; /**< BLE mac address **/
201 * @brief IP Information
205 char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enroller**/
206 char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
207 char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
213 * @brief Network Information
217 EnrolleeInfo netAddressInfo; /**< Enroller Network Info**/
218 OCConnectivityType connType; /**< Connectivity Type**/
219 bool isSecured; /**< Secure connection**/
220 // TODO : Ideally isSecured should be renamed to needSecuredEasysetup.
221 // To provide backward compatibility to v1.0 release, a new variable is being added.
222 // If isSecured is not used by other applications, isSecured will be depricated.
223 bool needSecuredEasysetup; /**< Need of secure ownership transfer during easysetup**/
224 } EnrolleeNWProvInfo;
227 * Client applications implement this callback to consume responses received from Servers.
229 typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
239 ES_PROVISIONING_ERROR = -1,
240 ES_NEED_PROVISIONING,
241 ES_PROVISIONED_ALREADY,
242 ES_PROVISIONING_SUCCESS
257 ES_SEC_ACL_PROVISIONED,
258 ES_SEC_CREDS_PROVISIONED
262 * Security Provisioning Status
264 class SecProvisioningResult
267 std::shared_ptr< SecProvisioningResult > shared_ptr;
268 SecProvisioningResult(std::string deviceUUID, ESResult result) :
269 m_devUUID(deviceUUID), m_result(result)
274 std::string getDeviceUUID()
284 std::string m_devUUID;
289 * Callback function definition for providing Enrollee security status .
291 typedef std::function< void(std::shared_ptr<SecProvisioningResult>) > EnrolleeSecStatusCb;
294 * Callback definition to be invoked when the security stack expects a pin from application.
296 typedef std::function< void(std::string&) > SecurityPinCb;
299 * Callback definition to be invoked when the stack expects a db path.
301 typedef std::function< void(std::string&) > SecProvisioningDbPathCb;
303 class ProvisioningStatus
306 std::shared_ptr< ProvisioningStatus > shared_ptr;
307 ProvisioningStatus(ESResult result, ESState esState) :
308 m_result(result), m_esState(esState)
313 ESResult& getESResult()
318 ESState& getESState()
327 class EasySetupStatus
330 std::shared_ptr< EasySetupStatus > shared_ptr;
331 EasySetupStatus(const EasySetupState& easySetupState,
332 const EnrolleeNWProvInfo& enrolleeNWProvInfo) :
333 m_easySetupState(easySetupState), m_enrolleeNWProvInfo(enrolleeNWProvInfo)
338 EnrolleeNWProvInfo& getEasySetupNWProvInfo()
340 return m_enrolleeNWProvInfo;
343 EasySetupState& getEasySetupState()
345 return m_easySetupState;
348 EasySetupState m_easySetupState;
349 EnrolleeNWProvInfo m_enrolleeNWProvInfo;
353 #endif //WITH_ARDUINO
355 #endif //ES_COMMON_H_