X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Feasy-setup%2Fmediator%2Frichsdk%2Finc%2FRemoteEnrollee.h;h=76ce15525c92d832c8b43cc593a5222b089980aa;hb=refs%2Ftags%2Ftizen_4.0.m2_release;hp=cbc5ac2b9d33c958bf996029b32bfb9459e44ad5;hpb=a5c63ff4150291f73fe6fc826d00bdc0141d2fe0;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h index cbc5ac2..76ce155 100755 --- a/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h +++ b/service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h @@ -22,6 +22,8 @@ #define REMOTE_ENROLLEE_H_ #include +#include +#include #include "ESRichCommon.h" #include "OCApi.h" @@ -37,120 +39,215 @@ namespace OIC class CloudResource; class EnrolleeSecurity; + typedef std::function resource)> onDeviceDiscoveredCb; + /** - * This class represents Remote Enrollee device instance. - * It will provide APIs for Mediator to perform operations to enable the Enrollee device - * to connect to the Enroller. + * This class represents Remote Enrollee device instance. What operation the class provides: + * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee + * devices. + * 2) Provision WiFi AP information used for which Enrollee is going to connect to the AP + * 3) Provision Device confiruation setting, i.e. language, country, and etc + * 4) Provision Cloud information used for which Enrollee is going to register to the cloud */ - class RemoteEnrollee + class RemoteEnrollee : public std::enable_shared_from_this { public: ~RemoteEnrollee() = default; -#ifdef __WITH_DTLS__ /** - * Register Security status and other information callback handlers. + * Get an Enrollee's status which includes provisioning status and last error code * - * @param secProvisioningDbCb Callback to be invoked when the stack expects a - * path for the provisioning db. - * @param securityPinCb Callback to get security pin during pin based ownership transfer. + * @param callback will give the requested status * - * @throws InvalidParameterException If callback is an empty function or null. - * @throws ESBadRequestException If registration is already completed. + * @throws ESInvalidParameterException If callback is null. + * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * - * @see SecProvisioningResult + * @see GetStatusCb */ - ESResult registerSecurityCallbackHandler(SecurityPinCb securityPinCb, - SecProvisioningDbPathCb secProvisioningDbPathCb); -#endif //__WITH_DTLS__ + void getStatus(const GetStatusCb callback); /** - * Start provisioning of target Enrollers information to the Enrollee. + * Get an Enrollee's configuration which includes WiFi supported frequency and device name * + * @param callback will give the requested configuration + * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * - * @see RemoteEnrollee + * @see GetConfigurationStatusCb */ - void initRemoteEnrollee(); + void getConfiguration(const GetConfigurationStatusCb callback); /** - * Start provisioning of target Enrollers information to the Enrollee. + * Do security provisioning such as ownership tranfer to Enrollee. + * + * @param callback will give the result if the security provisioning succeeds or fails for some reasons * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * - * @see RemoteEnrollee + * @see SecurityProvStatusCb */ - void requestPropertyData(RequestPropertyDataStatusCb callback); + void provisionSecurity(const SecurityProvStatusCb callback); - /** - * Start provisioning of target Enrollers information to the Enrollee. + /** + * Do security provisioning such as ownership tranfer to Enrollee which may require more + * specific user selections like a type of ownership transfer method or pre-configured + * pin number used to Pre-configured pin-based MOT. + * + * @param callback will give the result if the security provisioning succeeds or fails for some reasons. * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * - * @see RemoteEnrollee + * @see SecurityProvStatusCb */ - void startSecurityProvisioning(SecurityProvStatusCb callback); + void provisionSecurity(const SecurityProvStatusCbWithOption callback); /** - * Start provisioning of target Enrollers information to the Enrollee. + * Provision WiFi AP information and device configuration to Enrollee + * 1. WiFi AP information includes a SSID, password, auth type, and encryption type. + * 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2) + * + * @param devProp a data structure storing the above information to be delivered + * @param callback will give the result if the provisioning succeeds or fails * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * - * @see RemoteEnrollee + * @see DeviceProp + * @see DevicePropProvStatusCb */ - void startDataProvisioning(DataProvStatusCb callback); + void provisionDeviceProperties(const DeviceProp& devProp, + const DevicePropProvStatusCb callback); /** - * Start provisioning of target Enrollers information to the Enrollee. + * Provision Cloud information to Enrollee, which includes Auth code, auth provider, + * Cloud interface server URL, and etc. + * In this function, Discovery for the Enrollee will happen again in a given network. + * Because, this function is expected to call *AFTER* the Enrollee disconnects its Soft AP + * and successfully connects to the certain WiFi AP. In that case, Mediator should discover + * the Enrollee with a certain Device ID in the network. * + * @param cloudProp a data structure storing the above information to be delivered + * @param callback will give the result if the provisioning succeeds or fails + * + * @throws ESInvalidParameterException If callback is null. * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * - * @see RemoteEnrollee + * @see CloudProp + * @see CloudPropProvStatusCb */ - void startCloudProvisioning(CloudProvStatusCb callback); + void provisionCloudProperties(const CloudProp& cloudProp, + const CloudPropProvStatusCb callback); /** - * Get the Provisioning information provided for the current Enrollee. + * Provision Cloud information to Enrollee, which includes Auth code, auth provider, + * Cloud interface server URL, and etc. + * Note that, this API is skipping finding Enrollee in a given network. Instead, an OCResource + * given as a first parameter will be considered to the Enrollee for cloud provisioning. + * + * @param resource an OCResource corresponding to a target Enrollee for cloud provisioning + * @param cloudProp a data structure storing the above information to be delivered + * @param callback will give the result if the provisioning succeeds or fails + * + * @throws ESInvalidParameterException If callback is null. + * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call. * - * @return DataProvInfo Provisioning information provided for the current Enrollee. + * @see CloudProp + * @see CloudPropProvStatusCb */ - DataProvInfo getDataProvInfo(); + void provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource, + const CloudProp& cloudProp, + const CloudPropProvStatusCb callback); - void setDataProvInfo(const DataProvInfo& ); - void setCloudProvInfo(const CloudProvInfo& ); + /** + * Notify an Enrollee to Connect WiFi/Cloud + * + * @param connectTypes Target configurations to be connected. E.g. WiFi and coap cloud server + * @param callback will give the result if the connect request succeeds or fails + * + * @see ES_CONNECT_TYPE + * @see ConnectRequestStatusCb + */ + void requestToConnect(const std::vector &connectTypes, const ConnectRequestStatusCb callback); private: - RemoteEnrollee(); + RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource); ESResult discoverResource(); - ESResult ESDiscoveryTimeout(unsigned short waittime); - void onDeviceDiscovered(std::shared_ptr resource); + + static void onDiscoveredCallback(const std::shared_ptr resource, + std::weak_ptr this_ptr); + + static void onGetStatusHandlerCallback( + const std::shared_ptr< GetEnrolleeStatus > status, + std::weak_ptr this_ptr); + + static void onGetConfigurationStatusHandlerCallback( + const std::shared_ptr< GetConfigurationStatus > status, + std::weak_ptr this_ptr); + + static void onDevicePropProvisioningStatusHandlerCallback( + const std::shared_ptr< DevicePropProvisioningStatus > status, + std::weak_ptr this_ptr); + + static void onCloudPropProvisioningStatusHandlerCallback( + const std::shared_ptr< CloudPropProvisioningStatus > status, + std::weak_ptr this_ptr); + + static void onConnectRequestStatusHandlerCallback( + const std::shared_ptr< ConnectRequestStatus > status, + std::weak_ptr this_ptr); + + static void onSecurityStatusHandlerCallback( + const std::shared_ptr< SecProvisioningStatus > status, + std::weak_ptr this_ptr); + + static ESOwnershipTransferData onSecurityStatusWithOptionHandlerCallback( + const std::shared_ptr< SecProvisioningStatus > status, + std::weak_ptr this_ptr); + + void onDeviceDiscovered(const std::shared_ptr resource); void initCloudResource(); - void RequestPropertyDataStatusHandler (std::shared_ptr< RequestPropertyDataStatus > status); - void dataProvisioningStatusHandler (std::shared_ptr< DataProvisioningStatus > status); - void cloudProvisioningStatusHandler (std::shared_ptr< CloudProvisioningStatus > status); - void securityStatusHandler(std::shared_ptr< SecProvisioningStatus > status); + void getStatusHandler + (const std::shared_ptr< GetEnrolleeStatus > status) const; + void getConfigurationStatusHandler + (const std::shared_ptr< GetConfigurationStatus > status) const; + void devicePropProvisioningStatusHandler + (const std::shared_ptr< DevicePropProvisioningStatus > status) const; + void cloudPropProvisioningStatusHandler + (const std::shared_ptr< CloudPropProvisioningStatus > status) const; + void connectRequestStatusHandler( + const std::shared_ptr< ConnectRequestStatus > status) const; + void securityStatusHandler + (const std::shared_ptr< SecProvisioningStatus > status) const; + ESOwnershipTransferData securityStatusWithOptionHandler + (const std::shared_ptr< SecProvisioningStatus > status) const; private: std::shared_ptr< OC::OCResource > m_ocResource; std::shared_ptr< EnrolleeResource > m_enrolleeResource; - std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity; + std::shared_ptr< EnrolleeSecurity > m_localEnrolleeSecurity; + std::shared_ptr< EnrolleeSecurity > m_cloudEnrolleeSecurity; std::shared_ptr< CloudResource > m_cloudResource; std::string m_deviceId; bool m_discoveryResponse; + std::mutex m_discoverymtx; + std::condition_variable m_cond; + SecurityProvStatusCb m_securityProvStatusCb; - RequestPropertyDataStatusCb m_requestPropertyDataStatusCb; + SecurityProvStatusCbWithOption m_securityProvStatusCbWithOption; + GetStatusCb m_getStatusCb; + GetConfigurationStatusCb m_getConfigurationStatusCb; SecurityPinCb m_securityPinCb; SecProvisioningDbPathCb m_secProvisioningDbPathCb; - DataProvStatusCb m_dataProvStatusCb; - CloudProvStatusCb m_cloudProvStatusCb; - - DataProvInfo m_dataProvInfo; - CloudProvInfo m_cloudProvInfo; - PropertyData m_propertyData; + DevicePropProvStatusCb m_devicePropProvStatusCb; + CloudPropProvStatusCb m_cloudPropProvStatusCb; + ConnectRequestStatusCb m_connectRequestStatusCb; friend class EasySetup; };