93a2c918f06a089379e4fa034ee6003ec61b9508
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / ESSCCommon.h
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 ESSC_COMMON_RICH_H_
22 #define ESSC_COMMON_RICH_H_
23
24 #include "ESRichCommon.h"
25
26 using namespace OC;
27 using namespace std;
28
29 #define SC_RSRVD_ES_VENDOR_NETCONNECTION_STATE  "x.com.samsung.ncs"
30 #define SC_RSRVD_ES_VENDOR_DISCOVERY_CHANNEL    "x.com.samsung.chn"
31 #define SC_RSRVD_ES_VENDOR_DEVICE_TYPE          "x.com.samsung.dt"
32 #define SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE       "x.com.samsung.sdt"
33 #define SC_RSRVD_ES_VENDOR_LOCATION             "x.com.samsung.location"
34 #define SC_RSRVD_ES_VENDOR_CLIENTID             "x.com.samsung.clientid"
35 #define SC_RSRVD_ES_VENDOR_ACCOUNT              "x.com.samsung.account"
36 #define SC_RSRVD_ES_VENDOR_SSO_LIST            "x.com.samsung.ssolist"
37 #define SC_RSRVD_ES_VENDOR_ADDITIONAL_AUTH_CODE "x.com.samsung.aac"
38 #define SC_RSRVD_ES_VENDOR_ACCESS_TOKEN         "x.com.samsung.accesstoken"
39 #define SC_RSRVD_ES_VENDOR_REFRESH_TOKEN        "x.com.samsung.refreshtoken"
40 #define SC_RSRVD_ES_VENDOR_UTC_DATE_TIME        "x.com.samsung.datetime"
41 #define SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME   "x.com.samsung.regionaldatetime"
42 #define SC_RSRVD_ES_VENDOR_BSSID                "x.com.samsung.bssid"
43 #define SC_RSRVD_ES_VENDOR_USERID               "x.com.samsung.uid"
44 #define SC_RSRVD_ES_VENDOR_REGISTER_MOBILE_DEV  "x.com.samsung.rmd"
45 #define SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV     "x.com.samsung.rsd"
46 #define SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO    "x.com.samsung.npi"
47 #define SC_RSRVD_ES_VENDOR_TC_STATUS            "x.com.samsung.tcstatus"
48 #define SC_RSRVD_ES_VENDOR_TC_HEADER            "x.com.samsung.tcheader"
49 #define SC_RSRVD_ES_VENDOR_TC_VERSION           "x.com.samsung.tcversion"
50 #define SC_RSRVD_ES_VENDOR_TC_RESULT            "x.com.samsung.tcresult"
51 #define SC_RSRVD_ES_VENDOR_PNP_PIN              "x.com.samsung.pnppin"
52 #define SC_RSRVD_ES_VENDOR_MODEL_NUMBER         "x.com.samsung.modelnumber"
53 #define SC_RSRVD_ES_VENDOR_LANGUAGE             "x.com.samsung.language"
54 #define SC_RSRVD_ES_VENDOR_COUNTRY              "x.com.samsung.country"
55 #define SC_RSRVD_ES_VENDOR_GPSLOCATION          "x.com.samsung.gpslocation"
56 #define SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION  "x.com.samsung.espv"
57 #define SC_RSRVD_ES_VENDOR_CANDIDATEAPS         "x.com.samsung.candidateaps"
58 #define SC_RSRVD_ES_VENDOR_SSID                 "x.com.samsung.ssid"
59 #define SC_RSRVD_ES_VENDOR_PASSPHRASE           "x.com.samsung.passphrase"
60 #define SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL    "x.com.samsung.channel"
61
62 #define MAXLEN_STRING 1000
63
64
65 namespace OIC
66 {
67     namespace Service
68     {
69
70         #define INVALID_DISCOVERY_CHANNEL -1
71
72         typedef enum
73         {
74             NET_STATE_INIT = -1,                /**< Init state **/
75             NET_STATE_WIRED_CONNECTED = 0,      /**< Wired connected **/
76             NET_STATE_WIRELESS_CONNECTED,       /**< Wireless connected **/
77             NET_STATE_NOT_CONNECTED             /**< Not connected, at all **/
78         } NETCONNECTION_STATE;
79
80         typedef enum
81         {
82             TC_STATUS_NOT_SUPPORTED = 0,
83             TC_STATUS_ALREADY_AGREED,
84             TC_STATUS_NEED_TO_AGREE,
85             TC_STATUS_DOWNLOADING_TC,
86             TC_STATUS_SUCCESS_TO_DOWNLOAD_TC,
87             TC_STATUS_FAIL_TO_DOWNLOAD_TC,
88             TC_STATUS_DISAGREED_WITH_TC,
89             TC_STATUS_GEO_BLOCKED,
90             TC_STATUS_TIMEOUT_TO_AGREE
91         } TC_STATUS;
92
93         typedef struct SCCandidateAPInfo
94         {
95             std::string ssid;
96             std::string passphrase;
97             int channel;
98             std::string bssid;
99         } SCCandidateAPInfo;
100
101         /**
102          * @brief Properties of provisioning resource. It includes a provisioning status and last
103          *        error code.
104          */
105         class SCEnrolleeStatus : public EnrolleeStatus
106         {
107         public:
108             SCEnrolleeStatus(const EnrolleeStatus&& parent) : EnrolleeStatus(parent)
109             {
110             }
111
112             /**
113              * Get a network connection state property of Enrollee.
114              *
115              * @return a network connection state property of Enrollee.
116              */
117             NETCONNECTION_STATE getNetConnectionState() const
118             {
119                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_NETCONNECTION_STATE))
120                 {
121                     return static_cast<NETCONNECTION_STATE>
122                                     (m_rep.getValue<int>(SC_RSRVD_ES_VENDOR_NETCONNECTION_STATE));
123                 }
124                 return NETCONNECTION_STATE::NET_STATE_INIT;
125             }
126
127             /**
128              * Get T&C status
129              *
130              * @return T&C Status
131              *
132              * @see TC_STATUS
133              */
134             TC_STATUS getTCStatus()
135             {
136                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_STATUS))
137                 {
138                     return static_cast<TC_STATUS>
139                             (m_rep.getValue<int>(SC_RSRVD_ES_VENDOR_TC_STATUS));
140                 }
141
142                 return TC_STATUS::TC_STATUS_NOT_SUPPORTED;
143             }
144         };
145
146         /**
147          * @brief Data class stored for Device property provisioning which includes a WiFi
148          *        and device configuration provisioning
149          */
150         class SCDeviceProp : public DeviceProp
151         {
152         public:
153
154             /**
155              * Set DevConf resource properties to be delivered to Enrollee
156              *
157              * @param language IETF language tag using ISO 639X
158              * @param country ISO Country Code (ISO 3166-1 Alpha-2)
159              * @param location location information
160              */
161             void setDevConfProp(string language, string country, string location)
162             {
163                 m_rep.setValue(SC_RSRVD_ES_VENDOR_LANGUAGE, language);
164                 m_rep.setValue(SC_RSRVD_ES_VENDOR_COUNTRY, country);
165                 m_rep.setValue(SC_RSRVD_ES_VENDOR_GPSLOCATION, location);
166             }
167
168             /**
169              * Get a language to be set. A language is expressed in IETF language tag
170              * using ISO 639X.
171              *
172              * @return a language to be set
173              */
174             std::string getLanguage() const
175             {
176                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_LANGUAGE))
177                 {
178                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_LANGUAGE);
179                 }
180                 return std::string("");
181             }
182
183             /**
184              * Get a country to be set. A country is expressed in ISO Country Code
185              * (ISO 3166-1 Alpha-2)
186              *
187              * @return a country to be set
188              */
189             std::string getCountry() const
190             {
191                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_COUNTRY))
192                 {
193                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_COUNTRY);
194                 }
195                 return std::string("");
196             }
197
198             /**
199              * Get a location to be set. A location is GPS information
200              *
201              * @return a country to be set
202              */
203             std::string getLocation() const
204             {
205                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_GPSLOCATION))
206                 {
207                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_GPSLOCATION);
208                 }
209                 return std::string("");
210             }
211
212             /**
213              * Set discoveryChannel properties to be delivered to Enrollee
214              *
215              * @param discoveryChannel Channel of the Enroller for fast discover
216              */
217             void setDiscoveryChannel(int discoveryChannel)
218             {
219                 m_rep.setValue(SC_RSRVD_ES_VENDOR_DISCOVERY_CHANNEL, discoveryChannel);
220             }
221
222             /**
223              * Get an channel of Enroller
224              *
225              * @return an channel of enroller
226              */
227             int getDiscoveryChannel()
228             {
229                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_DISCOVERY_CHANNEL))
230                 {
231                     return m_rep.getValue<int>(SC_RSRVD_ES_VENDOR_DISCOVERY_CHANNEL);
232                 }
233                 return INVALID_DISCOVERY_CHANNEL;
234             }
235
236             /**
237              * Set samsung-specific location property to be delivered to Enrollee
238              *
239              * @param locations a set of location information
240              */
241             void setSCLocation(const std::vector<std::string> &locations)
242             {
243                 m_rep.setValue(SC_RSRVD_ES_VENDOR_LOCATION, locations);
244             }
245
246             /**
247              * Set samsung account property to be delivered to Enrollee (for TV)
248              *
249              * @param account a samsung account ID information (for TV)
250              */
251             void setSCAccount(const std::string &account)
252             {
253                 m_rep.setValue(SC_RSRVD_ES_VENDOR_ACCOUNT, account);
254             }
255
256             /**
257              * Set UTC date time property to be delivered to Enrollee.
258              * The format is "[yyyy]-[mm]-[dd]T[hh]:[mm]:[ss]Z"
259              *
260              * @param datetime UTC date time
261              */
262             void setUTCDatetime(const std::string &datetime)
263             {
264                 m_rep.setValue(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME, datetime);
265             }
266
267             /**
268              * Get UTC date time property
269              *
270              * @return UTC date time
271              */
272             std::string getUTCDatetime()
273             {
274                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME))
275                 {
276                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME);
277                 }
278                 return {};
279             }
280
281             /**
282              * Set regional date time property to be delivered to Enrollee.
283              * The format is "[yyyy]-[mm]-[dd]T[hh]:[mm]:[ss]Z"
284              *
285              * @param datetime Regional date time
286              */
287             void setRegionalDatetime(const std::string &datetime)
288             {
289                 m_rep.setValue(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME, datetime);
290             }
291
292             /**
293              * Get regional date time property
294              *
295              * @return Date time
296              */
297             std::string getRegionalDatetime()
298             {
299                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME))
300                 {
301                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME);
302                 }
303                 return {};
304             }
305
306             /**
307              * Set Mobile device information used for 'register TV'
308              * The format is in json. The key indicates the meaning of value and the value is a
309              * corresponding information. Supported keys include: wm(Wifi MAC), pm(P2P MAC),
310              * bm(BT MAC), dn(device name), dt(device type), it(icon type).
311              *
312              * @param regMobileDev register mobile device
313              */
314             void setRegisterMobileDevice(const std::string &regMobileDev)
315             {
316                 m_rep.setValue(SC_RSRVD_ES_VENDOR_REGISTER_MOBILE_DEV, regMobileDev);
317             }
318
319             /**
320              * Get Mobile device information used for 'register TV'
321              *
322              * @return register mobile device
323              */
324             std::string getRegisterMobileDevice()
325             {
326                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGISTER_MOBILE_DEV))
327                 {
328                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGISTER_MOBILE_DEV);
329                 }
330                 return {};
331             }
332
333             /**
334              * Set a BSSID of Enroller
335              *
336              * @param a BSSID of enroller
337              */
338             void setBSSID(const std::string &bssid)
339             {
340                 m_rep.setValue(SC_RSRVD_ES_VENDOR_BSSID, bssid);
341             }
342
343             /**
344              * Get a BSSID of Enroller
345              *
346              * @return a BSSID of enroller
347              */
348             std::string getBSSID()
349             {
350                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_BSSID))
351                 {
352                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_BSSID);
353                 }
354                 return {};
355             }
356
357             /**
358              * Set SSO list information
359              *
360              * @param  SSO list
361              */
362             void setSSOList(const std::string &ssoList)
363             {
364                 m_rep.setValue(SC_RSRVD_ES_VENDOR_SSO_LIST, ssoList);
365             }
366
367             /**
368              * Get SSO List information which is registered in device
369              *
370              * @return SSO List
371              */
372             std::string getSSOList()
373             {
374                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSO_LIST))
375                 {
376                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_SSO_LIST);
377                 }
378                 return {};
379             }
380
381              /**
382              * Set Candidate AP information which is stored.
383              *
384              * @param clientID - Client service ID
385              */
386             void setCandidateAPList(SCCandidateAPInfo *candidateInfo,int numCandidateAP)
387             {
388                 std::vector<OC::OCRepresentation> candidateAPList;
389                 for (int i=0;i<numCandidateAP;i++)
390                 {
391                             OCRepresentation candidateListInfo;
392                             candidateListInfo.setValue(SC_RSRVD_ES_VENDOR_BSSID, candidateInfo[i].bssid);
393                             candidateListInfo.setValue(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL, candidateInfo[i].channel);
394                             candidateListInfo.setValue(SC_RSRVD_ES_VENDOR_PASSPHRASE, candidateInfo[i].passphrase);
395                             candidateListInfo.setValue(SC_RSRVD_ES_VENDOR_SSID, candidateInfo[i].ssid);
396                             candidateAPList.push_back(candidateListInfo);
397                 }
398                 m_rep.setValue(SC_RSRVD_ES_VENDOR_CANDIDATEAPS, candidateAPList);
399             }
400
401              /**
402              * Get Candidate AP information which is registered in device.
403              *
404              * @return SCCandidateAPInfo list.
405              */
406             std::vector<SCCandidateAPInfo> getCandidateAPList()
407             {
408                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
409                 {
410                     std::vector<OC::OCRepresentation> candidateInfo=
411                                 m_rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
412                     std::vector<SCCandidateAPInfo> postcandidateInfo;
413                     for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
414                               it != candidateInfo.end(); ++it)
415                     {
416                         OC::OCRepresentation rep = *it;
417                         SCCandidateAPInfo candidateInfotemp;
418                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSID))
419                         {
420                             candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_SSID);
421                         }
422                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_PASSPHRASE))
423                         {
424                             candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_PASSPHRASE);
425                         }
426                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
427                         {
428                             candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
429
430                         }
431                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_BSSID))
432                         {
433                             candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_BSSID);
434                         }
435                         postcandidateInfo.push_back(candidateInfotemp);
436                     }
437                     return postcandidateInfo;
438                 }
439                 return {};
440             }
441         };
442
443         class SCCloudProp : public CloudProp
444         {
445             public:
446             /**
447              * Set samsung-specific client service ID property to be delivered to Enrollee
448              *
449              * @param clientID - Client service ID
450              */
451             void setClientID(const std::string &clientID)
452             {
453                 m_rep.setValue(SC_RSRVD_ES_VENDOR_CLIENTID, clientID);
454             }
455
456             /**
457              * Get samsung-specific client service ID property.
458              *
459              * @return Client service ID.
460              */
461             std::string getClientID()
462             {
463                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_CLIENTID))
464                 {
465                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_CLIENTID);
466                 }
467                 return {};
468             }
469
470             /**
471              * Set samsung-specific additional AuthCode property to be delivered to Enrollee (for TV/AV sign up VD SSO)
472              *
473              * @param additionalAuthcode - additional AuthCode (for TV/AV sign up VD SSO)
474              */
475             void setAdditionalAuthCode(const std::string &additionalAuthcode)
476             {
477                 m_rep.setValue(SC_RSRVD_ES_VENDOR_ADDITIONAL_AUTH_CODE, additionalAuthcode);
478             }
479
480             /**
481              * Set samsung-specific refresh token property to be delivered to Enrollee
482              *
483              * @param refreshtoken - Refresh token.
484              */
485             void setRefreshToken(const std::string &refreshtoken)
486             {
487                 m_rep.setValue(SC_RSRVD_ES_VENDOR_REFRESH_TOKEN, refreshtoken);
488             }
489
490             /**
491              * Get samsung-specific refresh token property.
492              *
493              * @return refreshtoken - Refresh token.
494              */
495             std::string getRefreshToken()
496             {
497                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_REFRESH_TOKEN))
498                 {
499                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REFRESH_TOKEN);
500                 }
501                 return {};
502             }
503
504             /**
505              * Set samsung-specific user ID property to be delivered to Enrollee
506              *
507              * @param uid - user ID.
508              */
509             void setUserID(const std::string &uid)
510             {
511                 m_rep.setValue(SC_RSRVD_ES_VENDOR_USERID, uid);
512             }
513
514             /**
515              * Get samsung-specific user ID property
516              *
517              * @return uid - user ID.
518              */
519             std::string getUserID()
520             {
521                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_USERID))
522                 {
523                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_USERID);
524                 }
525                 return {};
526             }
527
528             /**
529              * Set T&C Result
530              * Indicates T&C result by mobile user in json format.
531              *
532              * @param uid - user ID.
533              */
534             void setTCResult(const std::string &result)
535             {
536                 m_rep.setValue(SC_RSRVD_ES_VENDOR_TC_RESULT, result);
537             }
538
539             /**
540              * Get T&C Result
541              *
542              * @return uid - user ID.
543              */
544             std::string getTCResult()
545             {
546                 if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_RESULT))
547                 {
548                     return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_TC_RESULT);
549                 }
550                 return {};
551             }
552         };
553
554         /**
555          * @breif This provide a set of getter APIs from received response for getConfiguration().
556          *        Received information includes a device name, WiFi supported mode, and frequency.
557          *        Additionally, you can know if Enrollee can be access to cloud server with this
558          *        object.
559          */
560         class SCEnrolleeConf : public EnrolleeConf
561         {
562         public:
563             SCEnrolleeConf(const EnrolleeConf&& parent) : EnrolleeConf(parent)
564             {
565             }
566
567             /**
568              * Get a model number of Enrollee.
569              *
570              * @return a model number of Enrollee
571              */
572             std::string getModelNumber() const
573             {
574                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
575                 for(auto child = children.begin(); child != children.end(); ++child)
576                 {
577                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
578                     {
579                         OCRepresentation rep;
580                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
581                         {
582                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
583                         }
584                         else
585                         {
586                             return std::string("");
587                         }
588
589                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_MODEL_NUMBER))
590                         {
591                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_MODEL_NUMBER);
592                         }
593                     }
594                 }
595                 return std::string("");
596             }
597
598             /**
599              * Get a device type of Enrollee.
600              * It is Device's human-friendly name like device model name.
601              *
602              * @return a device type of Enrollee
603              */
604             std::string getDeviceType() const
605             {
606                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
607                 for(auto child = children.begin(); child != children.end(); ++child)
608                 {
609                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
610                     {
611                         OCRepresentation rep;
612                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
613                         {
614                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
615                         }
616                         else
617                         {
618                             return std::string("");
619                         }
620
621                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_DEVICE_TYPE))
622                         {
623                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_DEVICE_TYPE);
624                         }
625                     }
626                 }
627                 return std::string("");
628             }
629
630             /**
631              * Get a device sub-type of Enrollee.
632              * It is Device's human-friendly name like device model name.
633              *
634              * @return a device sub-type of Enrollee
635              */
636             std::string getDeviceSubType() const
637             {
638                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
639                 for(auto child = children.begin(); child != children.end(); ++child)
640                 {
641                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
642                     {
643                         OCRepresentation rep;
644                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
645                         {
646                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
647                         }
648                         else
649                         {
650                             return std::string("");
651                         }
652
653                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE))
654                         {
655                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE);
656                         }
657                     }
658                 }
659                 return std::string("");
660             }
661
662             /**
663              * Get Set device information used for 'register TV'
664              * The format is in json. The key indicates the meaning of value and the value is a
665              * corresponding information. Supported keys include: wm(Wifi MAC), pm(P2P MAC),
666              * bm(BT MAC), rt(Remote Type)
667              *
668              * @return Register Set Device
669              */
670             std::string getRegisterSetDevice() const
671             {
672                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
673                 for(auto child = children.begin(); child != children.end(); ++child)
674                 {
675                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
676                     {
677                         OCRepresentation rep;
678                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
679                         {
680                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
681                         }
682                         else
683                         {
684                             return std::string("");
685                         }
686
687                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV))
688                         {
689                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV);
690                         }
691                     }
692                 }
693                 return std::string("");
694             }
695
696             /**
697             * Get Candidate AP information which is registered in device.
698             *
699             * @return SCCandidateAPInfo list.
700             */
701             std::vector<SCCandidateAPInfo> getCandidateAPList() const
702             {
703                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
704                 for(auto child = children.begin(); child != children.end(); ++child)
705                 {
706                     if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
707                     {
708                         OCRepresentation rep;
709                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
710                         {
711                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
712                         }
713
714                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS))
715                         {
716                             std::vector<OC::OCRepresentation> candidateInfo=rep.getValue<std::vector<OC::OCRepresentation>>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS);
717                             std::vector<SCCandidateAPInfo> postcandidateInfo;
718                             for(std::vector<OC::OCRepresentation>::iterator it = candidateInfo.begin();
719                                       it != candidateInfo.end(); ++it)
720                             {
721                                 OC::OCRepresentation rep = *it;
722                                 SCCandidateAPInfo candidateInfotemp;
723                                 if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSID))
724                                 {
725                                     candidateInfotemp.ssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_SSID);
726                                 }
727                                 if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_PASSPHRASE))
728                                 {
729                                     candidateInfotemp.passphrase=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_PASSPHRASE);
730                                 }
731                                 if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL))
732                                 {
733                                     candidateInfotemp.channel=rep.getValue<int>(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL);
734
735                                 }
736                                 if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_BSSID))
737                                 {
738                                     candidateInfotemp.bssid=rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_BSSID);
739                                 }
740                                 postcandidateInfo.push_back(candidateInfotemp);
741                             }
742                             return postcandidateInfo;
743                         }
744                     }
745                 }
746             }
747
748             /**
749              * Get network provisioning information for the device.
750              * Mediator can use this information to enquire & validate registration status with corresponding Network Vendor.
751              * The format is in JSON. The key indicates the meaning of value and the value is a
752              * corresponding information. Supported keys include: IMEI (IMEI Number), IMSI (IMSI Number),
753              * MCC_MNC(MCC & MNC Number), SN(Serial Number)
754              *
755              * @return Network Provisioning Information String.
756              */
757             std::string getNetworkProvisioningInfo() const
758             {
759                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
760                 for(auto child = children.begin(); child != children.end(); ++child)
761                 {
762                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
763                     {
764                         OCRepresentation rep;
765                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
766                         {
767                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
768                         }
769                         else
770                         {
771                             return std::string("");
772                         }
773
774                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO))
775                         {
776                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO);
777                         }
778                     }
779                 }
780                 return std::string("");
781             }
782
783             /**
784              * Get SSO List information for the device.
785              * The format is in JSON. The key indicates the meaning of value and the value is a
786              * corresponding information. Supported keys include: Available Count , Registered Count,
787              * Account List
788              *
789              * @return SSo List Information String.
790              */
791             std::string getSSOList() const
792             {
793                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
794                 for(auto child = children.begin(); child != children.end(); ++child)
795                 {
796                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
797                     {
798                         OCRepresentation rep;
799                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
800                         {
801                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
802                         }
803                         else
804                         {
805                             return std::string("");
806                         }
807
808                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSO_LIST))
809                         {
810                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_SSO_LIST);
811                         }
812                     }
813                 }
814                 return std::string("");
815             }
816
817             /**
818              * Get T&C status
819              * Indicates T&C is already agreed or not.
820              *
821              * @return T&C Status
822              *
823              * @see TC_STATUS
824              */
825             TC_STATUS getTCStatus()
826             {
827                 OCRepresentation rep;
828                 if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
829                 {
830                     rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
831                 }
832                 else
833                 {
834                     return TC_STATUS::TC_STATUS_NOT_SUPPORTED;
835                 }
836
837                 if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_STATUS))
838                 {
839                     return static_cast<TC_STATUS>
840                             (rep.getValue<int>(SC_RSRVD_ES_VENDOR_TC_STATUS));
841                 }
842
843                 return TC_STATUS::TC_STATUS_NOT_SUPPORTED;
844             }
845
846             /**
847              * Get T&C Header
848              * T&C Header Information in json format
849              *
850              * @return T&C Header
851              */
852             std::string getTCHeader()
853             {
854                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
855                 for(auto child = children.begin(); child != children.end(); ++child)
856                 {
857                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
858                     {
859                         OCRepresentation rep;
860                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
861                         {
862                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
863                         }
864                         else
865                         {
866                             return std::string("");
867                         }
868
869                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_HEADER))
870                         {
871                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_TC_HEADER);
872                         }
873                     }
874                 }
875                 return std::string("");
876             }
877
878             /**
879              * Get T&C Version
880              *
881              * @return T&C Version
882              */
883             std::string getTCVersion()
884             {
885                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
886                 for(auto child = children.begin(); child != children.end(); ++child)
887                 {
888                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
889                     {
890                         OCRepresentation rep;
891                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
892                         {
893                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
894                         }
895                         else
896                         {
897                             return std::string("");
898                         }
899
900                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_TC_VERSION))
901                         {
902                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_TC_VERSION);
903                         }
904                     }
905                 }
906                 return std::string("");
907             }
908
909             /**
910              * Get PnP Pin
911              *
912              * @return PnP Pin
913              */
914             std::string getPnpPin() const
915             {
916                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
917                 for(auto child = children.begin(); child != children.end(); ++child)
918                 {
919                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
920                     {
921                         OCRepresentation rep;
922                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
923                         {
924                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
925                         }
926                         else
927                         {
928                             return std::string("");
929                         }
930
931                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_PNP_PIN))
932                         {
933                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_PNP_PIN);
934                         }
935                     }
936                 }
937                 return std::string("");
938             }
939
940             /**
941              * Get a network connection state property of Enrollee.
942              *
943              * @return a network connection state property of Enrollee.
944              */
945             NETCONNECTION_STATE getNetConnectionState() const
946             {
947                 OCRepresentation rep;
948                 if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
949                 {
950                     rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
951                 }
952                 else
953                 {
954                     return NETCONNECTION_STATE::NET_STATE_INIT;
955                 }
956
957                 if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_NETCONNECTION_STATE))
958                 {
959                     return static_cast<NETCONNECTION_STATE>
960                                     (rep.getValue<int>(SC_RSRVD_ES_VENDOR_NETCONNECTION_STATE));
961                 }
962
963                 return NETCONNECTION_STATE::NET_STATE_INIT;
964             }
965
966             /**
967              * Get a BSSID of Enroller
968              *
969              * @return a BSSID of enroller
970              */
971             std::string getBSSID() const
972             {
973                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
974                 for(auto child = children.begin(); child != children.end(); ++child)
975                 {
976                     if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
977                     {
978                         OCRepresentation rep;
979                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
980                         {
981                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
982                         }
983                         else
984                         {
985                             return std::string("");
986                         }
987
988                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_BSSID))
989                         {
990                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_BSSID);
991                         }
992                     }
993                 }
994                 return {};
995             }
996
997             /**
998              * Get UTC date time
999              *
1000              * @return UTC date time
1001              */
1002             std::string getUTCDatetime() const
1003             {
1004                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
1005                 for(auto child = children.begin(); child != children.end(); ++child)
1006                 {
1007                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
1008                     {
1009                         OCRepresentation rep;
1010                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
1011                         {
1012                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
1013                         }
1014                         else
1015                         {
1016                             return std::string("");
1017                         }
1018
1019                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME))
1020                         {
1021                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_UTC_DATE_TIME);
1022                         }
1023                     }
1024                 }
1025                 return {};
1026             }
1027
1028             /**
1029              * Get regional date time
1030              *
1031              * @return date time
1032              */
1033             std::string getRegionalDatetime() const
1034             {
1035                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
1036                 for(auto child = children.begin(); child != children.end(); ++child)
1037                 {
1038                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
1039                     {
1040                         OCRepresentation rep;
1041                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
1042                         {
1043                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
1044                         }
1045                         else
1046                         {
1047                             return std::string("");
1048                         }
1049
1050                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME))
1051                         {
1052                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME);
1053                         }
1054                     }
1055                 }
1056                 return {};
1057             }
1058
1059             /**
1060              * Get Samsung Easy Setup Protocol Version.
1061              *
1062              * Mediator can use this API to differentiate between Easy Setup Protcol supported by
1063              * Samsung Enrollee Devices.
1064              *
1065              * Example: Version Value for Tizen4.0: [\932.0\94]
1066              *
1067              * @return Easy Setup Protocol Version String.
1068              */
1069             std::string getESProtocolVersion() const
1070             {
1071                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
1072                 for(auto child = children.begin(); child != children.end(); ++child)
1073                 {
1074                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
1075                     {
1076                         OCRepresentation rep;
1077                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
1078                         {
1079                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
1080                         }
1081                         else
1082                         {
1083                             return std::string("");
1084                         }
1085
1086                         if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION))
1087                         {
1088                             return rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION);
1089                         }
1090                     }
1091                 }
1092                 return std::string("");
1093             }
1094
1095         };
1096     }
1097 }
1098
1099 #endif //ESSC_COMMON_RICH_H_