Merge branch 'master' into easysetup & CBOR changes
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / src / easysetupmgr.cpp
1  //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <signal.h>
24 #include <unistd.h>
25 #include <stdint.h>
26 #include <sstream>
27
28 #include "easysetupmgr.h"
29
30 //Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
31 char ipv4addr[IPV4_ADDR_SIZE] = { 0 };
32
33 static OCProvisioningStatusCB cbData = NULL;
34
35 OCStackResult InitEasySetupManager() {
36         
37         
38     OCStackResult result = OC_STACK_ERROR;
39
40     if (InitProvisioningHandler() == OC_STACK_OK) {
41         result = OC_STACK_OK;
42         OIC_LOG(DEBUG, TAG, "InitProvisioningHandler returned Success");
43     } else {
44         result = OC_STACK_ERROR;
45         OIC_LOG_V(ERROR, TAG, "InitProvisioningHandler returned error = %s",
46                 result);
47     }
48
49     return result;
50 }
51
52 OCStackResult TerminateEasySetupManager() {
53     return TerminateProvisioningHandler();
54 }
55
56 OCStackResult RegisterProvisioningStausCallback(
57         OCProvisioningStatusCB provisioningStatusCallback) {
58     OCStackResult result = OC_STACK_OK;
59
60     if(provisioningStatusCallback != NULL)
61     {
62         cbData = provisioningStatusCallback;
63     }
64     else
65     {
66         result = OC_STACK_ERROR;
67         OIC_LOG(ERROR, TAG, "provisioningStatusCallback is NULL");
68     }
69
70     return result;
71 }
72
73 void UnRegisterProvisioningStausCallback() {
74     if (cbData) {
75         cbData = NULL;
76     }
77 }
78
79 OCStackResult ProvisionEnrollee(const EnrolleeNWProvInfo_t *netInfo)
80 {
81         return StartProvisioningProcess(netInfo, cbData);
82 }
83
84 OCStackResult StopEnrolleeProvisioning(OCConnectivityType connectivityType) {
85     OCStackResult result = OC_STACK_OK;
86
87     //TODO: Have to handle the transport specific easy setup termination
88     StopProvisioningProcess();
89
90     return result;
91 }
92