1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 "provisioningapi.h"
32 #define ES_MEDIATOR_TAG "easysetupsample"
36 /* SIGINT handler: set quitFlag to 1 for graceful termination */
37 void handleSigInt(int signum) {
38 if (signum == SIGINT) {
44 * This callback function is used to receive the notifications about the provisioning status
45 * In success or failure, ProvisioningInfo structure holds the current state of provisioning
46 * and also holds the Enrollee information for which provisioning is requested
47 * This function can be used to update the application about the current provisioning status of the Enrollee
49 void ProvisioningStatusCallback(ProvisioningInfo * provInfo) {
50 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "Enrollee connectivity: %d", provInfo->provDeviceInfo.connType);
51 if (provInfo->provStatus == DEVICE_PROVISIONED) {
52 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "Successfully provisioned the Enrollee with IP : %s ",
53 provInfo->provDeviceInfo.addr->addr);
56 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "Provisioing Failed for the Enrollee with IP : %s",
57 provInfo->provDeviceInfo.addr->addr);
61 static void PrintUsage() {
62 OIC_LOG(INFO, ES_MEDIATOR_TAG, "Usage : occlient -d \"192.168.0.20\"");
65 int main(int argc, char **argv) {
68 ProvConfig provConfig;
69 //WiFiOnboardingConfig onboardConfig;
70 WiFiOnboadingConnection onboardConn;
76 RegisterCallback(&ProvisioningStatusCallback);
78 while ((opt = getopt(argc, argv, "d:s:p:")) != -1) {
81 strncpy(onboardConn.ipAddress, optarg, IPV4_ADDR_SIZE - 1);
84 strncpy(provConfig.provData.WIFI.ssid, optarg, NET_WIFI_SSID_SIZE - 1);
87 strncpy(provConfig.provData.WIFI.pwd, optarg, NET_WIFI_PWD_SIZE - 1);
95 provConfig.connType = CT_ADAPTER_IP;
96 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "IP Address of the Provisioning device is =%s\n",
97 onboardConn.ipAddress);
98 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "SSID of the Enroller is =%s\n", provConfig.provData.WIFI.ssid);
99 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "Password of the Enroller is =%s\n", provConfig.provData.WIFI.pwd);
101 StartProvisioning(&provConfig, &onboardConn);
103 signal(SIGINT, handleSigInt);
105 OCStackResult result;
107 result = OCProcess();
109 if (result != OC_STACK_OK)
111 OIC_LOG(ERROR, "Mediator_CSDK", "OCStack stop error");
114 // To minimize CPU utilization we may wish to do this with sleep
119 OIC_LOG(INFO, ES_MEDIATOR_TAG, "Exiting occlient main loop...");