X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Feasy-setup%2Fsampleapp%2Fenrollee%2Ftizen-sdb%2FEnrolleeSample%2Fenrolleewifi.cpp;h=8c7c58c436487e600d7322d00c7d75304cf6efdf;hb=c315c87e07c4080ecd0ef488e7a1047bc3c509b2;hp=caf002068c3ebc8e4d615b3c9940deb4a700bc2d;hpb=6a9d53f35cae085ba9c147114ab9b8db639a97a6;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp index caf0020..8c7c58c 100755 --- a/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp +++ b/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2015 Samsung Electronics All Rights Reserved. +// Copyright 2016 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -20,87 +20,147 @@ #include "easysetup.h" +#include "easysetup_wifi_conn.h" +#include #include #include #include - -#define TAG "TS" +#include +#include +#include +#define TAG "TIZEN_ES" using namespace std; -void *listeningFunc(void*); +gboolean mainThread(GIOChannel *source, GIOCondition condition, gpointer data); +void *listeningFunc(void *); -/** - * @var ssid - * @brief Target SSID of the Soft Access point to which the device has to connect - */ -static char ssid[] = "EasySetup123"; +GMainLoop *gMainloop; +static pthread_t gThreadHandle = 0; -/** - * @var passwd - * @brief Password of the Soft Access point to which the device has to connect - */ -static char passwd[] = "EasySetup123"; /** * Secure Virtual Resource database for Iotivity Server * It contains Server's Identity and the PSK credentials * of other devices which the server trusts */ -static char CRED_FILE[] = "oic_svr_db_server.json"; - -OCPersistentStorage ps ; +static char CRED_FILE[] = "oic_svr_db_server.dat"; +OCPersistentStorage ps; /** * @var gIsSecured * @brief Variable to check if secure mode is enabled or not. */ static bool gIsSecured = false; +static bool gWiFiCBflag = false; +static char gSSID[OIC_STRING_MAX_VALUE]; +static char gPasswd[OIC_STRING_MAX_VALUE]; void PrintMenu() { - cout<<"============"<numRequest ; ++i) + { + cout << "connect : " << connectRequest->connect[i] << endl; + } + + cout << "ConnectRequestCbInApp OUT" << endl; + PrintMenu(); +} + +void WiFiConfProvCbInApp(ESWiFiConfData *eventData) +{ + cout << "WiFiConfProvCbInApp IN" << endl; + gWiFiCBflag = true; + + ESSetState(ES_STATE_CONNECTING_TO_ENROLLER); + + if(eventData == NULL) + { + cout << "ESWiFiConfData is NULL" << endl; + return ; + } + + cout << "SSID : " << eventData->ssid << endl; + cout << "Password : " << eventData->pwd << endl; + cout << "AuthType : " << eventData->authtype << endl; + cout << "EncType : " << eventData->enctype << endl; + + memset(gSSID, 0, OIC_STRING_MAX_VALUE); + memset(gPasswd, 0, OIC_STRING_MAX_VALUE); + if(eventData->ssid != NULL) + { + strncpy(gSSID, eventData->ssid, strlen(eventData->ssid)); + } + + if(eventData->pwd != NULL) + { + strncpy(gPasswd, eventData->pwd, strlen(eventData->pwd)); + } + + cout << "WiFiConfProvCbInApp OUT" << endl; + PrintMenu(); +} + +void DevConfProvCbInApp(ESDevConfData *eventData) +{ + cout << "DevConfProvCbInApp IN" << endl; + + if(eventData == NULL) { - cout<<"Easy stup is failed at Enrollee state = "<authCode << endl; + cout << "AuthProvider : " << eventData->authProvider << endl; + cout << "CI Server : " << eventData->ciServer << endl; + cout << "CoapCloudConfProvCbInApp OUT" << endl; + PrintMenu(); +} + +ESProvisioningCallbacks gCallbacks = { + .ConnectRequestCb = &ConnectRequestCbInApp, + .WiFiConfProvCb = &WiFiConfProvCbInApp, + .DevConfProvCb = &DevConfProvCbInApp, + .CoapCloudConfProvCb = &CoapCloudConfProvCbInApp +}; + FILE* server_fopen(const char *path, const char *mode) { (void) path; @@ -109,121 +169,233 @@ FILE* server_fopen(const char *path, const char *mode) void EnableSecurity() { - cout << "Inside EnableSecurity API.." << endl; + printf("Inside EnableSecurity API..\n"); gIsSecured = true; // Initialize Persistent Storage for SVR database - ps = { server_fopen, fread, fwrite, fclose, unlink }; + ps = (OCPersistentStorage){ server_fopen, fread, fwrite, fclose, unlink }; OCRegisterPersistentStorageHandler(&ps); } void StartEasySetup() { - cout<<"StartEasySetup and onboarding started.."<> entered; + cin.ignore(numeric_limits::max(), '\n'); + + switch (entered) { + case 'Q': // quit + case 'q': + StopEasySetup(); + break; + + case 'A': // Enable Security + case 'a': +#ifdef __WITH_DTLS__ + EnableSecurity(); +#else + cout << "Sample is not built with secured mode" << endl; +#endif + PrintMenu(); + break; + + case 'B': // Init EasySetup + case 'b': + StartEasySetup(); + PrintMenu(); + break; + + case 'C': // Set Device Info + case 'c': + SetDeviceInfo(); + PrintMenu(); + break; + + case 'D': // Start to connect target AP + case 'd': + ConnectToTargetAP(); + PrintMenu(); + break; + + case 'E': // Print Menu + case 'e': + PrintMenu(); + break; + + default: + cout << "Wrong option" << endl; + PrintMenu(); + break; + } - cout<<"StopEasySetup OUT"<>option; - switch (option) - { - case 'H': // help - case 'h': - PrintMenu(); - break; - - case 'Q': // quit - case 'q': - cout<<"quit"; - break; - - case 'S': // Enable Security - case 's': - EnableSecurity(); - break; - - case 'I': // Init EasySetup - case 'i': - StartEasySetup(); - break; - - case 'P': // start provisioning - case 'p': - StartOICStackAndStartResources(); - break; - - case 'T': // stop easy setup - case 't': - StopEasySetup(); - break; - - default: - cout<<"wrong option"<