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. Get Linked Devices"<<std::endl;
91 std::cout << " 10. Get Device Status"<<std::endl;
92 std::cout << " 11. Provision Direct-Pairing Configuration"<<std::endl;
93 std::cout << " 12. Exit loop"<<std::endl;
96 void moveTransferredDevice()
98 pOwnedDevList.push_back(pUnownedDevList[transferDevIdx]);
99 pUnownedDevList.erase(pUnownedDevList.begin() + transferDevIdx);
102 void InputPinCB(char* pinBuf, size_t bufSize)
106 std::cout <<"INPUT PIN : ";
109 OICStrcpy(pinBuf, bufSize, ptr.c_str());
114 void printUuid(OicUuid_t uuid)
116 for (int i = 0; i < UUID_LENGTH; i++)
118 std::cout <<std::hex << uuid.id[i] << " ";
120 std::cout<<std::endl;
123 void ownershipTransferCB(PMResultList_t *result, int hasError)
127 std::cout << "Error!!! in OwnershipTransfer"<<std::endl;
131 std::cout<< "\nTransferred Ownership successfuly for device : ";
132 printUuid(result->at(0).deviceId);
135 moveTransferredDevice();
140 void printStatus(int status)
142 static std::map<int, std::string> devStatus = {{1<<0, DEV_STATUS_ON}, {1<<1, DEV_STATUS_OFF}};
144 std::cout <<devStatus[status] <<std::endl;
147 void printDevices(DeviceList_t &list)
149 for (unsigned int i = 0; i < list.size(); i++ )
151 std::cout << "Device "<< i+1 <<" ID: ";
152 std::cout << list[i]->getDeviceID() << " From IP: ";
153 std::cout << list[i]->getDevAddr() << std::endl;
158 * Callback function for provisioning ACL, Credentials.
160 * @param[in] result Result list
161 * @param[in] hasError indicates if the result has error
163 void provisionCB(PMResultList_t *result, int hasError)
167 std::cout << "Error in provisioning operation!"<<std::endl;
171 std::cout<< "\nReceived provisioning results: ";
172 for (unsigned int i = 0; i < result->size(); i++)
174 std::cout << "Result is = " << result->at(i).res <<" for device ";
175 printUuid(result->at(i).deviceId);
185 * Ask user with which devices it wants to make further actions.
186 * All possible error checks included.
187 * Default behavior in case if only one options leaves are included too.
188 * Expect that user count devices from 1, f.e. 1st, 2nd, 3rd, etc
189 * Use DeviceList_t instead of devicesCount because of print devices info
191 * @param[in] list owned devices list.
192 * @param[out] out device number array.
193 * @param[in] count how many device numbers need to read.
194 * @return 0 in case of success and other value otherwise.
196 int readDeviceNumber(DeviceList_t &list, int count, int *out)
198 if (out == NULL || count <= 0)
200 std::cout << "Error! Please put valid input parameters" << std::endl;
204 int devicesCount = list.size();
206 //Print current list of owned devices
207 std::cout <<"Owned devices, count = " << devicesCount << std::endl;
210 if (devicesCount < count)
212 std::cout << "You can't proceed with selected action because Owned devices count ( ";
213 std::cout << devicesCount << " ) are less then required devices ( " << count << " ).";
214 std::cout << "You may need to discover devices again" << std::endl;
218 std::cout << "Select " << count << " device(s) for provisioning" << std::endl;
220 for (int curr = 0; curr < count; curr++)
222 //select last device by default if only 1 option exist
223 //from user's point of view device counting starts from 1,
224 //so 1st, 2nd, 3rd, etc devices
225 if ((curr == count - 1) && (devicesCount == count))
228 for (int i = 0; i < curr; i++)
233 out[curr] = (count*(count+1))/2 - sum;
235 std::cout << "Device " << curr + 1 << " : " << out[curr];
236 std::cout << " - selected automatically (because no other options exist)" << std::endl;
241 std::cout << "Device " << curr + 1 << " : ";
244 if (choice < 1 || choice > devicesCount)
246 std::cout << "Error! You should enter valid device number!" << std::endl;
250 //check that user doesn't select the same device twice
251 for (int i = 0; i < curr; i++)
253 if (out[i] == choice)
255 std::cout << "Error! You cannot select the same device twice!" << std::endl;
263 //Users count devices from 1, so 1st, 2nd, 3rd, etc device
264 //But deviceList array start index is 0, so need to decrease all numbers to 1
265 for (int i = 0; i < count; i++) out[i] -= 1;
271 * Perform cleanup for ACL
274 static void deleteACL(OicSecAcl_t *acl)
281 * Calculate ACL permission from string to bit
283 * @param[in] temp_psm Input data of ACL permission string
284 * @param[in,out] pms The pointer of ACL permission value
285 * @return 0 on success otherwise -1.
287 static int CalculateAclPermission(const char *temp_pms, uint16_t *pms)
291 if (NULL == temp_pms || NULL == pms)
296 while (temp_pms[i] != '\0')
345 * Get the ACL property from user
347 * @param[in] ACL Datastructure to save user inputs
348 * @return 0 on success otherwise -1.
350 static int InputACL(OicSecAcl_t *acl)
353 char *temp_id, *temp_rsc, *temp_pms;
355 printf("******************************************************************************\n");
356 printf("-Set ACL policy for target device\n");
357 printf("******************************************************************************\n");
359 printf("-URN identifying the subject\n");
360 printf("ex) 1111-1111-1111-1111 (16 Numbers except to '-')\n");
361 printf("Subject : ");
362 ret = scanf("%19ms", &temp_id);
364 OicSecAce_t* ace = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t));
367 OIC_LOG(ERROR, TAG, "Error while memory allocation");
370 LL_APPEND(acl->aces, ace);
374 for (int i = 0, j = 0; temp_id[i] != '\0'; i++)
376 if (DASH != temp_id[i])
377 ace->subjectuuid.id[j++] = temp_id[i];
384 printf("Error while input\n");
389 size_t resourcesLen = 0;
390 printf("Num. of Resource : ");
391 ret = scanf("%zu", &resourcesLen);
392 if ((1 != ret) || (resourcesLen <= 0 || resourcesLen > 50))
395 printf("Error while input\n");
398 printf("-URI of resource\n");
399 printf("ex)/oic/sh/temp/0 (Max_URI_Length: 64 Byte )\n");
400 for(size_t i = 0; i < resourcesLen; i++)
402 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
406 OIC_LOG(ERROR, TAG, "Error while memory allocation");
410 LL_APPEND(ace->resources, rsrc);
412 printf("[%zu]Resource : ", i + 1);
413 ret = scanf("%64ms", &temp_rsc);
416 printf("Error while input\n");
420 rsrc->href = OICStrdup(temp_rsc);
423 char* rsrc_in = NULL;
427 printf(" Enter Number of resource type for [%s]: ", rsrc_in);
428 for(int ret=0; 1!=ret; )
430 ret = scanf("%d", &arrLen);
431 for( ; 0x20<=getchar(); ); // for removing overflow garbages
432 // '0x20<=code' is character region
434 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
438 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
441 rsrc->typeLen = arrLen;
442 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
445 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
449 for(int i = 0; i < arrLen; i++)
451 printf(" Enter ResourceType[%d] Name: ", i+1);
452 for(int ret=0; 1!=ret; )
454 ret = scanf("%64ms", &rsrc_in); // '128' is ACL_RESRC_MAX_LEN
455 for( ; 0x20<=getchar(); ); // for removing overflow garbages
456 // '0x20<=code' is character region
458 rsrc->types[i] = OICStrdup(rsrc_in);
462 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
469 printf(" Enter Number of interface name for [%s]: ", rsrc_in);
470 for(int ret=0; 1!=ret; )
472 ret = scanf("%d", &arrLen);
473 for( ; 0x20<=getchar(); ); // for removing overflow garbages
474 // '0x20<=code' is character region
476 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
480 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
483 rsrc->interfaceLen = arrLen;
484 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
485 if(!rsrc->interfaces)
487 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
491 for(int i = 0; i < arrLen; i++)
493 printf(" Enter ResourceType[%d] Name: ", i+1);
494 for(int ret=0; 1!=ret; )
496 ret = scanf("%64ms", &rsrc_in); // '128' is ACL_RESRC_MAX_LEN
497 for( ; 0x20<=getchar(); ); // for removing overflow garbages
498 // '0x20<=code' is character region
500 rsrc->interfaces[i] = OICStrdup(rsrc_in);
502 if(!rsrc->interfaces[i])
504 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
514 printf("-Set the permission(C,R,U,D,N)\n");
515 printf("ex) CRUDN, CRU_N,..(5 Charaters)\n");
516 printf("Permission : ");
517 ret = scanf("%5ms", &temp_pms);
520 printf("Error while input\n");
523 ret = CalculateAclPermission(temp_pms, &(ace->permission));
528 printf("-URN identifying the rowner\n");
529 printf("ex) 1111-1111-1111-1111 (16 Numbers except to '-')\n");
532 ret = scanf("%19ms", &temp_id);
535 printf("Error while input\n");
539 for (int k = 0, j = 0; temp_id[k] != '\0'; k++)
541 if (DASH != temp_id[k])
543 acl->rownerID.id[j++] = temp_id[k];
555 static int InputCredentials(Credential &cred)
561 std::cout << "Select credential type from following values:" << std::endl;
562 std::cout << "1: symmetric pair-wise key" << std::endl;
563 std::cout << "2: symmetric group key" << std::endl;
564 std::cout << "4: asymmetric key" << std::endl;
565 std::cout << "8: signed asymmetric key (aka certificate)" << std::endl;
566 std::cout << "16: PIN /password" << std::endl;
567 std::cout << "Your choice: ";
573 cred.setCredentialType(static_cast<OicSecCredType_t>(choice));
574 choice = 0; //validation of the accepted choice.
580 std::cout << "selected type is not supported yet" << std::endl;
583 std::cout << "Error! Please select valid credential type" << std::endl;
586 } while(0 != choice);
588 std::cout << "Please enter key size (valid size is 128 or 256) :";
593 cred.setCredentialKeySize(OWNER_PSK_LENGTH_128);
595 else if(256 == choice)
597 cred.setCredentialKeySize(OWNER_PSK_LENGTH_256);
601 std::cout << "Error! Please enter valid key size!" << std::endl;
608 static void deletePconf()
610 OICFree(g_pconf.prm);
612 OicSecPdAcl_t* acl = g_pconf.pdacls;
615 /* Clean Resources */
616 for (unsigned int i = 0; i < (acl)->resourcesLen; i++)
618 OICFree((acl)->resources[i]);
620 OICFree((acl)->resources);
622 /* Clean ACL node itself */
623 /* Required only if acl was created in heap */
626 memset(&g_pconf, 0, sizeof(OicSecPconf_t));
629 static OicSecPdAcl_t* InputPdACL()
632 char *temp_rsc, *temp_pms;
634 printf("******************************************************************************\n");
635 printf("-Set ACL policy for target DP device\n");
636 printf("******************************************************************************\n");
638 OicSecPdAcl_t *acl = (OicSecPdAcl_t *)OICCalloc(1,sizeof(OicSecPdAcl_t));
641 OIC_LOG(ERROR, TAG, "Error while memory allocation");
646 printf("Num. of Resource : ");
647 ret = scanf("%zu", &acl->resourcesLen);
648 if ((1 != ret) || (acl->resourcesLen <= 0 || acl->resourcesLen > 50))
650 printf("Error while input\n");
654 printf("-URI of resource\n");
655 printf("ex)/oic/sh/temp/0 (Max_URI_Length: 64 Byte )\n");
656 acl->resources = (char **)OICCalloc(acl->resourcesLen, sizeof(char *));
657 if (NULL == acl->resources)
659 OIC_LOG(ERROR, TAG, "Error while memory allocation");
663 for (size_t i = 0; i < acl->resourcesLen; i++)
665 printf("[%zu]Resource : ", i + 1);
666 ret = scanf("%64ms", &temp_rsc);
669 printf("Error while input\n");
670 OICFree(acl->resources);
675 acl->resources[i] = OICStrdup(temp_rsc);
677 if (NULL == acl->resources[i])
679 OIC_LOG(ERROR, TAG, "Error while memory allocation");
680 OICFree(acl->resources);
689 printf("-Set the permission(C,R,U,D,N)\n");
690 printf("ex) CRUDN, CRU_N,..(5 Charaters)\n");
691 printf("Permission : ");
692 ret = scanf("%5ms", &temp_pms);
695 printf("Error while input\n");
696 OICFree(acl->resources);
700 ret = CalculateAclPermission(temp_pms, &(acl->permission));
707 void provisionDirectPairingCB(PMResultList_t *result, int hasError)
711 std::cout << "Error in provisioning operation!"<<std::endl;
715 std::cout<< "\nReceived provisioning results: Direct Pairing is successful ";
716 for (unsigned int i = 0; i < result->size(); i++)
718 std::cout << "Result is = " << result->at(i).res <<" for device ";
719 printUuid(result->at(i).deviceId);
729 static void provisionDP(int dev_num)
737 // set default supported PRM types
738 g_pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
739 g_pconf.prm = (OicSecPrm_t *)OICCalloc(g_pconf.prmLen, sizeof(OicSecPrm_t));
742 for (size_t i=0; i < g_pconf.prmLen; i++)
744 g_pconf.prm[i] = SUPPORTED_PRMS[i];
749 OIC_LOG(ERROR, TAG, "create prm error return");
753 std::cout << "Enter PIN to be configured: ";
757 if (pin.length() == DP_PIN_LENGTH)
763 std::cout << "PIN length should be 8, Enter again: ";
767 memcpy(g_pconf.pin.val, pin.c_str(), DP_PIN_LENGTH);
771 g_pconf.pdacls = InputPdACL();
774 OIC_LOG(ERROR, TAG, "InputPdACL error return");
778 // call |OCProvisionDirectPairing| API actually
779 // calling this API with callback actually acts like blocking
780 // for error checking, the return value saved and printed
781 rst = pOwnedDevList[dev_num-1]->provisionDirectPairing(&g_pconf, provisionDirectPairingCB);
782 if(OC_STACK_OK != rst)
784 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
785 if (OC_STACK_UNAUTHORIZED_REQ == rst)
787 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
794 deletePconf(); // after here |acl| points nothing
800 OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
802 // Create PlatformConfig object
804 OC::ServiceType::InProc,
808 OC::QualityOfService::LowQos,
812 OCPlatform::Configure(cfg);
817 OicSecAcl_t *acl1 = nullptr, *acl2 = nullptr;
818 if (OCSecure::provisionInit("") != OC_STACK_OK)
820 std::cout <<"PM Init failed"<< std::endl;
824 for (int out = 0; !out;)
848 //Secure resource discovery.
850 pUnownedDevList.clear();
851 std::cout << "Started discovery..." <<std::endl;
852 OCStackResult result = OCSecure::discoverUnownedDevices(DISCOVERY_TIMEOUT,
854 if (result != OC_STACK_OK)
856 std::cout<< "!!Error - UnOwned Discovery failed."<<std::endl;
858 else if (pUnownedDevList.size())
860 std::cout <<"Found secure devices, count = " <<
861 pUnownedDevList.size() << std::endl;
862 printDevices(pUnownedDevList);
866 std::cout <<"No Secure devices found"<<std::endl;
872 pOwnedDevList.clear();
873 std::cout << "Started discovery..." <<std::endl;
874 OCStackResult result = OCSecure::discoverOwnedDevices(DISCOVERY_TIMEOUT,
876 if (result != OC_STACK_OK)
878 std::cout<< "!!Error - Owned Discovery failed."<<std::endl;
880 else if (pOwnedDevList.size())
882 std::cout <<"Found owned devices, count = " <<
883 pOwnedDevList.size() << std::endl;
884 printDevices(pOwnedDevList);
888 std::cout <<"No Secure devices found"<<std::endl;
896 if (!pUnownedDevList.size())
898 std::cout <<"There are no more Unowned devices"<<std::endl;
902 for (unsigned int i = 0; i < pUnownedDevList.size(); i++ )
904 std::cout << i+1 << ": "<< pUnownedDevList[i]->getDeviceID();
905 std::cout << " From IP:" << pUnownedDevList[i]->getDevAddr() <<std::endl;
908 std::cout <<"Select device number: "<<std::endl;
910 if (devNum > pUnownedDevList.size())
912 std::cout <<"Invalid device number"<<std::endl;
915 transferDevIdx = devNum - 1;
917 //register callbacks for JUST WORKS and PIN methods
918 std::cout <<"Registering OTM Methods: 1. JUST WORKS and 2. PIN"<<std::endl;
921 OTMCallbackData_t justWorksCBData;
922 justWorksCBData.loadSecretCB = LoadSecretJustWorksCallback;
923 justWorksCBData.createSecureSessionCB =
924 CreateSecureSessionJustWorksCallback;
925 justWorksCBData.createSelectOxmPayloadCB =
926 CreateJustWorksSelectOxmPayload;
927 justWorksCBData.createOwnerTransferPayloadCB =
928 CreateJustWorksOwnerTransferPayload;
929 OCSecure::setOwnerTransferCallbackData(OIC_JUST_WORKS,
930 &justWorksCBData, NULL);
934 OTMCallbackData_t pinBasedCBData;
935 pinBasedCBData.loadSecretCB = InputPinCodeCallback;
936 pinBasedCBData.createSecureSessionCB =
937 CreateSecureSessionRandomPinCallback;
938 pinBasedCBData.createSelectOxmPayloadCB =
939 CreatePinBasedSelectOxmPayload;
940 pinBasedCBData.createOwnerTransferPayloadCB =
941 CreatePinBasedOwnerTransferPayload;
942 OCSecure::setOwnerTransferCallbackData(OIC_RANDOM_DEVICE_PIN,
943 &pinBasedCBData, InputPinCB);
947 std::cout << "Transfering ownership for : "<<
948 pUnownedDevList[devNum-1]->getDeviceID()<<std::endl;
949 if (pUnownedDevList[devNum-1]->doOwnershipTransfer(ownershipTransferCB)
952 std::cout<<"OwnershipTransferCallback is failed"<<std::endl;
957 case 4: //Provision ACL
961 if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
963 std::cout << "Provision ACL for : "<<
964 pOwnedDevList[index]->getDeviceID()<< std::endl;
966 acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
969 OIC_LOG(ERROR, TAG, "Error while memory allocation");
973 std::cout << "Please input ACL for selected device: " << std::endl;
974 if (0 != InputACL(acl1))
981 if (pOwnedDevList[index]->provisionACL(acl1, provisionCB) != OC_STACK_OK)
984 std::cout <<"provisionACL is failed"<< std::endl;
988 case 5: //Provision Credentials
992 if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
994 int first = devices[0];
995 int second = devices[1];
997 std::cout << "Provision Credentials to devices: "<<
998 pOwnedDevList[first]->getDeviceID();
999 std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
1001 Credential cred( NO_SECURITY_MODE ,0);
1002 std::cout << "Please input credentials for selected devices: " << std::endl;
1003 if (0 != InputCredentials(cred))
1008 if (pOwnedDevList[first]->provisionCredentials(cred,
1009 *pOwnedDevList[second].get(), provisionCB) != OC_STACK_OK)
1012 std::cout <<"provisionCredentials is failed"<< std::endl;
1016 case 6: //Provision ACL & Creds b/w two devices.
1020 if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
1022 int first = devices[0];
1023 int second = devices[1];
1025 std::cout << "Provision pairwise devices: "<<
1026 pOwnedDevList[first]->getDeviceID();
1027 std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
1029 Credential cred( NO_SECURITY_MODE, 0);
1030 std::cout << "Please input credentials for selected devices: " << std::endl;
1031 if (0 != InputCredentials(cred))
1034 acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
1037 OIC_LOG(ERROR, TAG, "Error while memory allocation");
1041 std::cout << "Please input ACL for selected device: " << std::endl;
1042 if (0 != InputACL(acl1))
1047 acl2 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
1050 OIC_LOG(ERROR, TAG, "Error while memory allocation");
1054 std::cout << "Please input ACL for selected device: " << std::endl;
1055 if (0 != InputACL(acl2))
1062 if (pOwnedDevList[first]->provisionPairwiseDevices(cred, acl1,
1063 *pOwnedDevList[second].get(), acl2, provisionCB) != OC_STACK_OK)
1066 std::cout <<"provisionPairwiseDevices is failed"<< std::endl;
1070 case 7: //Unlink Devices
1074 if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
1076 int first = devices[0];
1077 int second = devices[1];
1079 std::cout << "Unlink devices: "<< pOwnedDevList[first]->getDeviceID();
1080 std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
1084 if (pOwnedDevList[first]->unlinkDevices(*pOwnedDevList[second].get(),
1085 provisionCB) != OC_STACK_OK)
1088 std::cout <<"unlinkDevice is failed"<< std::endl;
1092 case 8: //Remove Device
1096 if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
1098 std::cout << "Remove Device: "<< pOwnedDevList[index]->getDeviceID()<< std::endl;
1102 if (pOwnedDevList[index]->removeDevice(DISCOVERY_TIMEOUT, provisionCB)
1106 std::cout <<"removeDevice is failed"<< std::endl;
1110 case 9: //Get Linked devices
1112 UuidList_t linkedUuid;
1113 unsigned int devNum;
1115 if (!pOwnedDevList.size())
1117 std::cout <<"There are no Owned devices yet,"
1118 " may need to discover"<<std::endl;
1122 for (unsigned int i = 0; i < pOwnedDevList.size(); i++ )
1124 std::cout << i+1 << ": "<< pOwnedDevList[i]->getDeviceID() <<" From IP:";
1125 std::cout << pOwnedDevList[i]->getDevAddr() <<std::endl;
1128 std::cout <<"Select device number: "<<std::endl;
1130 if (devNum > pOwnedDevList.size())
1132 std::cout <<"Invalid device number"<<std::endl;
1136 if(pOwnedDevList[devNum -1]->getLinkedDevices(linkedUuid) == OC_STACK_OK)
1138 if (!linkedUuid.size())
1140 std::cout <<"No devices are linked to "<<
1141 pOwnedDevList[devNum -1]->getDeviceID() << std::endl;
1143 //display the Linked devices (UUIDs)
1144 for(unsigned int i = 0; i < linkedUuid.size(); i++)
1146 printUuid(linkedUuid[i]);
1151 std::cout <<"Error! in getLinkedDevices"<<std::endl;
1155 case 10: //Get device' status
1157 DeviceList_t unownedList, ownedList;
1159 if (OCSecure::getDevInfoFromNetwork(DISCOVERY_TIMEOUT, ownedList,
1160 unownedList) == OC_STACK_OK)
1162 std::cout <<"Owned Device' status for" <<std::endl;
1163 for (unsigned int i = 0; i < ownedList.size(); i++ )
1165 std::cout << "Device "<<i+1 <<" ID: '";
1166 std::cout << ownedList[i]->getDeviceID() << "' From IP: ";
1167 std::cout << ownedList[i]->getDevAddr() << " Status: ";
1168 printStatus(ownedList[i]->getDeviceStatus());
1170 std::cout <<"\nUnOwned Device' status for" <<std::endl;
1171 for (unsigned int i = 0; i < unownedList.size(); i++ )
1173 std::cout << "Device "<<i+1 <<" ID: '";
1174 std::cout << unownedList[i]->getDeviceID() << "' From IP: ";
1175 std::cout << unownedList[i]->getDevAddr() << " Status: ";
1176 printStatus(unownedList[i]->getDeviceStatus());
1185 unsigned int devNum;
1187 if (!pOwnedDevList.size())
1189 std::cout <<"There are no Owned devices yet,"
1190 " may need to discover"<<std::endl;
1194 for (unsigned int i = 0; i < pOwnedDevList.size(); i++ )
1196 std::cout << i+1 << ": "<< pOwnedDevList[i]->getDeviceID() <<" From IP:";
1197 std::cout << pOwnedDevList[i]->getDevAddr() <<std::endl;
1200 std::cout <<"Select device number: "<<std::endl;
1202 if (devNum > pOwnedDevList.size())
1204 std::cout <<"Invalid device number"<<std::endl;
1209 provisionDP(devNum);
1220 catch(OCException& e)
1222 oclog() << "Exception in main: "<<e.what();