Merge "Implement functionality to set PSK credentials for DTLS in OC stack."
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / canetworkconfigurator.c
1 /******************************************************************
2  *
3  * Copyright 2014 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
21 #include <stdlib.h>
22
23 #include "canetworkconfigurator.h"
24 #include "uarraylist.h"
25 #include "logger.h"
26 #include "cainterfacecontroller.h"
27
28 #define TAG PCF("CA")
29
30 static u_arraylist_t *gSelectedNetworkList = NULL;
31
32 CAResult_t CAAddNetworkType(uint32_t ConnectivityType)
33 {
34     if (gSelectedNetworkList == NULL)
35     {
36         OIC_LOG_V(DEBUG, TAG, "Create network list");
37
38         gSelectedNetworkList = u_arraylist_create();
39     }
40
41     switch (ConnectivityType)
42     {
43         case CA_ETHERNET:
44
45 #ifndef ETHERNET_ADAPTER
46             OIC_LOG_V(DEBUG, TAG, "Add network type(ETHERNET) - Not Supported");
47             return CA_NOT_SUPPORTED;
48 #endif /* ETHERNET_ADAPTER */
49
50             OIC_LOG_V(DEBUG, TAG, "Add network type(ETHERNET)");
51             u_arraylist_add(gSelectedNetworkList, &NETWORK_ETHERNET);
52
53             break;
54
55         case CA_WIFI:
56
57 #ifndef WIFI_ADAPTER
58             OIC_LOG_V(DEBUG, TAG, "Add network type(WIFI) - Not Supported");
59             return CA_NOT_SUPPORTED;
60 #endif /* WIFI_ADAPTER */
61
62             OIC_LOG_V(DEBUG, TAG, "Add network type(WIFI)");
63             u_arraylist_add(gSelectedNetworkList, &NETWORK_WIFI);
64
65             break;
66
67         case CA_EDR:
68
69 #ifndef EDR_ADAPTER
70             OIC_LOG_V(DEBUG, TAG, "Add network type(EDR) - Not Supported");
71             return CA_NOT_SUPPORTED;
72 #endif /* EDR_ADAPTER */
73
74             OIC_LOG_V(DEBUG, TAG, "Add network type(EDR)");
75             u_arraylist_add(gSelectedNetworkList, &NETWORK_EDR);
76             break;
77
78         case CA_LE:
79
80 #ifdef LE_ADAPTER
81             OIC_LOG_V(DEBUG, TAG, "Add network type(LE) - Not Supported");
82             return CA_NOT_SUPPORTED;
83 #endif /* LE_ADAPTER */
84
85             OIC_LOG_V(DEBUG, TAG, "Add network type(LE)");
86             u_arraylist_add(gSelectedNetworkList, &NETWORK_LE);
87             break;
88
89     }
90
91     // start selected interface adapter
92     CAStartAdapter(ConnectivityType);
93
94     return CA_STATUS_OK;
95 }
96
97 CAResult_t CARemoveNetworkType(uint32_t ConnectivityType)
98 {
99     if (gSelectedNetworkList == NULL)
100     {
101         OIC_LOG_V(DEBUG, TAG, "Selected network not found");
102
103         return CA_STATUS_FAILED;
104     }
105
106     switch (ConnectivityType)
107     {
108         case CA_ETHERNET:
109
110 #ifndef ETHERNET_ADAPTER
111             OIC_LOG_V(DEBUG, TAG, "Remove network type(ETHERNET) - Not Supported");
112             return CA_NOT_SUPPORTED;
113 #else
114
115             OIC_LOG_V(DEBUG, TAG, "Remove network type(ETHERNET)");
116             u_arraylist_remove(gSelectedNetworkList, &NETWORK_ETHERNET);
117 #endif /* ETHERNET_ADAPTER */
118             break;
119
120         case CA_WIFI:
121
122 #ifndef WIFI_ADAPTER
123             OIC_LOG_V(DEBUG, TAG, "Remove network type(WIFI) - Not Supported");
124             return CA_NOT_SUPPORTED;
125 #else
126             OIC_LOG_V(DEBUG, TAG, "Remove network type(WIFI)");
127             u_arraylist_remove(gSelectedNetworkList, &NETWORK_WIFI);
128 #endif /* WIFI_ADAPTER */
129
130             break;
131
132         case CA_EDR:
133
134 #ifndef EDR_ADAPTER
135             OIC_LOG_V(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
136             return CA_NOT_SUPPORTED;
137 #else
138             OIC_LOG_V(DEBUG, TAG, "Remove network type(EDR)");
139             u_arraylist_remove(gSelectedNetworkList, &NETWORK_EDR);
140 #endif /* EDR_ADAPTER */
141
142             break;
143
144         case CA_LE:
145
146 #ifdef LE_ADAPTER
147             OIC_LOG_V(DEBUG, TAG, "Remove network type(LE) - Not Supported");
148             return CA_NOT_SUPPORTED;
149 #else
150             OIC_LOG_V(DEBUG, TAG, "Remove network type(LE)");
151             u_arraylist_remove(gSelectedNetworkList, &NETWORK_LE);
152 #endif /* LE_ADAPTER */
153
154             break;
155     }
156
157     // stop selected interface adapter
158     CAStopAdapter(ConnectivityType);
159
160     return CA_STATUS_OK;
161 }
162
163 u_arraylist_t* CAGetSelectedNetworkList()
164 {
165     if (gSelectedNetworkList == NULL)
166     {
167         OIC_LOG_V(DEBUG, TAG, "Selected network not found");
168
169         return NULL;
170     }
171
172     return gSelectedNetworkList;
173 }