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 "prov_adapter.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) {
67 EnrolleeNWProvInfo netInfo;
72 RegisterCallback(ProvisioningStatusCallback);
74 while ((opt = getopt(argc, argv, "d:s:p:")) != -1) {
77 strncpy(netInfo.netAddressInfo.WIFI.ipAddress, optarg, IPV4_ADDR_SIZE - 1);
80 strncpy(netInfo.netAddressInfo.WIFI.ssid, optarg, NET_WIFI_SSID_SIZE - 1);
83 strncpy(netInfo.netAddressInfo.WIFI.pwd, optarg, NET_WIFI_PWD_SIZE - 1);
91 netInfo.connType = CT_ADAPTER_IP;
92 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "IP Address of the Provisioning device is =%s\n",
93 netInfo.netAddressInfo.WIFI.ipAddress);
94 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "SSID of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.ssid);
95 OIC_LOG_V(INFO, ES_MEDIATOR_TAG, "Password of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.pwd);
97 StartProvisioning(&netInfo);
99 signal(SIGINT, handleSigInt);
105 OIC_LOG(INFO, ES_MEDIATOR_TAG, "Exiting occlient main loop...");