IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ESRichCommon.h
Go to the documentation of this file.
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 
21 #ifndef ES_COMMON_RICH_H_
22 #define ES_COMMON_RICH_H_
23 
24 #include <iostream>
25 #include <string>
26 #ifndef WITH_ARDUINO
27 #include <memory>
28 #include <vector>
29 #endif
30 
31 #include "OCPlatform.h"
32 #include "ocstack.h"
33 #include "octypes.h"
34 #ifdef __WITH_DTLS__
35 #include "experimental/securevirtualresourcetypes.h"
37 #include "ocrandom.h"
38 #endif
39 
40 #include "escommon.h"
41 
42 #include "logger.h"
43 
44 using namespace OC;
45 using namespace std;
46 
47 #define ES_RICH_COMMON_TAG "ES_MEDIATOR_COMMON"
48 #define OCF_CONTENT_FORMAT_VERSION_OPTION_ID 2053
49 #define OCF_CONTENT_FORMAT_VERSION_VALUE 2048
50 
51 #ifndef WITH_ARDUINO
52 namespace OIC
53 {
54  namespace Service
55  {
61  {
62  public:
63 
68  {
69  m_rep = rep;
70  }
71 
72  EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
73  m_rep(enrolleeStatus.getRepresentation())
74  {
75  }
76 
77  EnrolleeStatus(const EnrolleeStatus&& enrolleeStatus) :
78  m_rep(std::move(enrolleeStatus.getRepresentation()))
79  {
80  }
81 
88  {
89  if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
90  {
91  return static_cast<ProvStatus>(
92  m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
93  }
94  return ES_STATE_INIT;
95  }
96 
103  {
104  if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
105  {
106  return static_cast<ESErrorCode>(
107  m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
108  }
109  return ES_ERRCODE_NO_ERROR;
110  }
111 
118  {
119  return m_rep;
120  }
121  protected:
123  };
124 
128  class CloudProp
129  {
130  public:
131 
136  {
137  m_cloudID = "";
138  m_credID = 0;
139  }
140 
141  CloudProp(const CloudProp& cloudProp) :
142  m_rep(cloudProp.toOCRepresentation()),
143  m_cloudID(cloudProp.getCloudID()),
144  m_credID(cloudProp.getCredID())
145  {
146  }
147 
148  CloudProp(const CloudProp&& cloudProp) :
149  m_rep(std::move(cloudProp.toOCRepresentation())),
150  m_cloudID(cloudProp.getCloudID()),
151  m_credID(cloudProp.getCredID())
152  {
153  }
154 
160  {
161  m_rep = rep;
162  m_cloudID = "";
163  m_credID = 0;
164  }
165 
173  void setCloudProp(string authCode, string authProvider, string ciServer)
174  {
175  m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
176  m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
177  m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
178  }
179 
191  void setCloudPropWithAccessToken(string accessToken, OAUTH_TOKENTYPE tokenType,
192  string authProvider, string ciServer)
193  {
194  m_rep.setValue(OC_RSRVD_ES_ACCESSTOKEN, accessToken);
195  m_rep.setValue(OC_RSRVD_ES_ACCESSTOKEN_TYPE, tokenType);
196  m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
197  m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
198  }
199 
205  void setCloudID(string cloudID)
206  {
207  m_cloudID = cloudID;
208  }
209 
215  void setCredID(int credID)
216  {
217  m_credID = credID;
218  }
219 
225  std::string getAuthCode() const
226  {
227  if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
228  {
229  return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
230  }
231  return std::string("");
232  }
233 
239  std::string getAuthProvider() const
240  {
241  if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
242  {
243  return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
244  }
245  return std::string("");
246  }
247 
253  std::string getCiServer() const
254  {
255  if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
256  {
257  return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
258  }
259  return std::string("");
260  }
261 
267  std::string getCloudID() const
268  {
269  return m_cloudID;
270  }
271 
277  int getCredID() const
278  {
279  return m_credID;
280  }
281 
287  std::string getAccessToken() const
288  {
289  if(m_rep.hasAttribute(OC_RSRVD_ES_ACCESSTOKEN))
290  {
291  return m_rep.getValue<std::string>(OC_RSRVD_ES_ACCESSTOKEN);
292  }
293  return std::string("");
294  }
295 
302  {
303 
304  if(m_rep.hasAttribute(OC_RSRVD_ES_ACCESSTOKEN_TYPE))
305  {
306  return static_cast<OAUTH_TOKENTYPE>(
307  m_rep.getValue<int>(OC_RSRVD_ES_ACCESSTOKEN_TYPE));
308  }
309  return NONE_OAUTH_TOKENTYPE;
310  }
311 
318  {
319  return m_rep;
320  }
321 
329  void updateOCRepresentation(int specVersion)
330  {
331  if(0 == specVersion) // OIC Server does not contain CONTENT FORMAT VERSION
332  {
333  // Representation is already stored as per older resource schemas.
334  return;
335  }
336 
337  // Representation should be updated as per OCF 1.3 Easy Setup resource schemas.
338  std::string authCode = m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
339  std::string authProvider = m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
340  std::string ciServer = m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
341 
342  std::string accessToken = m_rep.getValue<std::string>(OC_RSRVD_ES_ACCESSTOKEN);
343  OAUTH_TOKENTYPE accessTokenType = static_cast<OAUTH_TOKENTYPE>(
344  m_rep.getValue<int>(OC_RSRVD_ES_ACCESSTOKEN_TYPE));
345 
346  OCRepresentation rootRep;
348 
349  OCRepresentation cloudDataRep;
350 
351  if(authCode.length() > 0)
352  {
353  cloudDataRep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
354  }
355 
356  if(accessToken.length() > 0)
357  {
358  cloudDataRep.setValue(OC_RSRVD_ES_ACCESSTOKEN, accessToken);
359  cloudDataRep.setValue(OC_RSRVD_ES_ACCESSTOKEN_TYPE, accessTokenType);
360  }
361 
362  cloudDataRep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
363  cloudDataRep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
364 
365  OCRepresentation cloudconfRep;
367  cloudconfRep.setValue(OC_RSRVD_HREF, std::string(OC_RSRVD_ES_URI_COAPCLOUDCONF));
368  cloudconfRep.setValue(OC_RSRVD_REPRESENTATION, cloudDataRep);
369 
370  rootRep.addChild(cloudconfRep);
371  m_rep = rootRep;
372  }
373 
374  protected:
376  std::string m_cloudID;
377  int m_credID;
378  };
379 
385  {
386  public:
387 
392  {
393  }
394 
395  DeviceProp(const DeviceProp& deviceProp) :
396  m_rep(deviceProp.toOCRepresentation())
397  {
398  }
399 
400  DeviceProp(const DeviceProp&& deviceProp) :
401  m_rep(std::move(deviceProp.toOCRepresentation()))
402  {
403  }
404 
410  {
411  m_rep = rep;
412  }
413 
425  void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
426  {
427  m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
428  m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
429  m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
430  m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
431  }
432 
438  std::string getSsid() const
439  {
440  if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
441  {
442  return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
443  }
444  return std::string("");
445  }
446 
452  std::string getPassword() const
453  {
454  if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
455  {
456  return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
457  }
458  return std::string("");
459  }
460 
469  {
471  if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
472  {
473  return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
474  }
475  return NONE_AUTH;
476  }
477 
486  {
488  if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
489  {
490  return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
491  }
492  return NONE_ENC;
493  }
494 
501  {
502  return m_rep;
503  }
504 
512  void updateOCRepresentation(int specVersion)
513  {
514  if(0 == specVersion) // OIC Server does not contain CONTENT FORMAT VERSION
515  {
516  // Representation is already stored as per older resource schemas.
517  return;
518  }
519 
520  // Representation should be updated as per OCF 1.3 Easy Setup resource schemas.
521  WIFI_AUTHTYPE authtype = static_cast<WIFI_AUTHTYPE> (m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
522  WIFI_ENCTYPE enctype = static_cast<WIFI_ENCTYPE> (m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
523 
524  OCRepresentation rootRep;
526 
527  OCRepresentation wifiDataRep;
528  wifiDataRep.setValue(OC_RSRVD_ES_SSID, m_rep.getValue<std::string>(OC_RSRVD_ES_SSID));
529  wifiDataRep.setValue(OC_RSRVD_ES_CRED, m_rep.getValue<std::string>(OC_RSRVD_ES_CRED));
530  wifiDataRep.setValue(OC_RSRVD_ES_AUTHTYPE, getAuthTypeAsString(authtype));
531  wifiDataRep.setValue(OC_RSRVD_ES_ENCTYPE, getEncTypeAsString(enctype));
532 
533  OCRepresentation wificonfRep;
534  wificonfRep.setUri(OC_RSRVD_ES_URI_WIFICONF);
535  wificonfRep.setValue(OC_RSRVD_HREF, std::string(OC_RSRVD_ES_URI_WIFICONF));
536  wificonfRep.setValue(OC_RSRVD_REPRESENTATION, wifiDataRep);
537 
538  rootRep.addChild(wificonfRep);
539  m_rep = rootRep;
540  }
541 
542  protected:
544 
545  private:
546  std::string getAuthTypeAsString(WIFI_AUTHTYPE authType) const
547  {
548  switch(authType)
549  {
550  case NONE_AUTH:
551  return "None";
552  case WEP:
553  return "WEP";
554  case WPA_PSK:
555  return "WPA_PSK";
556  case WPA2_PSK:
557  return "WPA2_PSK";
558  default:
559  return "None";
560  }
561  }
562 
563  std::string getEncTypeAsString(WIFI_ENCTYPE encType) const
564  {
565  switch(encType)
566  {
567  case NONE_ENC:
568  return "None";
569  case WEP_64:
570  return "WEP_64";
571  case WEP_128:
572  return "WEP_128";
573  case TKIP:
574  return "TKIP";
575  case AES:
576  return "AES";
577  case TKIP_AES:
578  return "TKIP_AES";
579  default:
580  return "None";
581  }
582  }
583  };
584 
589  {
590  public:
591  SecProvisioningStatus(string deviceUUID, ESResult result) :
592  m_devUUID(deviceUUID), m_result(result)
593  {
594 #ifdef __WITH_DTLS__
595  m_selectedOTMethod = OIC_JUST_WORKS;
596  m_isMOTEnabled = false;
597  m_isOwned = false;
598  m_ownerID = {};
599 #endif
600  }
601 #ifdef __WITH_DTLS__
602  SecProvisioningStatus(std::shared_ptr<OCSecureResource> resource, ESResult result) :
603  m_result(result)
604  {
605  m_isMOTEnabled = false;
606  if(resource.get() != nullptr)
607  {
608  m_devUUID = resource->getDeviceID();
609  m_isOwned = resource->getOwnedStatus();
610 #ifdef MULTIPLE_OWNER
611  m_isMOTEnabled = resource->isMOTEnabled();
612 #endif
613 
614  if( OC_STACK_OK != resource->getOTMethod(&m_selectedOTMethod) )
615  {
616  m_selectedOTMethod = OIC_OXM_COUNT; // Out-of-range
617  }
618 
619  if(resource->getOwnedStatus())
620  {
621  char uuidString[UUID_STRING_SIZE] = {};
622  if(OCConvertUuidToString(resource->getDevPtr()->doxm->owner.id, uuidString))
623  {
624  m_ownerID = uuidString;
625  }
626  else
627  {
628  m_ownerID = {};
629  }
630  }
631  }
632  }
633 
634  OicSecOxm_t getSelectedOTMethod() const
635  {
636  return m_selectedOTMethod;
637  }
638 
639  bool isMOTEnabled() const
640  {
641  return m_isMOTEnabled;
642  }
643 
644  bool isOwnedDevice() const
645  {
646  return m_isOwned;
647  }
648 
649  const std::string getOwnerID()
650  {
651  return m_ownerID;
652  }
653 #endif
654  const std::string getDeviceUUID()
655  {
656  return m_devUUID;
657  }
668  {
669  return m_result;
670  }
671  private:
672  string m_devUUID;
673  ESResult m_result;
674 #ifdef __WITH_DTLS__
675  OicSecOxm_t m_selectedOTMethod;
676  bool m_isMOTEnabled;
677  bool m_isOwned;
678  std::string m_ownerID;
679 #endif
680  };
681 
689  {
690  public:
699  m_EasySetupRep(rep), m_OCFServerVersion(0)
700  {
701  }
702 
703  EnrolleeConf(const OCRepresentation& rep, const int OCFServerVersion) :
704  m_EasySetupRep(rep), m_OCFServerVersion(OCFServerVersion)
705  {
706  }
707 
708  EnrolleeConf(const EnrolleeConf& enrolleeConf) :
709  m_EasySetupRep(enrolleeConf.getEasySetupRep()), m_OCFServerVersion(enrolleeConf.getOCFSpecVersion())
710  {
711  }
712 
713  EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
714  m_EasySetupRep(std::move(enrolleeConf.getEasySetupRep())),
715  m_OCFServerVersion(std::move(enrolleeConf.getOCFSpecVersion()))
716  {
717  }
718 
725  std::string getDeviceName() const
726  {
727  std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
728  for(auto child = children.begin(); child != children.end(); ++child)
729  {
730  if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
731  {
732  OCRepresentation rep;
733  if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
734  {
736  }
737  else
738  {
739  return std::string("");
740  }
741 
743  {
744  return rep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
745  }
746  }
747  }
748  return std::string("");
749  }
750 
758  vector<WIFI_MODE> getWiFiModes() const
759  {
760  vector<WIFI_MODE> modes;
761  modes.clear();
762 
763  std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
764  for(auto child = children.begin(); child != children.end(); ++child)
765  {
766  if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
767  {
768  OCRepresentation rep;
769  if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
770  {
772  }
773  else
774  {
775  return modes;
776  }
777 
779  {
780  // Response from OIC Server does not contain spec version in header, so assumed as 0.
781  if(0 == m_OCFServerVersion)
782  {
783  OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiModes() with OIC Spec");
784 
785  // Considering Representation as per OIC Core Spec.
786  for(auto it : rep.getValue
787  <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
788  {
789  modes.push_back(static_cast<WIFI_MODE>(it));
790  }
791  }
792  else // m_OCFServerVersion > 0 for OCF Spec (2048 for OCF 1.0 Spec)
793  {
794  OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiModes() with OCF Spec");
795 
796  // Considering Representation as per OCF 1.0 / 1.x Core Spec.
797  for(auto it : rep.getValue
798  <std::vector<std::string>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
799  {
800  modes.push_back(getWiFiModeAsEnum(it));
801  }
802  }
803  }
804  }
805  }
806  return modes;
807  }
808 
817  {
818  std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
819  for(auto child = children.begin(); child != children.end(); ++child)
820  {
821  if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
822  {
823  OCRepresentation rep;
824  if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
825  {
827  }
828  else
829  {
830  return WIFI_FREQ_NONE;
831  }
832 
834  {
835  // Response from OIC Server does not contain spec version in header, so assumed as 0.
836  if(0 == m_OCFServerVersion)
837  {
838  OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiFreq() with OIC Spec");
839 
840  // Considering Representation as per OIC Core Spec.
841  return static_cast<WIFI_FREQ>(
843  }
844  else // m_OCFServerVersion > 0 for OCF Spec (2048 for OCF 1.0 Spec)
845  {
846  OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiFreq() with OCF Spec");
847 
848  // Considering Representation as per OCF 1.0 / 1.x Core Spec.
849  return getWiFiFreqAsEnum(rep.getValue
850  <std::vector<std::string>>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
851  }
852  }
853  }
854  }
855  return WIFI_FREQ_NONE;
856  }
857 
865  vector<std::string> getSupportedWiFiAuthTypes() const
866  {
867  vector<std::string> swatVector;
868 
869  std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
870  for(auto child = children.begin(); child != children.end(); ++child)
871  {
872  if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
873  {
874  OCRepresentation rep;
875  if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
876  {
878  }
879  else
880  {
881  break;
882  }
883 
885  {
886  /* This property is include only from OCF 1.3 Spec Onwards */
887  swatVector = rep.getValue<std::vector<std::string>>(OC_RSRVD_ES_SUPPORTEDWIFIAUTHTYPE);
888  break;
889  }
890  }
891  }
892  return swatVector;
893  }
894 
902  vector<std::string> getSupportedWiFiEncTypes() const
903  {
904  vector<std::string> swetVector;
905 
906  std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
907  for(auto child = children.begin(); child != children.end(); ++child)
908  {
909  if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
910  {
911  OCRepresentation rep;
912  if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
913  {
915  }
916 
918  {
919  /* This property is include only from OCF 1.3 Spec Onwards */
920  swetVector = rep.getValue<std::vector<std::string>>(OC_RSRVD_ES_SUPPORTEDWIFIENCTYPE);
921  break;
922  }
923  }
924  }
925  return swetVector;
926  }
927 
934  {
935  OCRepresentation rep;
936  if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
937  {
938  rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
939  }
940  else
941  {
942  return ES_STATE_INIT;
943  }
944 
946  {
947  return static_cast<ProvStatus>(
948  rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
949  }
950  return ES_STATE_INIT;
951  }
952 
959  {
960  OCRepresentation rep;
961  if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
962  {
963  rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
964  }
965  else
966  {
967  return ES_ERRCODE_NO_ERROR;
968  }
969 
971  {
972  return static_cast<ESErrorCode>(
974  }
975  return ES_ERRCODE_NO_ERROR;
976  }
977 
983  bool isCloudAccessible() const
984  {
985  std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
986  for(auto child = children.begin(); child != children.end(); ++child)
987  {
988  OCRepresentation rep;
989  if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
990  {
992  }
993  else
994  {
995  return false;
996  }
997 
999  {
1000  for (auto rt : rep.getValue<std::vector<std::string>>(OC_RSRVD_RESOURCE_TYPE))
1001  {
1002  if(0 == rt.compare(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF))
1003  {
1004  return true;
1005  }
1006  }
1007  }
1008  }
1009  return false;
1010  }
1011 
1018  {
1019  return m_EasySetupRep;
1020  }
1021 
1027  int getOCFSpecVersion() const
1028  {
1029  return m_OCFServerVersion;
1030  }
1031 
1032  protected:
1035 
1036  private:
1037 
1038  WIFI_MODE getWiFiModeAsEnum(std::string wifiMode) const
1039  {
1040  if(0 == wifiMode.compare("A"))
1041  {
1042  return WIFI_11A;
1043  }
1044  else if(0 == wifiMode.compare("B"))
1045  {
1046  return WIFI_11B;
1047  }
1048  else if(0 == wifiMode.compare("G"))
1049  {
1050  return WIFI_11G;
1051  }
1052  else if(0 == wifiMode.compare("N"))
1053  {
1054  return WIFI_11N;
1055  }
1056  else /* if(0 == wifiMode.compare("AC")) */
1057  {
1058  return WIFI_11AC;
1059  }
1060  //return WiFi_EOF;
1061  }
1062 
1063  WIFI_FREQ getWiFiFreqAsEnum(std::vector<std::string> wifiFreqList) const
1064  {
1065  bool b_2_4G = false;
1066  bool b_5G = false;
1067 
1068  for (std::string& freq : wifiFreqList)
1069  {
1070  if(0 == freq.compare("2.4G"))
1071  {
1072  b_2_4G = true;
1073  }
1074  else if(0 == freq.compare("5G"))
1075  {
1076  b_5G = true;
1077  }
1078  }
1079 
1080  if(b_2_4G && b_5G)
1081  {
1082  return WIFI_BOTH;
1083  }
1084 
1085  if(b_2_4G)
1086  {
1087  return WIFI_24G;
1088  }
1089 
1090  if(b_5G)
1091  {
1092  return WIFI_5G;
1093  }
1094 
1095  return WIFI_FREQ_NONE;
1096  }
1097  };
1098 
1108  {
1109  public:
1113  GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
1114  m_result(result), m_enrolleeStatus(status)
1115  {
1116  }
1117 
1127  {
1128  return m_result;
1129  }
1130 
1139  {
1140  return m_enrolleeStatus;
1141  }
1142 
1143  private:
1144  ESResult m_result;
1145  EnrolleeStatus m_enrolleeStatus;
1146  };
1147 
1157  {
1158  public:
1163  m_result(result), m_enrolleeConf(conf)
1164  {
1165  }
1166 
1177  {
1178  return m_result;
1179  }
1180 
1189  {
1190  return m_enrolleeConf;
1191  }
1192 
1193  private:
1194  ESResult m_result;
1195  EnrolleeConf m_enrolleeConf;
1196  };
1197 
1204  {
1205  public:
1210  m_result(result)
1211  {
1212  }
1213 
1224  {
1225  return m_result;
1226  }
1227 
1228  private:
1229  ESResult m_result;
1230  };
1231 
1240  {
1241  public:
1246  m_result(result)
1247  {
1248  }
1249 
1264  {
1265  return m_result;
1266  }
1267 
1268  private:
1269  ESResult m_result;
1270  };
1271 
1277  {
1278  public:
1283  m_result(result)
1284  {
1285  }
1286 
1297  {
1298  return m_result;
1299  }
1300 
1301  private:
1302  ESResult m_result;
1303  };
1304 
1306  {
1307  public:
1308 #ifdef __WITH_DTLS__
1310  m_MOTMethod(OIC_OXM_COUNT), m_preconfiguredPin("")
1311  {
1312  }
1313 
1315  m_MOTMethod(data.getMOTMethod()),
1316  m_preconfiguredPin(data.getPreConfiguredPin())
1317  {
1318  }
1319 
1320  ESResult setMOTMethod(OicSecOxm_t method)
1321  {
1322 #ifdef MULTIPLE_OWNER
1323  if(OIC_RANDOM_DEVICE_PIN != method)
1324  {
1325  return ES_ERROR;
1326  }
1327 
1328  m_MOTMethod = method;
1329  return ES_OK;
1330 #else
1331  (void) method;
1332 
1333  return ES_ERROR;
1334 #endif
1335  }
1336 
1337  ESResult setMOTMethod(OicSecOxm_t method, const std::string& pin)
1338  {
1339 #ifdef MULTIPLE_OWNER
1340  if(OIC_PRECONFIG_PIN != method || pin.empty())
1341  {
1342  return ES_ERROR;
1343  }
1344 
1345  m_preconfiguredPin = pin;
1346  m_MOTMethod = method;
1347  return ES_OK;
1348 #else
1349  (void) method;
1350  (void) pin;
1351 
1352  return ES_ERROR;
1353 #endif
1354  }
1355 
1356  OicSecOxm_t getMOTMethod() const
1357  {
1358  return m_MOTMethod;
1359  }
1360 
1361  std::string getPreConfiguredPin() const
1362  {
1363  return m_preconfiguredPin;
1364  }
1365 
1366  private:
1367  OicSecOxm_t m_MOTMethod;
1368  std::string m_preconfiguredPin;
1369 #endif
1370  };
1371 
1375  typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
1376 
1380  typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
1381 
1385  typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
1386 
1390  typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
1391 
1395  typedef function< void(shared_ptr< ConnectRequestStatus >) > ConnectRequestStatusCb;
1396 
1397 
1401  typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
1402 
1408  typedef function< ESOwnershipTransferData(shared_ptr<SecProvisioningStatus>) >
1410 
1414  typedef function< void(string&) > SecurityPinCb;
1415 
1419  typedef function< void(string&) > SecProvisioningDbPathCb;
1420 
1421  }
1422 }
1423 #endif //WITH_ARDUINO
1424 
1425 #endif //ES_COMMON_RICH_H_
802.11ac
Definition: escommon.h:104
OAUTH_TOKENTYPE
OAuth Access Token Types.
Definition: escommon.h:134
WEP-128.
Definition: escommon.h:125
Properties of easysetup resource.
Definition: ESRichCommon.h:60
#define OC_RSRVD_ES_DEVNAME
Definition: escommon.h:66
std::string getAccessToken() const
Get an access token to be delivered.
Definition: ESRichCommon.h:287
function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb
Callback function definition for providing Enrollee cloud property provisioning status.
Definition: ESRichCommon.h:1390
OCRepresentation m_EasySetupRep
Definition: ESRichCommon.h:1033
void updateOCRepresentation(int specVersion)
Update Cloud property representation as per OCF Specification.
Definition: ESRichCommon.h:329
Success status code - START HERE.
Definition: octypes.h:1057
EnrolleeConf(const OCRepresentation &rep, const int OCFServerVersion)
Definition: ESRichCommon.h:703
Default state of the device.
Definition: escommon.h:297
#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ
Definition: escommon.h:53
function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb
Callback function definition for providing Enrollee configuration status.
Definition: ESRichCommon.h:1380
EnrolleeStatus(const EnrolleeStatus &enrolleeStatus)
Definition: ESRichCommon.h:72
#define OC_RSRVD_ES_SUPPORTEDWIFIAUTHTYPE
Definition: escommon.h:54
function< void(string &) > SecProvisioningDbPathCb
Callback definition to be invoked when the stack expects a db path.
Definition: ESRichCommon.h:1419
#define OC_RSRVD_HREF
To represent href.
Definition: octypes.h:139
Definition: escommon.h:136
CloudProp(const CloudProp &&cloudProp)
Definition: ESRichCommon.h:148
Provisioning fails for some reason.
Definition: escommon.h:275
NO encryption.
Definition: escommon.h:123
function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb
Callback function definition for providing Enrollee device property provisioning status.
Definition: ESRichCommon.h:1385
This file contains the declaration of classes and its members related to OCPlatform.
void setCloudPropWithAccessToken(string accessToken, OAUTH_TOKENTYPE tokenType, string authProvider, string ciServer)
Set CoapCloudConf resource properties with Access token to be delivered to Enrollee.
Definition: ESRichCommon.h:191
OAUTH_TOKENTYPE getAccessTokenType() const
Get an access token type to be delivered.
Definition: ESRichCommon.h:301
GetConfigurationStatus(ESResult result, const EnrolleeConf &conf)
Constructor.
Definition: ESRichCommon.h:1162
EnrolleeConf(const EnrolleeConf &enrolleeConf)
Definition: ESRichCommon.h:708
Security Provisioning Status.
Definition: ESRichCommon.h:588
void setUri(const char *uri)
Init Error Code.
Definition: escommon.h:358
const std::string getDeviceUUID()
Definition: ESRichCommon.h:654
DeviceProp()
Constructor.
Definition: ESRichCommon.h:391
802.11a
Definition: escommon.h:100
const OCRepresentation & getRepresentation() const
Get OCRepresentation object.
Definition: ESRichCommon.h:117
void setCredID(int credID)
Set CloudServer's credential ID of certificate.
Definition: ESRichCommon.h:215
void setCloudID(string cloudID)
Set CloudServer's UUID.
Definition: ESRichCommon.h:205
ConnectRequestStatus(ESResult result)
Constructor.
Definition: ESRichCommon.h:1282
vector< std::string > getSupportedWiFiAuthTypes() const
Get supported WiFi authentication types by the Enrollee.
Definition: ESRichCommon.h:865
OCRepresentation m_rep
Definition: ESRichCommon.h:375
#define OC_RSRVD_ES_URI_EASYSETUP
Definition: escommon.h:74
void setCloudProp(string authCode, string authProvider, string ciServer)
Set CoapCloudConf resource properties to be delivered to Enrollee.
Definition: ESRichCommon.h:173
std::string getPassword() const
Get a password of Enroller.
Definition: ESRichCommon.h:452
void setValue(const std::string &str, const T &val)
Definition: OCRepresentation.h:142
void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
Set WiFiConf resource properties to be delivered to Enrollee.
Definition: ESRichCommon.h:425
ESResult
A result of Easy Setup.
Definition: escommon.h:154
ESResult getESResult()
Get a result of Connect request.
Definition: ESRichCommon.h:1296
2.4G and 5G
Definition: escommon.h:91
#define OC_RSRVD_ES_URI_WIFICONF
Definition: escommon.h:76
EOF.
Definition: escommon.h:92
const OCRepresentation & toOCRepresentation() const
Get OCRepresentation object.
Definition: ESRichCommon.h:500
802.11n
Definition: escommon.h:103
#define OC_RSRVD_ES_AUTHCODE
Definition: escommon.h:60
function< ESOwnershipTransferData(shared_ptr< SecProvisioningStatus >) > SecurityProvStatusCbWithOption
Callback function definition for providing Enrollee security provisioning status. ...
Definition: ESRichCommon.h:1409
GetEnrolleeStatus(ESResult result, const EnrolleeStatus &status)
Constructor.
Definition: ESRichCommon.h:1113
WEP-64.
Definition: escommon.h:124
CloudProp()
Constructor.
Definition: ESRichCommon.h:135
std::string getAuthCode() const
Get an auth code to be delivered.
Definition: ESRichCommon.h:225
2.4G
Definition: escommon.h:89
#define OC_RSRVD_ES_ENCTYPE
Definition: escommon.h:59
std::string getAuthProvider() const
Get an auth provider which issued an auth code.
Definition: ESRichCommon.h:239
Status object for provisionCloudProperties API.
Definition: ESRichCommon.h:1239
WEP.
Definition: escommon.h:113
int m_OCFServerVersion
Definition: ESRichCommon.h:1034
WIFI_FREQ
Supported WIFI frequency like 2.4G and 5G.
Definition: escommon.h:87
DeviceProp(const DeviceProp &&deviceProp)
Definition: ESRichCommon.h:400
802.11b
Definition: escommon.h:101
bool isCloudAccessible() const
Get an accessibility to cloud server of an Enrollee.
Definition: ESRichCommon.h:983
SecProvisioningStatus(string deviceUUID, ESResult result)
Definition: ESRichCommon.h:591
#define OC_RSRVD_ES_CISERVER
Definition: escommon.h:64
ESErrorCode
Indicate last error code to describe a reason of error during easy setup.
Definition: escommon.h:353
std::string m_cloudID
Definition: ESRichCommon.h:376
#define OC_RSRVD_ES_LAST_ERRORCODE
Definition: escommon.h:50
EnrolleeConf(const EnrolleeConf &&enrolleeConf)
Definition: ESRichCommon.h:713
DevicePropProvisioningStatus(ESResult result)
Constructor.
Definition: ESRichCommon.h:1209
CloudPropProvisioningStatus(ESResult result)
Constructor.
Definition: ESRichCommon.h:1245
This file contains the definition, types and APIs for resource(s) be implemented. ...
#define OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF
Definition: escommon.h:77
int getOCFSpecVersion() const
Get OCF Specification Version.
Definition: ESRichCommon.h:1027
std::string getDeviceName() const
Get a device name of Enrollee.
Definition: ESRichCommon.h:725
OCRepresentation m_rep
Definition: ESRichCommon.h:122
ESResult getESResult()
Get a result of Device property provisioning.
Definition: ESRichCommon.h:1223
function< void(string &) > SecurityPinCb
Callback definition to be invoked when the security stack expects a pin from application.
Definition: ESRichCommon.h:1414
void addChild(const OCRepresentation &)
bool getValue(const std::string &str, T &val) const
Retrieve the attribute value associated with the supplied name.
Definition: OCRepresentation.h:167
const OCRepresentation & toOCRepresentation() const
Get OCRepresentation object.
Definition: ESRichCommon.h:317
ESResult getESResult()
Get a result of Cloud property provisioning.
Definition: ESRichCommon.h:1263
OCRepresentation m_rep
Definition: ESRichCommon.h:543
#define OC_RSRVD_REPRESENTATION
For representation.
Definition: octypes.h:145
const OCRepresentation & getEasySetupRep() const
Get OCRepresentation object.
Definition: ESRichCommon.h:1017
DeviceProp(const OCRepresentation &rep)
Constructor with OCRepresentation object.
Definition: ESRichCommon.h:409
const EnrolleeStatus & getEnrolleeStatus()
Get Enrollee's status and last error code properties.
Definition: ESRichCommon.h:1138
Data class stored for provisioning of coap cloud server properties.
Definition: ESRichCommon.h:128
ESErrorCode getLastErrCode() const
Get a last error code property of Enrollee.
Definition: ESRichCommon.h:958
function< void(shared_ptr< ConnectRequestStatus >) > ConnectRequestStatusCb
Callback function definition for providing 'Connect' request status.
Definition: ESRichCommon.h:1395
#define OC_RSRVD_ES_AUTHTYPE
Definition: escommon.h:58
#define OC_RSRVD_ES_ACCESSTOKEN_TYPE
Definition: escommon.h:62
std::string getCiServer() const
Get a CI server to be delivered.
Definition: ESRichCommon.h:253
Definition: ESRichCommon.h:1305
Provisioning succeeds.
Definition: escommon.h:159
WIFI_FREQ getWiFiFreq() const
Get a WiFi supported frequency of Enrollee.
Definition: ESRichCommon.h:816
Data class stored for provisioning of Device properties which includes properties of WiFiConf resourc...
Definition: ESRichCommon.h:384
#define OC_RSRVD_ES_SSID
Definition: escommon.h:56
WIFI_AUTHTYPE getAuthType() const
Get an auth type of Enroller.
Definition: ESRichCommon.h:468
#define OC_RSRVD_RESOURCE_TYPE
To represent resource type.
Definition: octypes.h:151
int m_credID
Definition: ESRichCommon.h:377
WPA2-PSK.
Definition: escommon.h:115
#define OC_RSRVD_ES_PROVSTATUS
Attributes used to form a proper easysetup conforming JSON message.
Definition: escommon.h:49
ESResult getESResult()
Get a result of getting provisioning status and last error code of Enrollee.
Definition: ESRichCommon.h:1126
std::string getSsid() const
Get a SSID of Enroller.
Definition: ESRichCommon.h:438
Status object for provisionDeviceProperties API.
Definition: ESRichCommon.h:1203
Status object for getConfiguration API.
Definition: ESRichCommon.h:1156
EnrolleeStatus(const OCRepresentation &rep)
Constructor.
Definition: ESRichCommon.h:67
void updateOCRepresentation(int specVersion)
Update Device and Wi-Fi representation as per OCF Specification.
Definition: ESRichCommon.h:512
EnrolleeConf & getEnrolleeConf()
Get Enrollee's pre-configuration properties.
Definition: ESRichCommon.h:1188
TKIP-AES.
Definition: escommon.h:128
WIFI_ENCTYPE getEncType() const
Get an encryption type of Enroller.
Definition: ESRichCommon.h:485
int getCredID() const
Get a CI server's credential ID of certificate.
Definition: ESRichCommon.h:277
TKIP.
Definition: escommon.h:126
5G
Definition: escommon.h:90
#define OC_RSRVD_ES_SUPPORTEDWIFIENCTYPE
Definition: escommon.h:55
#define ES_RICH_COMMON_TAG
Definition: ESRichCommon.h:47
DeviceProp(const DeviceProp &deviceProp)
Definition: ESRichCommon.h:395
WIFI_ENCTYPE
WIFI encryption type of the Enroller.
Definition: escommon.h:121
#define OC_RSRVD_ES_AUTHPROVIDER
Definition: escommon.h:63
#define OC_RSRVD_ES_URI_DEVCONF
Definition: escommon.h:80
WIFI_AUTHTYPE
WIFI Authentication tlype of the Enroller.
Definition: escommon.h:110
ProvStatus getProvStatus() const
Get a provisioning status property of Enrollee.
Definition: ESRichCommon.h:87
This provide a set of getter APIs from received response for getConfiguration().
Definition: ESRichCommon.h:688
#define OC_RSRVD_ES_CRED
Definition: escommon.h:57
AES.
Definition: escommon.h:127
ESResult getESResult()
Get a result for about security provisioning is success or not.
Definition: ESRichCommon.h:667
function< void(shared_ptr< SecProvisioningStatus >) > SecurityProvStatusCb
Callback function definition for providing Enrollee security provisioning status. ...
Definition: ESRichCommon.h:1401
Status object for connect API.
Definition: ESRichCommon.h:1276
vector< WIFI_MODE > getWiFiModes() const
Get a set of WiFi supported modes of Enrollee.
Definition: ESRichCommon.h:758
bool hasAttribute(const std::string &str) const
Status object for getStatus API.
Definition: ESRichCommon.h:1107
WPA-PSK.
Definition: escommon.h:114
ESErrorCode getLastErrCode() const
Get a last error code property of Enrollee.
Definition: ESRichCommon.h:102
vector< std::string > getSupportedWiFiEncTypes() const
Get supported WiFi encryption types by the Enrollee.
Definition: ESRichCommon.h:902
EnrolleeConf(const OCRepresentation &rep)
Constructor The expected OCRepresentation is one for collection resource and has several child OCRepr...
Definition: ESRichCommon.h:698
#define OC_RSRVD_ES_URI_COAPCLOUDCONF
Definition: escommon.h:78
function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb
Callback function definition for providing Enrollee status.
Definition: ESRichCommon.h:1375
ProvStatus getProvStatus() const
Get a provisioning status property of Enrollee.
Definition: ESRichCommon.h:933
enum ESEnrolleeState ProvStatus
802.11g
Definition: escommon.h:102
Definition: OCRepresentation.h:84
CloudProp(const CloudProp &cloudProp)
Definition: ESRichCommon.h:141
CloudProp(const OCRepresentation &rep)
Constructor with OCRepresentation object.
Definition: ESRichCommon.h:159
ESResult getESResult()
Get a result of getting preconfiguration of Enrollee.
Definition: ESRichCommon.h:1176
#define OC_RSRVD_ES_SUPPORTEDWIFIMODE
Definition: escommon.h:52
EnrolleeStatus(const EnrolleeStatus &&enrolleeStatus)
Definition: ESRichCommon.h:77
#define OC_RSRVD_ES_ACCESSTOKEN
Definition: escommon.h:61
std::string getCloudID() const
Get a CI server's Uuid to be delivered.
Definition: ESRichCommon.h:267
NO authentication.
Definition: escommon.h:112
WIFI_MODE
Supported WIFI mode like 802.11g and 802.11n.
Definition: escommon.h:98