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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
28 #include "prov_adapter.h"
30 #define ES_PROV_ADAP_TAG "ES_PROVISIONING_ADAPTER"
32 //Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
33 char ipv4addr[IPV4_ADDR_SIZE] = {0};
35 static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.r.prov";
37 volatile static OCProvisioningStatusCB cbData = NULL;
39 OCStackResult InitProvProcess() {
42 OCStackResult result = OC_STACK_ERROR;
44 if (InitProvisioningHandler() == OC_STACK_OK) {
46 OC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success");
48 result = OC_STACK_ERROR;
49 OC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d",
56 OCStackResult ResetProvProcess() {
57 return TerminateProvisioningHandler();
60 OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback) {
61 OCStackResult result = OC_STACK_OK;
63 if (provisioningStatusCallback != NULL) {
64 cbData = provisioningStatusCallback;
67 result = OC_STACK_ERROR;
68 OC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
74 void UnRegisterCallback() {
80 OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo) {
82 char findQuery[64] = {0};
83 snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY,
84 netInfo->netAddressInfo.WIFI.ipAddress, IP_PORT);
86 return StartProvisioningProcess(netInfo, cbData, findQuery);
89 OCStackResult StopProvisioning(OCConnectivityType /*connectivityType*/) {
90 OCStackResult result = OC_STACK_OK;
92 StopProvisioningProcess();