From: agrkush Date: Wed, 3 Oct 2018 07:52:22 +0000 (+0530) Subject: Adding candidateAP information. Following Samsung Specific Property is added : X-Git-Tag: submit/tizen/20181009.235403~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49a4ea0b7f705bf62ddca8c895ca630564d99f7c;p=platform%2Fupstream%2Fiotivity.git Adding candidateAP information. Following Samsung Specific Property is added : Property Name: Candidate AP List Information Key: "x.com.samsung.candidateaps" Type: Object Array (Containing ssid, passphrase, channel and bssid). Access Mode: Read Write Description: Candidate AP List information Changes made at Mediator and Enrollee Side (Samsung specific source). Linux Sample apps updated and verified (Samsung Specific Sample Apps) https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/323 (cherry picked from commit 839c794eda36bc5428933fef26613db1acdad040) Change-Id: Ia2cc7d6f421c1a0e4f500b820fc11c217d67bf2e Signed-off-by: agrkush Signed-off-by: Amit KS --- diff --git a/service/easy-setup/enrollee/inc/samsung/sc_easysetup.h b/service/easy-setup/enrollee/inc/samsung/sc_easysetup.h index ac52b068b..67030717a 100644 --- a/service/easy-setup/enrollee/inc/samsung/sc_easysetup.h +++ b/service/easy-setup/enrollee/inc/samsung/sc_easysetup.h @@ -55,7 +55,10 @@ #define SC_RSRVD_ES_VENDOR_UTC_DATE_TIME "x.com.samsung.datetime" #define SC_RSRVD_ES_VENDOR_REGIONAL_DATE_TIME "x.com.samsung.regionaldatetime" #define SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION "x.com.samsung.espv" - +#define SC_RSRVD_ES_VENDOR_CANDIDATEAPS "x.com.samsung.candidateaps" +#define SC_RSRVD_ES_VENDOR_SSID "x.com.samsung.ssid" +#define SC_RSRVD_ES_VENDOR_PASSPHRASE "x.com.samsung.passphrase" +#define SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL "x.com.samsung.channel" #define WIFI_DISCOVERY_CHANNEL_INIT -1 @@ -70,10 +73,20 @@ typedef enum NET_STATE_NOT_CONNECTED /**< Not connected, at all **/ } NETCONNECTION_STATE; +typedef struct SCCandidateAPInfo +{ + char ssid[MAXLEN_STRING]; + char passphrase[MAXLEN_STRING]; + int channel; + char bssid[MAXLEN_STRING]; +} SCCandidateAPInfo; + typedef struct SCWiFiConfProperties { int discoveryChannel; /**< Wi-Fi AP Channel used for fast discovery **/ char bssid[MAXLEN_STRING]; /**< Wi-Fi bssid information. **/ + int numCandidateAP; + SCCandidateAPInfo candidateAPInfo[5]; } SCWiFiConfProperties; typedef struct SCTncInfo @@ -136,6 +149,8 @@ typedef struct SCProperties char utcDateTime[MAXLEN_DATE_TIME]; /**< UTC date time **/ char regionalDateTime[MAXLEN_DATE_TIME]; /**< Regional date time **/ char esProtocolVersion[MAXLEN_STRING]; /**< Samsung Easy Setup Protocol Version **/ + int numCandidateAP; + SCCandidateAPInfo candidateAPInfo[5]; } SCProperties; void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata); diff --git a/service/easy-setup/enrollee/src/samsung/sc_easysetup.c b/service/easy-setup/enrollee/src/samsung/sc_easysetup.c index cb6bc24ff..8981ea465 100644 --- a/service/easy-setup/enrollee/src/samsung/sc_easysetup.c +++ b/service/easy-setup/enrollee/src/samsung/sc_easysetup.c @@ -287,6 +287,64 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata) OICFree(bssid); } } + + OCRepPayload **repPayload = NULL; + size_t dimensions[MAX_REP_ARRAY_DEPTH]; + if(OCRepPayloadGetPropObjectArray(payload, SC_RSRVD_ES_VENDOR_CANDIDATEAPS, &repPayload, dimensions)) + { + if(*userdata == NULL) + { + *userdata = (void*) OICMalloc(sizeof(SCWiFiConfProperties)); + if( *userdata == NULL ) + { + OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCWiFiConfProperties is failed"); + return ; + } + memset(*userdata, 0, sizeof(SCWiFiConfProperties)); + } + //size_t dim = calcDimTotal(dimensions); + SCWiFiConfProperties* pWifiConfProp = (SCWiFiConfProperties*)(*userdata); + for (size_t i = 0; i < dimensions[0]; i++) + { + int64_t cd_channel = -1; + char *cd_bssid = NULL; + char *ssid = NULL; + char *pwd = NULL; + if (OCRepPayloadGetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_SSID, &ssid)) + { + OICStrcpy(pWifiConfProp->candidateAPInfo[i].ssid, sizeof(pWifiConfProp->candidateAPInfo[i].ssid), ssid); + OICStrcpy(g_SCProperties.candidateAPInfo[i].ssid, sizeof(g_SCProperties.candidateAPInfo[i].ssid), ssid); + OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s", + SC_RSRVD_ES_VENDOR_SSID, ssid); + OICFree(ssid); + } + if (OCRepPayloadGetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_PASSPHRASE, &pwd)) + { + OICStrcpy(pWifiConfProp->candidateAPInfo[i].passphrase, sizeof(pWifiConfProp->candidateAPInfo[i].passphrase), pwd); + OICStrcpy(g_SCProperties.candidateAPInfo[i].passphrase, sizeof(g_SCProperties.candidateAPInfo[i].passphrase), pwd); + OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s", + SC_RSRVD_ES_VENDOR_PASSPHRASE, ssid); + OICFree(pwd); + } + if (OCRepPayloadGetPropInt(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL, &cd_channel)) + { + pWifiConfProp->candidateAPInfo[i].channel = (int) cd_channel; + g_SCProperties.candidateAPInfo[i].channel = cd_channel; + OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %d", + SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL, cd_channel); + } + if (OCRepPayloadGetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_BSSID, &cd_bssid)) + { + OICStrcpy(pWifiConfProp->candidateAPInfo[i].bssid, sizeof(pWifiConfProp->candidateAPInfo[i].bssid), cd_bssid); + OICStrcpy(g_SCProperties.candidateAPInfo[i].bssid, sizeof(g_SCProperties.candidateAPInfo[i].bssid), cd_bssid); + OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s", + SC_RSRVD_ES_VENDOR_BSSID, cd_bssid); + OICFree(bssid); + } + } + pWifiConfProp->numCandidateAP = (int)dimensions[0]; + g_SCProperties.numCandidateAP = (int)dimensions[0]; + } } else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF)) { @@ -512,6 +570,31 @@ void WriteUserdataCb(OCRepPayload* payload, char* resourceType) OCRepPayloadSetPropInt(payload, SC_RSRVD_ES_VENDOR_NETCONNECTION_STATE, (int) g_SCProperties.netConnectionState); } + if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFICONF)) + { + OCRepPayload **repPayload = OICCalloc(g_SCProperties.numCandidateAP, sizeof(OCRepPayload *)); + + for (size_t i = 0; i < (size_t)g_SCProperties.numCandidateAP; i++) + { + repPayload[i] = OCRepPayloadCreate(); + if (!repPayload[i]) + { + OCRepPayloadDestroy(payload); + for (size_t k = 0; k < i; k++) + { + OCRepPayloadDestroy(repPayload[k]); + } + OCRepPayloadDestroy(*repPayload); + break; + } + OCRepPayloadSetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_SSID, g_SCProperties.candidateAPInfo[i].ssid); + OCRepPayloadSetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_PASSPHRASE, g_SCProperties.candidateAPInfo[i].passphrase); + OCRepPayloadSetPropString(repPayload[i], SC_RSRVD_ES_VENDOR_BSSID, g_SCProperties.candidateAPInfo[i].bssid); + OCRepPayloadSetPropInt(repPayload[i], SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL, g_SCProperties.candidateAPInfo[i].channel); + } + size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_SCProperties.numCandidateAP, 0, 0}; + OCRepPayloadSetPropObjectArray(payload,SC_RSRVD_ES_VENDOR_CANDIDATEAPS, (const struct OCRepPayload **)repPayload, dimensions); + } if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF)) { #ifndef __TIZENRT__ diff --git a/service/easy-setup/mediator/richsdk/inc/ESSCCommon.h b/service/easy-setup/mediator/richsdk/inc/ESSCCommon.h index 1df7cb6e6..93a2c918f 100644 --- a/service/easy-setup/mediator/richsdk/inc/ESSCCommon.h +++ b/service/easy-setup/mediator/richsdk/inc/ESSCCommon.h @@ -54,6 +54,12 @@ using namespace std; #define SC_RSRVD_ES_VENDOR_COUNTRY "x.com.samsung.country" #define SC_RSRVD_ES_VENDOR_GPSLOCATION "x.com.samsung.gpslocation" #define SC_RSRVD_ES_VENDOR_ES_PROTOCOL_VERSION "x.com.samsung.espv" +#define SC_RSRVD_ES_VENDOR_CANDIDATEAPS "x.com.samsung.candidateaps" +#define SC_RSRVD_ES_VENDOR_SSID "x.com.samsung.ssid" +#define SC_RSRVD_ES_VENDOR_PASSPHRASE "x.com.samsung.passphrase" +#define SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL "x.com.samsung.channel" + +#define MAXLEN_STRING 1000 namespace OIC @@ -84,6 +90,14 @@ namespace OIC TC_STATUS_TIMEOUT_TO_AGREE } TC_STATUS; + typedef struct SCCandidateAPInfo + { + std::string ssid; + std::string passphrase; + int channel; + std::string bssid; + } SCCandidateAPInfo; + /** * @brief Properties of provisioning resource. It includes a provisioning status and last * error code. @@ -363,6 +377,67 @@ namespace OIC } return {}; } + + /** + * Set Candidate AP information which is stored. + * + * @param clientID - Client service ID + */ + void setCandidateAPList(SCCandidateAPInfo *candidateInfo,int numCandidateAP) + { + std::vector candidateAPList; + for (int i=0;i getCandidateAPList() + { + if(m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS)) + { + std::vector candidateInfo= + m_rep.getValue>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS); + std::vector postcandidateInfo; + for(std::vector::iterator it = candidateInfo.begin(); + it != candidateInfo.end(); ++it) + { + OC::OCRepresentation rep = *it; + SCCandidateAPInfo candidateInfotemp; + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSID)) + { + candidateInfotemp.ssid=rep.getValue(SC_RSRVD_ES_VENDOR_SSID); + } + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_PASSPHRASE)) + { + candidateInfotemp.passphrase=rep.getValue(SC_RSRVD_ES_VENDOR_PASSPHRASE); + } + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL)) + { + candidateInfotemp.channel=rep.getValue(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL); + + } + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_BSSID)) + { + candidateInfotemp.bssid=rep.getValue(SC_RSRVD_ES_VENDOR_BSSID); + } + postcandidateInfo.push_back(candidateInfotemp); + } + return postcandidateInfo; + } + return {}; + } }; class SCCloudProp : public CloudProp @@ -618,6 +693,58 @@ namespace OIC return std::string(""); } + /** + * Get Candidate AP information which is registered in device. + * + * @return SCCandidateAPInfo list. + */ + std::vector getCandidateAPList() const + { + std::vector children = m_EasySetupRep.getChildren(); + for(auto child = children.begin(); child != children.end(); ++child) + { + if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos) + { + OCRepresentation rep; + if(child->hasAttribute(OC_RSRVD_REPRESENTATION)) + { + rep = child->getValue(OC_RSRVD_REPRESENTATION); + } + + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATEAPS)) + { + std::vector candidateInfo=rep.getValue>(SC_RSRVD_ES_VENDOR_CANDIDATEAPS); + std::vector postcandidateInfo; + for(std::vector::iterator it = candidateInfo.begin(); + it != candidateInfo.end(); ++it) + { + OC::OCRepresentation rep = *it; + SCCandidateAPInfo candidateInfotemp; + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_SSID)) + { + candidateInfotemp.ssid=rep.getValue(SC_RSRVD_ES_VENDOR_SSID); + } + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_PASSPHRASE)) + { + candidateInfotemp.passphrase=rep.getValue(SC_RSRVD_ES_VENDOR_PASSPHRASE); + } + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL)) + { + candidateInfotemp.channel=rep.getValue(SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL); + + } + if(rep.hasAttribute(SC_RSRVD_ES_VENDOR_BSSID)) + { + candidateInfotemp.bssid=rep.getValue(SC_RSRVD_ES_VENDOR_BSSID); + } + postcandidateInfo.push_back(candidateInfotemp); + } + return postcandidateInfo; + } + } + } + } + /** * Get network provisioning information for the device. * Mediator can use this information to enquire & validate registration status with corresponding Network Vendor. diff --git a/service/easy-setup/sampleapp/enrollee/linux-samsung/sc_enrollee.c b/service/easy-setup/sampleapp/enrollee/linux-samsung/sc_enrollee.c index df91cd063..41ec0bd44 100644 --- a/service/easy-setup/sampleapp/enrollee/linux-samsung/sc_enrollee.c +++ b/service/easy-setup/sampleapp/enrollee/linux-samsung/sc_enrollee.c @@ -55,6 +55,7 @@ void PrintMenu() printf("S: Enabled Security\n"); printf("I: Init & Start EasySetup\n"); printf("D: Set DeviceInfo\n"); + printf("W: Set WiFiInfo\n"); printf("T: Terminate\n"); printf("Q: Quit\n"); printf("============\n"); @@ -79,6 +80,15 @@ void WiFiProvCbInApp(ESWiFiConfData *eventData) { SCWiFiConfProperties *data = eventData->userdata; printf("[SC] DiscoveryChannel : %d\n", data->discoveryChannel); + printf("[SC] Number of candidate AP : %d\n", data->numCandidateAP); + for (int i = 0; i< data->numCandidateAP ; i++) + { + printf("[SC] Candidate Bssid : %s\n", data->candidateAPInfo[i].bssid); + printf("[SC] Candidate Channel : %d\n", data->candidateAPInfo[i].channel); + printf("[SC] Candidate Passphrase : %s\n", data->candidateAPInfo[i].passphrase); + printf("[SC] Candidate SSID : %s\n", data->candidateAPInfo[i].ssid); + } + } printf("WiFiProvCbInApp OUT\n"); @@ -218,6 +228,26 @@ void SetDeviceInfo() printf("SetDeviceInfo OUT\n"); } +void SetWiFiInfo() +{ + + printf("SetWiFiInfo IN\n"); + strncpy(g_SCProperties.candidateAPInfo[0].ssid, "x_5GHz", MAXLEN_STRING); + strncpy(g_SCProperties.candidateAPInfo[0].passphrase, "12345678",MAXLEN_STRING); + g_SCProperties.candidateAPInfo[0].channel = 149; + strncpy(g_SCProperties.candidateAPInfo[0].bssid, "aa:bb:cc:dd:ee:01", MAXLEN_STRING); + strncpy(g_SCProperties.candidateAPInfo[1].ssid, "5GHz", MAXLEN_STRING); + strncpy(g_SCProperties.candidateAPInfo[1].passphrase, "12345678",MAXLEN_STRING); + g_SCProperties.candidateAPInfo[1].channel = 161; + strncpy(g_SCProperties.candidateAPInfo[1].bssid, "aa:bb:cc:dd:ee:02", MAXLEN_STRING); + g_SCProperties.numCandidateAP=2; + + if(SetSCProperties(&g_SCProperties) == ES_ERROR) + printf("SetSCProperties Error\n"); + printf("SetWiFiInfo OUT\n"); + +} + void StopEasySetup() { printf("StopEasySetup IN\n"); @@ -285,6 +315,11 @@ int main() SetDeviceInfo(); PrintMenu(); break; + case 'W': // Set Device Info + case 'w': + SetWiFiInfo(); + PrintMenu(); + break; case 'T': // stop easy setup case 't': StopEasySetup(); diff --git a/service/easy-setup/sampleapp/mediator/linux-samsung/richsdk_sample/mediator_sc.cpp b/service/easy-setup/sampleapp/mediator/linux-samsung/richsdk_sample/mediator_sc.cpp index ad913f964..bf03576a2 100644 --- a/service/easy-setup/sampleapp/mediator/linux-samsung/richsdk_sample/mediator_sc.cpp +++ b/service/easy-setup/sampleapp/mediator/linux-samsung/richsdk_sample/mediator_sc.cpp @@ -92,6 +92,15 @@ void printConfiguration(const SCEnrolleeConf& conf) cout << "\tUTC time: " << conf.getUTCDatetime() << endl; cout << "\tRegional time: " << conf.getRegionalDatetime() << endl; cout << "\tEasy Setup Protocol Version: " << conf.getESProtocolVersion() << endl; + std::vector candidateInfo = conf.getCandidateAPList(); + int size = candidateInfo.size(); + for(int i=0;i< size;i++) + { + cout << "[SC] Candidate Bssid :" << candidateInfo[i].bssid << endl; + cout << "[SC] Candidate Channel :" << candidateInfo[i].channel << endl; + cout << "[SC] Candidate Passphrase :" << candidateInfo[i].passphrase << endl; + cout << "[SC] Candidate SSID :" << candidateInfo[i].ssid << endl; + } cout << "===========================================" << endl; } @@ -230,6 +239,16 @@ void provisionDeviceProperty() scDevProp.setRegisterMobileDevice("{\"wm\":\"00:11:22:33:44:55\",\"pm\":\"00:11:22:33:44:55\",\"bm\":\"00:11:22:33:44:55\",\"dt\":\"0\",\"it\":\"0\"}"); scDevProp.setSSOList("[{\"AvailableCount\" : \"1\", \"RegisteredCount\" : \"3\", \"AccountList\" : {\"aaa@samsung.com\", \"bbb@samsung.com\",\"ccc@samsung.com\"} }] "); + SCCandidateAPInfo candidateAPInfo[2]; + candidateAPInfo[0].ssid = "x_5GHz"; + candidateAPInfo[0].passphrase= "12345678"; + candidateAPInfo[0].channel = 149; + candidateAPInfo[0].bssid = "aa:bb:cc:dd:ee:01"; + candidateAPInfo[1].ssid = "y_5GHz"; + candidateAPInfo[1].passphrase= "12345678"; + candidateAPInfo[1].channel = 161; + candidateAPInfo[1].bssid = "aa:bb:cc:dd:ee:02"; + scDevProp.setCandidateAPList(candidateAPInfo,2); // Set UTC and regional date time_t t = time(NULL);