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"
29 #include "oic_string.h"
32 #define ES_PROV_ADAP_TAG "ES_PROVISIONING_ADAPTER"
34 //Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
35 char ipv4addr[IPV4_ADDR_SIZE] = {0};
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) {
54 OIC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success");
56 result = OC_STACK_ERROR;
57 OIC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d",
64 OCStackResult ResetProvProcess() {
65 return TerminateProvisioningHandler();
68 OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback) {
69 OCStackResult result = OC_STACK_OK;
71 if (provisioningStatusCallback != NULL) {
72 cbData = provisioningStatusCallback;
75 result = OC_STACK_ERROR;
76 OIC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
82 void UnRegisterCallback() {
88 OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo) {
90 char findQuery[64] = {0};
92 #ifdef REMOTE_ARDUINO_ENROLEE
93 //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
94 // to Arduino WiFi enrollee
95 snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY,
96 netInfo->netAddressInfo.WIFI.ipAddress, IP_PORT);
98 OICStrcpy(findQuery, sizeof(findQuery)-1, UNICAST_PROVISIONING_QUERY);
101 return StartProvisioningProcess(netInfo, cbData, findQuery);
104 OCStackResult StopProvisioning(OCConnectivityType /*connectivityType*/) {
105 OCStackResult result = OC_STACK_OK;
107 StopProvisioningProcess();