Modified additional field
[platform/upstream/iotivity.git] / service / easy-setup / enrollee / src / samsung / sc_easysetup.c
1 //******************************************************************
2 //
3 // Copyright 2015 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
22 #include "samsung/sc_easysetup.h"
23 #include "string.h"
24 #include "oic_malloc.h"
25 #include "logger.h"
26 #include "stdio.h"
27
28 #include "ocpayload.h"
29 #include "oic_string.h"
30 #include "oic_malloc.h"
31
32 #include "resourcehandler.h"
33
34 /**
35  * @var SC_ENROLLEE_TAG
36  * @brief Logging tag for module name.
37  */
38 #define SC_ENROLLEE_TAG "ES_SC_ENROLLEE"
39
40 SCProperties g_SCProperties;
41
42 static void ReadAccountData(OCRepPayload* payload,void** userdata);
43 static void ReadTnCdata(OCRepPayload* payload,void** userdata);
44 static void WriteTnCdata(OCRepPayload* payload, char* resourceType);
45 static void WriteWifiData(OCRepPayload* payload, char* resourceType);
46
47 ESResult SetSCProperties(const SCProperties *prop)
48 {
49     OIC_LOG(INFO, SC_ENROLLEE_TAG, "SetSCProperties IN");
50     if(prop != NULL)
51     {
52         memcpy(&g_SCProperties, prop, sizeof(SCProperties));
53         OIC_LOG(INFO, SC_ENROLLEE_TAG, "SetSCProperties OUT");
54         return ES_OK;
55     }
56     OIC_LOG(INFO, SC_ENROLLEE_TAG, "SetSCProperties OUT");
57     return ES_ERROR;
58 }
59
60 static void ReadAccountData(OCRepPayload* payload,void** userdata)
61 {
62     OIC_LOG(INFO, SC_ENROLLEE_TAG, "ReadAccountData IN");
63
64     char* account = NULL;
65
66     if(OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_ACCOUNT, &account))
67     {
68         if(*userdata == NULL)
69         {
70             *userdata = (void*)OICMalloc(sizeof(SCDevConfProperties));
71             if( *userdata == NULL )
72             {
73                 OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCDevConfProperties is failed");
74                 OICFree(account);
75                 return;
76             }
77         }
78
79         SCDevConfProperties *pDevConfProp = (SCDevConfProperties*)(*userdata);
80         OICStrcpy(pDevConfProp->account, MAXLEN_STRING, account);
81         OICStrcpy(g_SCProperties.account, MAXLEN_STRING, account);
82
83         OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
84                 SC_RSRVD_ES_VENDOR_ACCOUNT, pDevConfProp->account);
85
86         OICFree(account);
87     }
88     OIC_LOG(INFO, SC_ENROLLEE_TAG, "ReadAccountData OUT");
89
90 }
91
92 ESResult SetSCTncInfo(SCTncInfo *tncInfo)
93 {
94     if(tncInfo == NULL)
95     {
96         return ES_ERROR;
97     }
98     g_SCProperties.tncInfo = *tncInfo;
99     return ES_OK;
100 }
101
102 ESResult SetSCTncStatus(int status)
103 {
104     g_SCProperties.tncStatus = status;
105     return ES_OK;
106 }
107
108 ESResult SetSCNetConnectionState(NETCONNECTION_STATE netConnectionState)
109 {
110     OIC_LOG(INFO, SC_ENROLLEE_TAG, "SetSCNetConnectionState IN");
111
112     OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "SetSCNetConnectionState: %d", netConnectionState);
113     g_SCProperties.netConnectionState = netConnectionState;
114
115     if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
116     {
117         OIC_LOG(DEBUG, SC_ENROLLEE_TAG, "provResource doesn't have any observers.");
118     }
119
120     OIC_LOG(INFO, SC_ENROLLEE_TAG, "SetSCNetConnectionState OUT");
121     return ES_OK;
122 }
123
124 static void ReadTnCdata(OCRepPayload* payload,void** userdata)
125 {
126     OIC_LOG(INFO, SC_ENROLLEE_TAG, "ReadTnCdata IN");
127
128     char* tncResult = NULL;
129
130     if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_TNC_RESULT, &tncResult))
131     {
132         if(*userdata == NULL)
133         {
134             *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
135             if( *userdata == NULL )
136             {
137                 OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
138                 return ;
139             }
140         }
141
142         SCCoapCloudServerConfProperties *pProp = (SCCoapCloudServerConfProperties*)(*userdata);
143         OICStrcpy(pProp->tncResult, MAXLEN_STRING, tncResult);
144         OICStrcpy(g_SCProperties.tncResult, MAXLEN_STRING, tncResult);
145
146         OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
147                 SC_RSRVD_ES_VENDOR_TNC_RESULT, pProp->tncResult);
148     }
149
150     OIC_LOG(INFO, SC_ENROLLEE_TAG, "ReadTnCdata OUT");
151 }
152
153 void WriteTnCdata(OCRepPayload* payload, char* resourceType)
154 {
155     OIC_LOG(INFO, SC_ENROLLEE_TAG, "WriteTnCdata IN");
156
157     if(payload == NULL || resourceType == NULL)
158     {
159         OIC_LOG(DEBUG, SC_ENROLLEE_TAG, "Invalid Params payload or resourceType is NULL");
160         OIC_LOG(DEBUG, SC_ENROLLEE_TAG, "WriteTnCdata OUT");
161         return;
162     }
163     if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_EASYSETUP))
164     {
165         OCRepPayloadSetPropInt(payload, SC_RSRVD_ES_VENDOR_TNC_STATUS, g_SCProperties.tncStatus);
166     }
167     else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF))
168     {
169         OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_TNC_HEADER,
170                 g_SCProperties.tncInfo.header);
171         OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_TNC_VERSION,
172                 g_SCProperties.tncInfo.version);
173     }
174     else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF))
175     {
176         OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_TNC_RESULT,
177                 g_SCProperties.tncResult);
178     }
179     OIC_LOG(INFO, SC_ENROLLEE_TAG, "WriteTnCdata OUT");
180 }
181
182 void WriteWifiData(OCRepPayload* payload, char* resourceType)
183 {
184     OIC_LOG(INFO, SC_ENROLLEE_TAG, "WriteWifiData IN");
185
186     if(payload == NULL || resourceType == NULL)
187     {
188         OIC_LOG(DEBUG, SC_ENROLLEE_TAG, "Invalid Params payload or resourceType is NULL");
189         OIC_LOG(DEBUG, SC_ENROLLEE_TAG, "WriteWifiData OUT");
190         return;
191     }
192
193     if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFICONF))
194     {
195         OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_BSSID,
196                 g_SCProperties.bssid);
197     }
198     OIC_LOG(INFO, SC_ENROLLEE_TAG, "WriteWifiData OUT");
199 }
200
201 ESResult SetRegisterSetDevice(const char *regSetDevice)
202 {
203     if(regSetDevice != NULL)
204     {
205         OICStrcpy(g_SCProperties.regSetDev, sizeof(g_SCProperties.regSetDev), regSetDevice);
206         return ES_OK;
207     }
208     return ES_ERROR;
209 }
210
211 ESResult SetNetworkProvInfo(const char *nwProvInfo)
212 {
213     if(nwProvInfo != NULL)
214     {
215         OICStrcpy(g_SCProperties.nwProvInfo, sizeof(g_SCProperties.nwProvInfo), nwProvInfo);
216         return ES_OK;
217     }
218     return ES_ERROR;
219 }
220
221 ESResult SetSCPnPPin(const char *pnp)
222 {
223     if(pnp != NULL)
224     {
225         OICStrcpy(g_SCProperties.pnpPin, sizeof(g_SCProperties.pnpPin), pnp);
226         return ES_OK;
227     }
228     return ES_ERROR;
229 }
230
231 ESResult SetESVersionInfo(const char *esProtocolVersion)
232 {
233     if(esProtocolVersion != NULL)
234     {
235         OICStrcpy(g_SCProperties.esProtocolVersion, sizeof(g_SCProperties.esProtocolVersion), esProtocolVersion);
236         return ES_OK;
237     }
238     return ES_ERROR;
239 }
240
241 ESResult SetSSOList(const char *ssoList)
242 {
243     if(ssoList != NULL)
244     {
245         OICStrcpy(g_SCProperties.ssoList, sizeof(g_SCProperties.ssoList), ssoList);
246         return ES_OK;
247     }
248     return ES_ERROR;
249 }
250
251 void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
252 {
253     OIC_LOG(INFO, SC_ENROLLEE_TAG, "ReadUserdataCb IN");
254
255     if(payload != NULL)
256     {
257         if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFICONF))
258         {
259             int64_t channel = -1;
260             char *bssid = NULL;
261             bool isHidden = false;
262             if (OCRepPayloadGetPropInt(payload, SC_RSRVD_ES_VENDOR_DISCOVERY_CHANNEL, &channel))
263             {
264                 if(*userdata == NULL)
265                 {
266                     *userdata = (void*)OICMalloc(sizeof(SCWiFiConfProperties));
267                     if( *userdata == NULL )
268                     {
269                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCWiFiConfProperties is failed");
270                         return ;
271                     }
272                     memset(*userdata, 0, sizeof(SCWiFiConfProperties));
273                 }
274                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : [%" PRId64 "]",
275                                                             SC_RSRVD_ES_VENDOR_DISCOVERY_CHANNEL, channel);
276                 ((SCWiFiConfProperties*)(*userdata))->discoveryChannel = (int) channel;
277                 g_SCProperties.discoveryChannel = channel;
278             }
279             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_BSSID, &bssid))
280             {
281                 if(*userdata == NULL)
282                 {
283                     *userdata = (void*) OICMalloc(sizeof(SCWiFiConfProperties));
284                     if( *userdata == NULL )
285                     {
286                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCWiFiConfProperties is failed");
287                         return ;
288                     }
289                     memset(*userdata, 0, sizeof(SCWiFiConfProperties));
290                 }
291                 if (*userdata != NULL)
292                 {
293                     OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
294                             SC_RSRVD_ES_VENDOR_BSSID, bssid);
295                     SCWiFiConfProperties* pWifiConfProp = (SCWiFiConfProperties*)(*userdata);
296                     OICStrcpy(pWifiConfProp->bssid, sizeof(pWifiConfProp->bssid), bssid);
297                     OICStrcpy(g_SCProperties.bssid, sizeof(g_SCProperties.bssid), bssid);
298                     OICFree(bssid);
299                 }
300             }
301
302             OCRepPayload **repPayload = NULL;
303             size_t dimensions[MAX_REP_ARRAY_DEPTH];
304             if(OCRepPayloadGetPropObjectArray(payload, SC_RSRVD_ES_VENDOR_CANDIDATEAPS, &repPayload, dimensions))
305             {
306                 if(*userdata == NULL)
307                 {
308                     *userdata = (void*) OICMalloc(sizeof(SCWiFiConfProperties));
309                     if( *userdata == NULL )
310                     {
311                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCWiFiConfProperties is failed");
312                         return ;
313                     }
314                     memset(*userdata, 0, sizeof(SCWiFiConfProperties));
315                 }
316                 //size_t dim = calcDimTotal(dimensions);
317                 SCWiFiConfProperties* pWifiConfProp = (SCWiFiConfProperties*)(*userdata);
318                 for (size_t i = 0; i < dimensions[0]; i++)
319                 {
320                    int64_t cdChannel = -1;
321                    char *cdBssid = NULL;
322                    char *cdSsid = NULL;
323                    char *cdPwd = NULL;
324                    if (OCRepPayloadGetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_SSID, &cdSsid))
325                    {
326                        OICStrcpy(pWifiConfProp->candidateAPInfo[i].ssid, sizeof(pWifiConfProp->candidateAPInfo[i].ssid), cdSsid);
327                        OICStrcpy(g_SCProperties.candidateAPInfo[i].ssid, sizeof(g_SCProperties.candidateAPInfo[i].ssid), cdSsid);
328                        OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
329                             SC_RSRVD_ES_VENDOR_CANDIDATE_SSID, cdSsid);
330                        OICFree(cdSsid);
331                    }
332                    if (OCRepPayloadGetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE, &cdPwd))
333                    {
334                        OICStrcpy(pWifiConfProp->candidateAPInfo[i].passphrase, sizeof(pWifiConfProp->candidateAPInfo[i].passphrase), cdPwd);
335                        OICStrcpy(g_SCProperties.candidateAPInfo[i].passphrase, sizeof(g_SCProperties.candidateAPInfo[i].passphrase), cdPwd);
336                        OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
337                             SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE, cdPwd);
338                        OICFree(cdPwd);
339                    }
340                    if (OCRepPayloadGetPropInt(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL, &cdChannel))
341                    {
342                        pWifiConfProp->candidateAPInfo[i].channel = (int) cdChannel;
343                        g_SCProperties.candidateAPInfo[i].channel = cdChannel;
344                        OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %d",
345                             SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL, (int) cdChannel);
346                    }
347                    if (OCRepPayloadGetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID, &cdBssid))
348                    {
349                        OICStrcpy(pWifiConfProp->candidateAPInfo[i].bssid, sizeof(pWifiConfProp->candidateAPInfo[i].bssid), cdBssid);
350                        OICStrcpy(g_SCProperties.candidateAPInfo[i].bssid, sizeof(g_SCProperties.candidateAPInfo[i].bssid), cdBssid);
351                        OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
352                             SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID, cdBssid);
353                        OICFree(cdBssid);
354                    }
355                 }
356                 pWifiConfProp->numCandidateAP = (int)dimensions[0];
357                 g_SCProperties.numCandidateAP = (int)dimensions[0];
358             }
359
360             if (OCRepPayloadGetPropBool(payload, SC_RSRVD_ES_VENDOR_HIDDEN, &isHidden))
361             {
362                 if(*userdata == NULL)
363                 {
364                     *userdata = (void*)OICMalloc(sizeof(SCWiFiConfProperties));
365                     if( *userdata == NULL )
366                     {
367                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCWiFiConfProperties is failed");
368                         return ;
369                     }
370                     memset(*userdata, 0, sizeof(SCWiFiConfProperties));
371                 }
372                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %d",
373                                                             SC_RSRVD_ES_VENDOR_HIDDEN, isHidden);
374                 ((SCWiFiConfProperties*)(*userdata))->isHidden = isHidden;
375                 g_SCProperties.isHidden = isHidden;
376             }
377         }
378         else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF))
379         {
380             if(*userdata == NULL)
381             {
382                 *userdata = (void*)OICMalloc(sizeof(SCDevConfProperties));
383                 if( *userdata == NULL )
384                 {
385                     OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCDevConfProperties is failed");
386                     return ;
387                 }
388                 memset(*userdata, 0, sizeof(SCDevConfProperties));
389             }
390
391             SCDevConfProperties *pDevConfProp = (SCDevConfProperties*)(*userdata);
392
393             char**locationList = NULL;
394             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0};
395             if(OCRepPayloadGetStringArray(payload, SC_RSRVD_ES_VENDOR_LOCATION, &locationList, dimensions))
396             {
397                 for(size_t idx = 0; idx < dimensions[0]; idx++)
398                 {
399                     OICStrcpy(pDevConfProp->location[idx], strlen(locationList[idx])+1, locationList[idx]);
400                     OICStrcpy(g_SCProperties.location[idx], strlen(locationList[idx])+1, locationList[idx]);
401
402                     OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
403                                         SC_RSRVD_ES_VENDOR_LOCATION, pDevConfProp->location[idx]);
404                 }
405
406                 ((SCDevConfProperties*)(*userdata))->numLocation = (int)dimensions[0];
407                 g_SCProperties.numLocation = (int)dimensions[0];
408             }
409
410             ReadAccountData(payload,userdata);
411
412             char *regMobileDev = NULL;
413             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_REGISTER_MOBILE_DEV, &regMobileDev))
414             {
415                 OICStrcpy(pDevConfProp->regMobileDev, strlen(regMobileDev)+1, regMobileDev);
416                 OICStrcpy(g_SCProperties.regMobileDev, strlen(regMobileDev)+1, regMobileDev);
417                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.regMobileDev %s", g_SCProperties.regMobileDev);
418             }
419
420             char *country = NULL;
421             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_COUNTRY, &country))
422             {
423                 OICStrcpy(pDevConfProp->country, strlen(country)+1, country);
424                 OICStrcpy(g_SCProperties.country, strlen(country)+1, country);
425                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.country %s", g_SCProperties.country);
426             }
427
428             char *language = NULL;
429             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_LANGUAGE, &language))
430             {
431                 OICStrcpy(pDevConfProp->language, strlen(language)+1, language);
432                 OICStrcpy(g_SCProperties.language, strlen(language)+1, language);
433                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.language %s", g_SCProperties.language);
434             }
435
436             char *gpsLocation = NULL;
437             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_GPSLOCATION, &gpsLocation))
438             {
439                 OICStrcpy(pDevConfProp->gpsLocation, strlen(gpsLocation)+1, gpsLocation);
440                 OICStrcpy(g_SCProperties.gpsLocation, strlen(gpsLocation)+1, gpsLocation);
441                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.gpsLocation %s", g_SCProperties.gpsLocation);
442             }
443
444             char *utcDateTime = NULL;
445             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_UTC_DATE_TIME, &utcDateTime))
446             {
447                 OICStrcpy(pDevConfProp->utcDateTime, strlen(utcDateTime)+1, utcDateTime);
448                 OICStrcpy(g_SCProperties.utcDateTime, strlen(utcDateTime)+1, utcDateTime);
449                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.utcDateTime %s", g_SCProperties.utcDateTime);
450             }
451
452             char *regionalDateTime = NULL;
453             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME, &regionalDateTime))
454             {
455                 OICStrcpy(pDevConfProp->regionalDateTime, strlen(regionalDateTime)+1, regionalDateTime);
456                 OICStrcpy(g_SCProperties.regionalDateTime, strlen(regionalDateTime)+1, regionalDateTime);
457                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.regionalDateTime %s", g_SCProperties.regionalDateTime);
458             }
459
460             char *timeZoneId = NULL;
461             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_TIMEZONE_ID, &timeZoneId))
462             {
463                 OICStrcpy(pDevConfProp->timeZoneId, strlen(timeZoneId)+1, timeZoneId);
464                 OICStrcpy(g_SCProperties.timeZoneId, strlen(timeZoneId)+1, timeZoneId);
465                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.timeZoneId %s", g_SCProperties.timeZoneId);
466             }
467
468             char *ssoList = NULL;
469             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_SSO_LIST, &ssoList))
470             {
471                 OICStrcpy(pDevConfProp->ssoList, strlen(ssoList)+1, ssoList);
472                 OICStrcpy(g_SCProperties.ssoList, strlen(ssoList)+1, ssoList);
473                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "pDevConfProp.ssoList %s", g_SCProperties.ssoList);
474             }
475         }
476         else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF))
477         {
478             char* clientID = NULL;
479             if(OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_CLIENTID, &clientID))
480             {
481                 if(*userdata == NULL)
482                 {
483                     *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
484                     if( *userdata == NULL )
485                     {
486                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
487                         OICFree(clientID);
488                         return;
489                     }
490                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
491                 }
492
493                 SCCoapCloudServerConfProperties *pCloudProp =
494                                                     (SCCoapCloudServerConfProperties*)(*userdata);
495
496                 OICStrcpy(pCloudProp->clientID, strlen(clientID)+1, clientID);
497                 OICStrcpy(g_SCProperties.clientID, strlen(clientID)+1, clientID);
498                 OICFree(clientID);
499
500                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
501                                         SC_RSRVD_ES_VENDOR_CLIENTID, pCloudProp->clientID);
502             }
503
504             //SC_RSRVD_ES_VENDOR_AAC
505             char *aac = NULL;
506             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_AAC, &aac))
507             {
508                 if(*userdata == NULL)
509                 {
510                     *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
511                     if( *userdata == NULL )
512                     {
513                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
514                         OICFree(aac);
515                         return;
516                     }
517                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
518                 }
519
520                 if (*userdata != NULL)
521                 {
522                     SCCoapCloudServerConfProperties *pCloudProp =
523                                                     (SCCoapCloudServerConfProperties*) (*userdata);
524                     pCloudProp->aac[0] = '\0';
525
526                     OICStrcpy(pCloudProp->aac, MAXLEN_STRING, aac);
527                     OICStrcpy(g_SCProperties.aac, MAXLEN_STRING, aac);
528                     OICFree(aac);
529
530                     OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
531                             SC_RSRVD_ES_VENDOR_AAC, pCloudProp->aac);
532                 }
533             }
534
535             //SC_RSRVD_ES_VENDOR_UID
536             char *uid = NULL;
537             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_UID, &uid))
538             {
539                 if(*userdata == NULL)
540                 {
541                     *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
542                     if( *userdata == NULL )
543                     {
544                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
545                         OICFree(uid);
546                         return;
547                     }
548                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
549                 }
550
551                 if (*userdata != NULL)
552                 {
553                     SCCoapCloudServerConfProperties *pCloudProp =
554                                                     (SCCoapCloudServerConfProperties*) (*userdata);
555                     pCloudProp->uid[0] = '\0';
556
557                     OICStrcpy(pCloudProp->uid, MAXLEN_STRING, uid);
558                     OICStrcpy(g_SCProperties.uid, MAXLEN_STRING, uid);
559                     OICFree(uid);
560
561                     OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
562                             SC_RSRVD_ES_VENDOR_UID, pCloudProp->uid);
563                 }
564             }
565
566             //SC_RSRVD_ES_VENDOR_REFRESH_TOKEN
567             char *refreshToken = NULL;
568             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_REFRESH_TOKEN, &refreshToken))
569             {
570                 if(*userdata == NULL)
571                 {
572                     *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
573                     if( *userdata == NULL )
574                     {
575                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
576                         OICFree(refreshToken);
577                         return;
578                     }
579                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
580                 }
581
582                 if (*userdata != NULL)
583                 {
584                     SCCoapCloudServerConfProperties *pCloudProp =
585                                                     (SCCoapCloudServerConfProperties*) (*userdata);
586                     pCloudProp->refreshToken[0] = '\0';
587
588                     OICStrcpy(pCloudProp->refreshToken, MAXLEN_STRING, refreshToken);
589                     OICStrcpy(g_SCProperties.refreshToken, MAXLEN_STRING, refreshToken);
590                     OICFree(refreshToken);
591
592                     OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
593                             SC_RSRVD_ES_VENDOR_REFRESH_TOKEN, pCloudProp->refreshToken);
594                 }
595             }
596
597             // SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT
598             char *deployEnv = NULL;
599             if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT, &deployEnv))
600             {
601                 if(*userdata == NULL)
602                 {
603                     *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
604                     if( *userdata == NULL )
605                     {
606                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
607                         OICFree(deployEnv);
608                         return;
609                     }
610                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
611                 }
612
613                 if (*userdata != NULL)
614                 {
615                     SCCoapCloudServerConfProperties *pCloudProp =
616                                                     (SCCoapCloudServerConfProperties*) (*userdata);
617                     OICStrcpy(pCloudProp->deployEnv, MAXLEN_STRING, deployEnv);
618                     OICStrcpy(g_SCProperties.deployEnv, MAXLEN_STRING, deployEnv);
619                     OICFree(deployEnv);
620
621                     OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
622                             SC_RSRVD_ES_VENDOR_REFRESH_TOKEN, pCloudProp->deployEnv);
623                 }
624             }
625
626             // SC_RSRVD_ES_VENDOR_IATT
627             int64_t iatt;
628             if (OCRepPayloadGetPropInt(payload, SC_RSRVD_ES_VENDOR_IATT, &iatt))
629             {
630                 if(*userdata == NULL)
631                 {
632                     *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
633                     if( *userdata == NULL )
634                     {
635                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
636                         return;
637                     }
638                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
639                 }
640
641                 SCCoapCloudServerConfProperties *pCloudProp =
642                                                 (SCCoapCloudServerConfProperties*) (*userdata);
643
644                 pCloudProp->iatt = iatt;
645                 g_SCProperties.iatt = iatt;
646
647                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %d",
648                         SC_RSRVD_ES_VENDOR_REFRESH_TOKEN, pCloudProp->iatt);
649             }
650
651             ReadTnCdata(payload,userdata);
652         }
653     }
654
655     OIC_LOG(INFO, SC_ENROLLEE_TAG, "ReadUserdataCb OUT");
656 }
657
658 void WriteUserdataCb(OCRepPayload* payload, char* resourceType)
659 {
660     OIC_LOG(INFO, SC_ENROLLEE_TAG, "WriteUserdataCb IN");
661
662     if(payload != NULL)
663     {
664         if (strstr(resourceType, OC_RSRVD_ES_RES_TYPE_EASYSETUP))
665         {
666             OCRepPayloadSetPropInt(payload, SC_RSRVD_ES_VENDOR_NETCONNECTION_STATE, (int) g_SCProperties.netConnectionState);
667         }
668
669         if (strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFICONF))
670         {
671            OCRepPayload **repPayload = OICCalloc(g_SCProperties.numCandidateAP, sizeof(OCRepPayload *));
672
673            for (size_t i = 0; i < (size_t)g_SCProperties.numCandidateAP; i++)
674            {
675                repPayload[i] = OCRepPayloadCreate();
676                if (!repPayload[i])
677                {
678                    OCRepPayloadDestroy(payload);
679                    for (size_t k = 0; k < i; k++)
680                    {
681                        OCRepPayloadDestroy(repPayload[k]);
682                    }
683                    OCRepPayloadDestroy(*repPayload);
684                    break;
685                }
686                OCRepPayloadSetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_SSID, g_SCProperties.candidateAPInfo[i].ssid);
687                OCRepPayloadSetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_PASSPHRASE, g_SCProperties.candidateAPInfo[i].passphrase);
688                OCRepPayloadSetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_BSSID, g_SCProperties.candidateAPInfo[i].bssid);
689                OCRepPayloadSetPropInt(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL, g_SCProperties.candidateAPInfo[i].channel);
690             }
691             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_SCProperties.numCandidateAP, 0, 0};
692             OCRepPayloadSetPropObjectArray(payload,SC_RSRVD_ES_VENDOR_CANDIDATEAPS, (const struct OCRepPayload **)repPayload, dimensions);
693         }
694         else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF))
695         {
696 #ifndef __TIZENRT__
697             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_DEVICE_TYPE, g_SCProperties.deviceType);
698             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE, g_SCProperties.deviceSubType);
699             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV, g_SCProperties.regSetDev);
700             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_REGISTER_MOBILE_DEV, g_SCProperties.regMobileDev);
701             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO, g_SCProperties.nwProvInfo);
702             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_SSO_LIST, g_SCProperties.ssoList);
703             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_PNP_PIN, g_SCProperties.pnpPin);
704             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_MODEL_NUMBER, g_SCProperties.modelNumber);
705             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_COUNTRY, g_SCProperties.country);
706             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_LANGUAGE, g_SCProperties.language);
707             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_GPSLOCATION, g_SCProperties.gpsLocation);
708             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_UTC_DATE_TIME, g_SCProperties.utcDateTime);
709             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME, g_SCProperties.regionalDateTime);
710             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION, g_SCProperties.esProtocolVersion);
711             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_HUB_ID, g_SCProperties.hubId);
712 #else
713             if(g_SCProperties.deviceType != NULL)
714             {
715                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_DEVICE_TYPE, g_SCProperties.deviceType);
716             }
717             if(g_SCProperties.deviceSubType != NULL)
718             {
719                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_DEVICE_SUBTYPE, g_SCProperties.deviceSubType);
720             }
721             if(g_SCProperties.regSetDev != NULL)
722             {
723                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_REGISTER_SET_DEV, g_SCProperties.regSetDev);
724             }
725             if(g_SCProperties.regMobileDev != NULL)
726             {
727                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_REGISTER_MOBILE_DEV, g_SCProperties.regMobileDev);
728             }
729             if(g_SCProperties.nwProvInfo!= NULL)
730             {
731                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_NETWORK_PROV_INFO, g_SCProperties.nwProvInfo);
732             }
733             if(g_SCProperties.ssoList!= NULL)
734             {
735                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_SSO_LIST, g_SCProperties.ssoList);
736             }
737             if(g_SCProperties.pnpPin != NULL)
738             {
739                OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_PNP_PIN, g_SCProperties.pnpPin);
740             }
741             if(g_SCProperties.modelNumber != NULL)
742             {
743                OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_MODEL_NUMBER, g_SCProperties.modelNumber);
744             }
745             if(g_SCProperties.country != NULL)
746             {
747                OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_COUNTRY, g_SCProperties.country);
748             }
749             if(g_SCProperties.language != NULL)
750             {
751                OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_LANGUAGE, g_SCProperties.language);
752             }
753             if(g_SCProperties.gpsLocation != NULL)
754             {
755                OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_GPSLOCATION, g_SCProperties.gpsLocation);
756             }
757             if(g_SCProperties.esProtocolVersion != NULL)
758             {
759                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION, g_SCProperties.esProtocolVersion);
760             }
761             if (g_SCProperties.hubId != NULL)
762             {
763                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_HUB_ID, g_SCProperties.hubId);
764             }
765 #endif
766         }
767         else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF))
768         {
769             // x.com.samsung.deployenv
770             if (g_SCProperties.deployEnv != NULL)
771             {
772                 OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT, g_SCProperties.deployEnv);
773             }
774
775             // x.com.samsung.iatt
776             OCRepPayloadSetPropInt(payload, SC_RSRVD_ES_VENDOR_IATT, g_SCProperties.iatt);
777         }
778     }
779
780     WriteTnCdata(payload, resourceType);
781     WriteWifiData(payload, resourceType);
782
783     OIC_LOG(INFO, SC_ENROLLEE_TAG, "WriteUserdataCb OUT");
784 }