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 "provisioningapi.h"
29 #include "oic_string.h"
31 #define ES_PROV_ADAP_TAG "ES_PROVISIONING_ADAPTER"
33 //Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
34 char ipv4addr[IPV4_ADDR_SIZE] =
37 #ifdef REMOTE_ARDUINO_ENROLEE
38 //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
39 // to Arduino WiFi enrollee
40 static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.r.prov";
42 static const char * UNICAST_PROVISIONING_QUERY = "/oic/res?rt=oic.r.prov";
45 volatile static OCProvisioningStatusCB cbData = NULL;
47 OCStackResult InitProvProcess()
50 OCStackResult result = OC_STACK_ERROR;
52 if (InitProvisioningHandler() == OC_STACK_OK)
55 OIC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success");
59 result = OC_STACK_ERROR;
60 OIC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d",
67 OCStackResult ResetProvProcess()
69 return TerminateProvisioningHandler();
72 OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback)
74 OCStackResult result = OC_STACK_OK;
76 if (provisioningStatusCallback != NULL)
78 cbData = provisioningStatusCallback;
82 result = OC_STACK_ERROR;
83 OIC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
89 void UnRegisterCallback()
97 OCStackResult StartProvisioning(const ProvConfig *provConfig, WiFiOnboadingConnection *onboardConn)
100 char findQuery[MAX_QUERY_LENGTH] =
103 if (provConfig == NULL || onboardConn == NULL)
105 return OC_STACK_ERROR;
108 #ifdef REMOTE_ARDUINO_ENROLEE
109 //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
110 // to Arduino WiFi enrollee
111 snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY,
112 onboardConn->ipAddress, IP_PORT);
114 OICStrcpy(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY);
117 return StartProvisioningProcess(provConfig, onboardConn, cbData, findQuery);
120 OCStackResult StopProvisioning(OCConnectivityType /*connectivityType*/)
122 OCStackResult result = OC_STACK_OK;
124 StopProvisioningProcess();