1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * *****************************************************************/
29 #include <condition_variable>
32 #include "oic_malloc.h"
33 #include "oic_string.h"
34 #include "OCPlatform.h"
36 #include "OCProvisioningManager.h"
37 #include "oxmjustworks.h"
38 #include "oxmrandompin.h"
39 #include "aclresource.h"
42 #define MAX_URI_LENGTH (64)
43 #define MAX_PERMISSION_LENGTH (5)
44 #define ACL_RESRC_ARRAY_SIZE (3)
51 #define PREDEFINED_TIMEOUT (10)
52 #define MAX_OWNED_DEVICE (10)
53 #define TAG "provisioningclient"
55 #define JSON_DB_PATH "./oic_svr_db_client.json"
56 #define DAT_DB_PATH "./oic_svr_db_client.dat"
57 #define DEV_STATUS_ON "DEV_STATUS_ON"
58 #define DEV_STATUS_OFF "DEV_STATUS_OFF"
60 #define DISCOVERY_TIMEOUT 5
62 static const OicSecPrm_t SUPPORTED_PRMS[1] =
69 DeviceList_t pUnownedDevList, pOwnedDevList;
70 static int transferDevIdx, ask = 1;
71 static OicSecPconf_t g_pconf;
73 static FILE* client_open(const char *UNUSED_PARAM, const char *mode)
76 return fopen(DAT_DB_PATH, mode);
81 std::cout << "\nChoose an option:"<<std::endl;
82 std::cout << " 1. UnOwned Device discovery"<<std::endl;
83 std::cout << " 2. Owned Device discovery"<<std::endl;
84 std::cout << " 3. Ownership transfer"<<std::endl;
85 std::cout << " 4. Provision ACL"<<std::endl;
86 std::cout << " 5. Provision Credentials"<<std::endl;
87 std::cout << " 6. Credential & ACL provisioning b/w two devices"<<std::endl;
88 std::cout << " 7. Unlink Devices"<<std::endl;
89 std::cout << " 8. Remove Device"<<std::endl;
90 std::cout << " 9. Remove Device using UUID"<<std::endl;
91 std::cout << " 10. Get Linked Devices"<<std::endl;
92 std::cout << " 11. Get Device Status"<<std::endl;
93 std::cout << " 12. Provision Direct-Pairing Configuration"<<std::endl;
94 std::cout << " 13. Exit loop"<<std::endl;
97 void moveTransferredDevice()
99 pOwnedDevList.push_back(pUnownedDevList[transferDevIdx]);
100 pUnownedDevList.erase(pUnownedDevList.begin() + transferDevIdx);
103 void InputPinCB(char* pinBuf, size_t bufSize)
107 std::cout <<"INPUT PIN : ";
110 OICStrcpy(pinBuf, bufSize, ptr.c_str());
115 void printUuid(OicUuid_t uuid)
117 for (int i = 0; i < UUID_LENGTH; i++)
119 std::cout <<std::hex << uuid.id[i] << " ";
121 std::cout<<std::endl;
124 void ownershipTransferCB(PMResultList_t *result, int hasError)
128 std::cout << "Error!!! in OwnershipTransfer"<<std::endl;
132 std::cout<< "\nTransferred Ownership successfuly for device : ";
133 printUuid(result->at(0).deviceId);
136 moveTransferredDevice();
141 void printStatus(int status)
143 static std::map<int, std::string> devStatus = {{1<<0, DEV_STATUS_ON}, {1<<1, DEV_STATUS_OFF}};
145 std::cout <<devStatus[status] <<std::endl;
148 void printDevices(DeviceList_t &list)
150 for (unsigned int i = 0; i < list.size(); i++ )
152 std::cout << "Device "<< i+1 <<" ID: ";
153 std::cout << list[i]->getDeviceID() << " From IP: ";
154 std::cout << list[i]->getDevAddr() << std::endl;
159 * Callback function for provisioning ACL, Credentials.
161 * @param[in] result Result list
162 * @param[in] hasError indicates if the result has error
164 void provisionCB(PMResultList_t *result, int hasError)
168 std::cout << "Error in provisioning operation!"<<std::endl;
172 std::cout<< "\nReceived provisioning results: ";
173 for (unsigned int i = 0; i < result->size(); i++)
175 std::cout << "Result is = " << result->at(i).res <<" for device ";
176 printUuid(result->at(i).deviceId);
186 * Ask user with which devices it wants to make further actions.
187 * All possible error checks included.
188 * Default behavior in case if only one options leaves are included too.
189 * Expect that user count devices from 1, f.e. 1st, 2nd, 3rd, etc
190 * Use DeviceList_t instead of devicesCount because of print devices info
192 * @param[in] list owned devices list.
193 * @param[out] out device number array.
194 * @param[in] count how many device numbers need to read.
195 * @return 0 in case of success and other value otherwise.
197 int readDeviceNumber(DeviceList_t &list, int count, int *out)
199 if (out == NULL || count <= 0)
201 std::cout << "Error! Please put valid input parameters" << std::endl;
205 int devicesCount = list.size();
207 //Print current list of owned devices
208 std::cout <<"Owned devices, count = " << devicesCount << std::endl;
211 if (devicesCount < count)
213 std::cout << "You can't proceed with selected action because Owned devices count ( ";
214 std::cout << devicesCount << " ) are less then required devices ( " << count << " ).";
215 std::cout << "You may need to discover devices again" << std::endl;
219 std::cout << "Select " << count << " device(s) for provisioning" << std::endl;
221 for (int curr = 0; curr < count; curr++)
223 //select last device by default if only 1 option exist
224 //from user's point of view device counting starts from 1,
225 //so 1st, 2nd, 3rd, etc devices
226 if ((curr == count - 1) && (devicesCount == count))
229 for (int i = 0; i < curr; i++)
234 out[curr] = (count*(count+1))/2 - sum;
236 std::cout << "Device " << curr + 1 << " : " << out[curr];
237 std::cout << " - selected automatically (because no other options exist)" << std::endl;
242 std::cout << "Device " << curr + 1 << " : ";
245 if (choice < 1 || choice > devicesCount)
247 std::cout << "Error! You should enter valid device number!" << std::endl;
251 //check that user doesn't select the same device twice
252 for (int i = 0; i < curr; i++)
254 if (out[i] == choice)
256 std::cout << "Error! You cannot select the same device twice!" << std::endl;
264 //Users count devices from 1, so 1st, 2nd, 3rd, etc device
265 //But deviceList array start index is 0, so need to decrease all numbers to 1
266 for (int i = 0; i < count; i++) out[i] -= 1;
272 * Perform cleanup for ACL
275 static void deleteACL(OicSecAcl_t *acl)
282 * Calculate ACL permission from string to bit
284 * @param[in] temp_psm Input data of ACL permission string
285 * @param[in,out] pms The pointer of ACL permission value
286 * @return 0 on success otherwise -1.
288 static int CalculateAclPermission(const char *temp_pms, uint16_t *pms)
292 if (NULL == temp_pms || NULL == pms)
297 while (temp_pms[i] != '\0')
346 * Get the ACL property from user
348 * @param[in] ACL Datastructure to save user inputs
349 * @return 0 on success otherwise -1.
351 static int InputACL(OicSecAcl_t *acl)
354 char *temp_id, *temp_rsc, *temp_pms;
356 printf("******************************************************************************\n");
357 printf("-Set ACL policy for target device\n");
358 printf("******************************************************************************\n");
360 printf("-URN identifying the subject\n");
361 printf("ex) 1111-1111-1111-1111 (16 Numbers except to '-')\n");
362 printf("Subject : ");
363 ret = scanf("%19ms", &temp_id);
365 OicSecAce_t* ace = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t));
368 OIC_LOG(ERROR, TAG, "Error while memory allocation");
371 LL_APPEND(acl->aces, ace);
375 for (int i = 0, j = 0; temp_id[i] != '\0'; i++)
377 if (DASH != temp_id[i])
378 ace->subjectuuid.id[j++] = temp_id[i];
385 printf("Error while input\n");
390 size_t resourcesLen = 0;
391 printf("Num. of Resource : ");
392 ret = scanf("%zu", &resourcesLen);
393 if ((1 != ret) || (resourcesLen <= 0 || resourcesLen > 50))
396 printf("Error while input\n");
399 printf("-URI of resource\n");
400 printf("ex)/oic/sh/temp/0 (Max_URI_Length: 64 Byte )\n");
401 for(size_t i = 0; i < resourcesLen; i++)
403 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
407 OIC_LOG(ERROR, TAG, "Error while memory allocation");
411 LL_APPEND(ace->resources, rsrc);
413 printf("[%zu]Resource : ", i + 1);
414 ret = scanf("%64ms", &temp_rsc);
417 printf("Error while input\n");
421 rsrc->href = OICStrdup(temp_rsc);
424 char* rsrc_in = NULL;
428 printf(" Enter Number of resource type for [%s]: ", rsrc->href);
429 for(int ret=0; 1!=ret; )
431 ret = scanf("%d", &arrLen);
432 for( ; 0x20<=getchar(); ); // for removing overflow garbages
433 // '0x20<=code' is character region
435 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
439 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
442 rsrc->typeLen = arrLen;
443 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
446 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
450 for(int i = 0; i < arrLen; i++)
452 printf(" Enter ResourceType[%d] Name (e.g. core.led): ", i+1);
453 for(int ret=0; 1!=ret; )
455 ret = scanf("%64ms", &rsrc_in); // '128' is ACL_RESRC_MAX_LEN
456 for( ; 0x20<=getchar(); ); // for removing overflow garbages
457 // '0x20<=code' is character region
459 rsrc->types[i] = OICStrdup(rsrc_in);
463 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
470 printf(" Enter Number of interface name for [%s]: ", rsrc->href);
471 for(int ret=0; 1!=ret; )
473 ret = scanf("%d", &arrLen);
474 for( ; 0x20<=getchar(); ); // for removing overflow garbages
475 // '0x20<=code' is character region
477 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
481 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
484 rsrc->interfaceLen = arrLen;
485 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
486 if(!rsrc->interfaces)
488 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
492 for(int i = 0; i < arrLen; i++)
494 printf(" Enter interfnace[%d] Name (e.g. oic.if.baseline): ", i+1);
495 for(int ret=0; 1!=ret; )
497 ret = scanf("%64ms", &rsrc_in); // '128' is ACL_RESRC_MAX_LEN
498 for( ; 0x20<=getchar(); ); // for removing overflow garbages
499 // '0x20<=code' is character region
501 rsrc->interfaces[i] = OICStrdup(rsrc_in);
503 if(!rsrc->interfaces[i])
505 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
515 printf("-Set the permission(C,R,U,D,N)\n");
516 printf("ex) CRUDN, CRU_N,..(5 Charaters)\n");
517 printf("Permission : ");
518 ret = scanf("%5ms", &temp_pms);
521 printf("Error while input\n");
524 ret = CalculateAclPermission(temp_pms, &(ace->permission));
529 printf("-URN identifying the rowner\n");
530 printf("ex) 1111-1111-1111-1111 (16 Numbers except to '-')\n");
533 ret = scanf("%19ms", &temp_id);
536 printf("Error while input\n");
540 for (int k = 0, j = 0; temp_id[k] != '\0'; k++)
542 if (DASH != temp_id[k])
544 acl->rownerID.id[j++] = temp_id[k];
556 static int InputCredentials(Credential &cred)
562 std::cout << "Select credential type from following values:" << std::endl;
563 std::cout << "1: symmetric pair-wise key" << std::endl;
564 std::cout << "2: symmetric group key" << std::endl;
565 std::cout << "4: asymmetric key" << std::endl;
566 std::cout << "8: signed asymmetric key (aka certificate)" << std::endl;
567 std::cout << "16: PIN /password" << std::endl;
568 std::cout << "Your choice: ";
574 cred.setCredentialType(static_cast<OicSecCredType_t>(choice));
575 choice = 0; //validation of the accepted choice.
581 std::cout << "selected type is not supported yet" << std::endl;
584 std::cout << "Error! Please select valid credential type" << std::endl;
587 } while(0 != choice);
589 std::cout << "Please enter key size (valid size is 128 or 256) :";
594 cred.setCredentialKeySize(OWNER_PSK_LENGTH_128);
596 else if(256 == choice)
598 cred.setCredentialKeySize(OWNER_PSK_LENGTH_256);
602 std::cout << "Error! Please enter valid key size!" << std::endl;
609 static void deletePconf()
611 OICFree(g_pconf.prm);
613 OicSecPdAcl_t* acl = g_pconf.pdacls;
616 /* Clean Resources */
617 for (unsigned int i = 0; i < (acl)->resourcesLen; i++)
619 OICFree((acl)->resources[i]);
621 OICFree((acl)->resources);
623 /* Clean ACL node itself */
624 /* Required only if acl was created in heap */
627 memset(&g_pconf, 0, sizeof(OicSecPconf_t));
630 static OicSecPdAcl_t* InputPdACL()
633 char *temp_rsc, *temp_pms;
635 printf("******************************************************************************\n");
636 printf("-Set ACL policy for target DP device\n");
637 printf("******************************************************************************\n");
639 OicSecPdAcl_t *acl = (OicSecPdAcl_t *)OICCalloc(1,sizeof(OicSecPdAcl_t));
642 OIC_LOG(ERROR, TAG, "Error while memory allocation");
647 printf("Num. of Resource : ");
648 ret = scanf("%zu", &acl->resourcesLen);
649 if ((1 != ret) || (acl->resourcesLen <= 0 || acl->resourcesLen > 50))
651 printf("Error while input\n");
655 printf("-URI of resource\n");
656 printf("ex)/oic/sh/temp/0 (Max_URI_Length: 64 Byte )\n");
657 acl->resources = (char **)OICCalloc(acl->resourcesLen, sizeof(char *));
658 if (NULL == acl->resources)
660 OIC_LOG(ERROR, TAG, "Error while memory allocation");
664 for (size_t i = 0; i < acl->resourcesLen; i++)
666 printf("[%zu]Resource : ", i + 1);
667 ret = scanf("%64ms", &temp_rsc);
670 printf("Error while input\n");
671 OICFree(acl->resources);
676 acl->resources[i] = OICStrdup(temp_rsc);
678 if (NULL == acl->resources[i])
680 OIC_LOG(ERROR, TAG, "Error while memory allocation");
681 OICFree(acl->resources);
690 printf("-Set the permission(C,R,U,D,N)\n");
691 printf("ex) CRUDN, CRU_N,..(5 Charaters)\n");
692 printf("Permission : ");
693 ret = scanf("%5ms", &temp_pms);
696 printf("Error while input\n");
697 OICFree(acl->resources);
701 ret = CalculateAclPermission(temp_pms, &(acl->permission));
708 void provisionDirectPairingCB(PMResultList_t *result, int hasError)
712 std::cout << "Error in provisioning operation!"<<std::endl;
716 std::cout<< "\nReceived provisioning results: Direct Pairing is successful ";
717 for (unsigned int i = 0; i < result->size(); i++)
719 std::cout << "Result is = " << result->at(i).res <<" for device ";
720 printUuid(result->at(i).deviceId);
730 static void provisionDP(int dev_num)
738 // set default supported PRM types
739 g_pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
740 g_pconf.prm = (OicSecPrm_t *)OICCalloc(g_pconf.prmLen, sizeof(OicSecPrm_t));
743 for (size_t i=0; i < g_pconf.prmLen; i++)
745 g_pconf.prm[i] = SUPPORTED_PRMS[i];
750 OIC_LOG(ERROR, TAG, "create prm error return");
754 std::cout << "Enter PIN to be configured: ";
758 if (pin.length() == DP_PIN_LENGTH)
764 std::cout << "PIN length should be 8, Enter again: ";
768 memcpy(g_pconf.pin.val, pin.c_str(), DP_PIN_LENGTH);
772 g_pconf.pdacls = InputPdACL();
775 OIC_LOG(ERROR, TAG, "InputPdACL error return");
779 // call |OCProvisionDirectPairing| API actually
780 // calling this API with callback actually acts like blocking
781 // for error checking, the return value saved and printed
782 rst = pOwnedDevList[dev_num-1]->provisionDirectPairing(&g_pconf, provisionDirectPairingCB);
783 if(OC_STACK_OK != rst)
785 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
786 if (OC_STACK_UNAUTHORIZED_REQ == rst)
788 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
795 deletePconf(); // after here |acl| points nothing
801 OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
803 // Create PlatformConfig object
805 OC::ServiceType::InProc,
809 OC::QualityOfService::LowQos,
813 OCPlatform::Configure(cfg);
818 OicSecAcl_t *acl1 = nullptr, *acl2 = nullptr;
819 if (OCSecure::provisionInit("") != OC_STACK_OK)
821 std::cout <<"PM Init failed"<< std::endl;
825 for (int out = 0; !out;)
849 //Secure resource discovery.
851 pUnownedDevList.clear();
852 std::cout << "Started discovery..." <<std::endl;
853 OCStackResult result = OCSecure::discoverUnownedDevices(DISCOVERY_TIMEOUT,
855 if (result != OC_STACK_OK)
857 std::cout<< "!!Error - UnOwned Discovery failed."<<std::endl;
859 else if (pUnownedDevList.size())
861 std::cout <<"Found secure devices, count = " <<
862 pUnownedDevList.size() << std::endl;
863 printDevices(pUnownedDevList);
867 std::cout <<"No Secure devices found"<<std::endl;
873 pOwnedDevList.clear();
874 std::cout << "Started discovery..." <<std::endl;
875 OCStackResult result = OCSecure::discoverOwnedDevices(DISCOVERY_TIMEOUT,
877 if (result != OC_STACK_OK)
879 std::cout<< "!!Error - Owned Discovery failed."<<std::endl;
881 else if (pOwnedDevList.size())
883 std::cout <<"Found owned devices, count = " <<
884 pOwnedDevList.size() << std::endl;
885 printDevices(pOwnedDevList);
889 std::cout <<"No Secure devices found"<<std::endl;
897 if (!pUnownedDevList.size())
899 std::cout <<"There are no more Unowned devices"<<std::endl;
903 for (unsigned int i = 0; i < pUnownedDevList.size(); i++ )
905 std::cout << i+1 << ": "<< pUnownedDevList[i]->getDeviceID();
906 std::cout << " From IP:" << pUnownedDevList[i]->getDevAddr() <<std::endl;
909 std::cout <<"Select device number: "<<std::endl;
911 if (devNum > pUnownedDevList.size())
913 std::cout <<"Invalid device number"<<std::endl;
916 transferDevIdx = devNum - 1;
918 //register callbacks for JUST WORKS and PIN methods
919 std::cout <<"Registering OTM Methods: 1. JUST WORKS and 2. PIN"<<std::endl;
922 OTMCallbackData_t justWorksCBData;
923 justWorksCBData.loadSecretCB = LoadSecretJustWorksCallback;
924 justWorksCBData.createSecureSessionCB =
925 CreateSecureSessionJustWorksCallback;
926 justWorksCBData.createSelectOxmPayloadCB =
927 CreateJustWorksSelectOxmPayload;
928 justWorksCBData.createOwnerTransferPayloadCB =
929 CreateJustWorksOwnerTransferPayload;
930 OCSecure::setOwnerTransferCallbackData(OIC_JUST_WORKS,
931 &justWorksCBData, NULL);
935 OTMCallbackData_t pinBasedCBData;
936 pinBasedCBData.loadSecretCB = InputPinCodeCallback;
937 pinBasedCBData.createSecureSessionCB =
938 CreateSecureSessionRandomPinCallback;
939 pinBasedCBData.createSelectOxmPayloadCB =
940 CreatePinBasedSelectOxmPayload;
941 pinBasedCBData.createOwnerTransferPayloadCB =
942 CreatePinBasedOwnerTransferPayload;
943 OCSecure::setOwnerTransferCallbackData(OIC_RANDOM_DEVICE_PIN,
944 &pinBasedCBData, InputPinCB);
948 std::cout << "Transfering ownership for : "<<
949 pUnownedDevList[devNum-1]->getDeviceID()<<std::endl;
950 if (pUnownedDevList[devNum-1]->doOwnershipTransfer(ownershipTransferCB)
953 std::cout<<"OwnershipTransferCallback is failed"<<std::endl;
958 case 4: //Provision ACL
962 if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
964 std::cout << "Provision ACL for : "<<
965 pOwnedDevList[index]->getDeviceID()<< std::endl;
967 acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
970 OIC_LOG(ERROR, TAG, "Error while memory allocation");
974 std::cout << "Please input ACL for selected device: " << std::endl;
975 if (0 != InputACL(acl1))
982 if (pOwnedDevList[index]->provisionACL(acl1, provisionCB) != OC_STACK_OK)
985 std::cout <<"provisionACL is failed"<< std::endl;
989 case 5: //Provision Credentials
993 if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
995 int first = devices[0];
996 int second = devices[1];
998 std::cout << "Provision Credentials to devices: "<<
999 pOwnedDevList[first]->getDeviceID();
1000 std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
1002 Credential cred( NO_SECURITY_MODE ,0);
1003 std::cout << "Please input credentials for selected devices: " << std::endl;
1004 if (0 != InputCredentials(cred))
1009 if (pOwnedDevList[first]->provisionCredentials(cred,
1010 *pOwnedDevList[second].get(), provisionCB) != OC_STACK_OK)
1013 std::cout <<"provisionCredentials is failed"<< std::endl;
1017 case 6: //Provision ACL & Creds b/w two devices.
1021 if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
1023 int first = devices[0];
1024 int second = devices[1];
1026 std::cout << "Provision pairwise devices: "<<
1027 pOwnedDevList[first]->getDeviceID();
1028 std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
1030 Credential cred( NO_SECURITY_MODE, 0);
1031 std::cout << "Please input credentials for selected devices: " << std::endl;
1032 if (0 != InputCredentials(cred))
1035 acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
1038 OIC_LOG(ERROR, TAG, "Error while memory allocation");
1042 std::cout << "Please input ACL for selected device: " << std::endl;
1043 if (0 != InputACL(acl1))
1048 acl2 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
1051 OIC_LOG(ERROR, TAG, "Error while memory allocation");
1055 std::cout << "Please input ACL for selected device: " << std::endl;
1056 if (0 != InputACL(acl2))
1063 if (pOwnedDevList[first]->provisionPairwiseDevices(cred, acl1,
1064 *pOwnedDevList[second].get(), acl2, provisionCB) != OC_STACK_OK)
1067 std::cout <<"provisionPairwiseDevices is failed"<< std::endl;
1071 case 7: //Unlink Devices
1075 if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
1077 int first = devices[0];
1078 int second = devices[1];
1080 std::cout << "Unlink devices: "<< pOwnedDevList[first]->getDeviceID();
1081 std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
1085 if (pOwnedDevList[first]->unlinkDevices(*pOwnedDevList[second].get(),
1086 provisionCB) != OC_STACK_OK)
1089 std::cout <<"unlinkDevice is failed"<< std::endl;
1093 case 8: //Remove Device
1097 if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
1099 std::cout << "Remove Device: "<< pOwnedDevList[index]->getDeviceID()<< std::endl;
1103 if (pOwnedDevList[index]->removeDevice(DISCOVERY_TIMEOUT, provisionCB)
1107 std::cout <<"removeDevice is failed"<< std::endl;
1111 case 9: //Remove Device using UUID
1115 if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
1117 std::cout << "Remove Device: "<< pOwnedDevList[index]->getDeviceID()<< std::endl;
1121 if (pOwnedDevList[index]->removeDeviceWithUuid(DISCOVERY_TIMEOUT,
1122 pOwnedDevList[index]->getDeviceID(),
1127 std::cout <<"removeDevice is failed"<< std::endl;
1132 case 10: //Get Linked devices
1134 UuidList_t linkedUuid;
1135 unsigned int devNum;
1137 if (!pOwnedDevList.size())
1139 std::cout <<"There are no Owned devices yet,"
1140 " may need to discover"<<std::endl;
1144 for (unsigned int i = 0; i < pOwnedDevList.size(); i++ )
1146 std::cout << i+1 << ": "<< pOwnedDevList[i]->getDeviceID() <<" From IP:";
1147 std::cout << pOwnedDevList[i]->getDevAddr() <<std::endl;
1150 std::cout <<"Select device number: "<<std::endl;
1152 if (devNum > pOwnedDevList.size())
1154 std::cout <<"Invalid device number"<<std::endl;
1158 if(pOwnedDevList[devNum -1]->getLinkedDevices(linkedUuid) == OC_STACK_OK)
1160 if (!linkedUuid.size())
1162 std::cout <<"No devices are linked to "<<
1163 pOwnedDevList[devNum -1]->getDeviceID() << std::endl;
1165 //display the Linked devices (UUIDs)
1166 for(unsigned int i = 0; i < linkedUuid.size(); i++)
1168 printUuid(linkedUuid[i]);
1173 std::cout <<"Error! in getLinkedDevices"<<std::endl;
1177 case 11: //Get device' status
1179 DeviceList_t unownedList, ownedList;
1181 if (OCSecure::getDevInfoFromNetwork(DISCOVERY_TIMEOUT, ownedList,
1182 unownedList) == OC_STACK_OK)
1184 std::cout <<"Owned Device' status for" <<std::endl;
1185 for (unsigned int i = 0; i < ownedList.size(); i++ )
1187 std::cout << "Device "<<i+1 <<" ID: '";
1188 std::cout << ownedList[i]->getDeviceID() << "' From IP: ";
1189 std::cout << ownedList[i]->getDevAddr() << " Status: ";
1190 printStatus(ownedList[i]->getDeviceStatus());
1192 std::cout <<"\nUnOwned Device' status for" <<std::endl;
1193 for (unsigned int i = 0; i < unownedList.size(); i++ )
1195 std::cout << "Device "<<i+1 <<" ID: '";
1196 std::cout << unownedList[i]->getDeviceID() << "' From IP: ";
1197 std::cout << unownedList[i]->getDevAddr() << " Status: ";
1198 printStatus(unownedList[i]->getDeviceStatus());
1207 unsigned int devNum;
1209 if (!pOwnedDevList.size())
1211 std::cout <<"There are no Owned devices yet,"
1212 " may need to discover"<<std::endl;
1216 for (unsigned int i = 0; i < pOwnedDevList.size(); i++ )
1218 std::cout << i+1 << ": "<< pOwnedDevList[i]->getDeviceID() <<" From IP:";
1219 std::cout << pOwnedDevList[i]->getDevAddr() <<std::endl;
1222 std::cout <<"Select device number: "<<std::endl;
1224 if (devNum > pOwnedDevList.size())
1226 std::cout <<"Invalid device number"<<std::endl;
1231 provisionDP(devNum);
1242 catch(OCException& e)
1244 oclog() << "Exception in main: "<<e.what();