Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / easy-setup / enrollee / src / softap.c
1 //      http://www.apache.org/licenses/LICENSE-2.0
2 //
3 // Unless required by applicable law or agreed to in writing, software
4 // distributed under the License is distributed on an "AS IS" BASIS,
5 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6 // See the License for the specific language governing permissions and
7 // limitations under the License.
8 //
9 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
10
11 /**
12  * These are adapter APIs will make caller modules agnostic to platform.
13  */
14
15 #include "softapnative.h"
16 #include "easysetup.h"
17 #include "softap.h"
18 #include "networkhandler.h"
19
20 void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
21                                                             const char* device_name );
22
23 ESEnrolleeNetworkEventCallback gCallback;
24
25 /**
26  * It will return Device which is creating Soft AP.
27  * i.e.Enrollee or Mediator.
28  * This decesion is based on, what is the value set for ES_SOFTAP_MODE in build command as well as 
29  * in iotivity.spec file.
30  */
31 DeviceRole ESSoftapHost()
32 {
33 #ifdef ENROLLEE_SOFTAP
34     //SoftAp at enrollee
35     return ENROLLEE;
36 #else
37     //SoftAp at mediator
38     return MEDIATOR;
39 #endif
40 }
41
42 /**
43  * It will return true if the Soft AP is created at Enrollee device
44  */
45 bool ESSoftapAtEnrollee()
46 {
47     return ( ESSoftapHost() == ENROLLEE) ? true : false;
48 }
49
50 /**
51  * It will return true if the Soft AP is created at Mediator device
52  */
53 bool ESSoftapAtMediator()
54 {
55     return (ESSoftapHost() == MEDIATOR) ? true : false;
56 }
57
58 /**
59  * This API will map result returned from the native to the caller.
60  * Callback API's signature needs to be modified under build switch according
61  * to the underline platform.
62  */
63 void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
64                                                                 const char* device_name)
65 {
66     if(SOFTAP_SUCCESS ==  result) //on Success
67     {
68         gCallback(ES_OK);
69     }
70     else //on Failure
71     {
72         gCallback(ES_ERROR);
73     }
74 }
75
76 /**
77  * This API will create the softap at enrollee
78  */
79 void ESCreateSoftap(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb)
80 {
81     gCallback = cb;
82
83     // TODO: To be implemented
84     // Create Soft AP through native APIs -- start
85     // native API call by and pass ESCreateSoftapCallback() as callback
86     ESCreateSoftapNative(ssid, passwd,ESCreateSoftapCallback);
87     // Create Soft AP through native APIs -- end
88 }
89