1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
23 #include "canetworkconfigurator.h"
24 #include "cainterfacecontroller.h"
25 #include "uarraylist.h"
28 #define TAG "OIC_CA_NW_CONFIG"
30 static u_arraylist_t *g_selectedNetworkList = NULL;
33 static uint32_t NETWORK_RFCOMM = CA_ADAPTER_RFCOMM_BTEDR;
37 static uint32_t NETWORK_GATT = CA_ADAPTER_GATT_BTLE;
41 static uint32_t NETWORK_IP = CA_ADAPTER_IP;
45 static uint32_t NETWORK_NFC = CA_ADAPTER_NFC;
49 static uint32_t NETWORK_RA = CA_ADAPTER_REMOTE_ACCESS;
53 static uint32_t NETWORK_TCP = CA_ADAPTER_TCP;
56 CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
58 if (NULL == g_selectedNetworkList)
60 OIC_LOG(DEBUG, TAG, "Create network list");
62 g_selectedNetworkList = u_arraylist_create();
64 if (NULL == g_selectedNetworkList)
66 return CA_MEMORY_ALLOC_FAILED;
70 switch (transportType)
74 OIC_LOG(DEBUG, TAG, "Add network type(IP) - Not Supported");
75 return CA_NOT_SUPPORTED;
78 OIC_LOG(DEBUG, TAG, "Add network type(IP)");
79 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_IP))
83 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_IP);
88 case CA_ADAPTER_RFCOMM_BTEDR:
90 OIC_LOG(DEBUG, TAG, "Add network type(EDR) - Not Supported");
91 return CA_NOT_SUPPORTED;
94 OIC_LOG(DEBUG, TAG, "Add network type(EDR)");
95 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RFCOMM))
99 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RFCOMM);
102 #endif // EDR_ADAPTER
104 case CA_ADAPTER_GATT_BTLE:
106 OIC_LOG(DEBUG, TAG, "Add network type(LE) - Not Supported");
107 return CA_NOT_SUPPORTED;
110 OIC_LOG(DEBUG, TAG, "Add network type(LE)");
111 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_GATT))
115 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_GATT);
121 case CA_ADAPTER_REMOTE_ACCESS:
123 OIC_LOG(DEBUG, TAG, "Add network type(RA)");
124 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RA))
128 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RA);
135 OIC_LOG(DEBUG, TAG, "Add network type(TCP)");
136 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_TCP))
140 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_TCP);
142 #endif // TCP_ADAPTER
146 OIC_LOG(DEBUG, TAG, "Add network type(NFC) - Not Supported");
147 return CA_NOT_SUPPORTED;
150 OIC_LOG(DEBUG, TAG, "Add network type(NFC)");
151 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_NFC))
155 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_NFC);
158 #endif // CA_ADAPTER_NFC
166 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
167 return CA_STATUS_FAILED;
169 // start selected interface adapter
170 CAResult_t result = CAStartAdapter(transportType);
174 OIC_LOG(DEBUG, TAG, "This adapter is already enabled");
178 CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType)
180 if (NULL == g_selectedNetworkList)
182 OIC_LOG(ERROR, TAG, "SelectedNetwork list is NULL");
184 return CA_STATUS_FAILED;
187 uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList);
188 for (uint32_t index = 0; index < selectedNetworkLength; index++)
190 void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
196 CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
198 if (transportType == connType)
200 switch (transportType)
204 OIC_LOG(DEBUG, TAG, "Remove network type(IP) - Not Supported");
205 return CA_NOT_SUPPORTED;
208 OIC_LOG(DEBUG, TAG, "Remove network type(IP)");
209 u_arraylist_remove(g_selectedNetworkList, index);
214 case CA_ADAPTER_RFCOMM_BTEDR:
216 OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
217 return CA_NOT_SUPPORTED;
219 OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
220 u_arraylist_remove(g_selectedNetworkList, index);
223 #endif // EDR_ADAPTER
225 case CA_ADAPTER_GATT_BTLE:
227 OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
228 return CA_NOT_SUPPORTED;
230 OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
231 u_arraylist_remove(g_selectedNetworkList, index);
237 case CA_ADAPTER_REMOTE_ACCESS:
238 OIC_LOG(DEBUG, TAG, "Remove network type(RA)");
239 u_arraylist_remove(g_selectedNetworkList, index);
245 OIC_LOG(DEBUG, TAG, "Remove network type(TCP)");
246 u_arraylist_remove(g_selectedNetworkList, index);
248 #endif // TCP_ADAPTER
252 OIC_LOG(DEBUG, TAG, "Add network type(NFC) - Not Supported");
253 return CA_NOT_SUPPORTED;
255 OIC_LOG(DEBUG, TAG, "Add network type(NFC)");
256 u_arraylist_remove(g_selectedNetworkList, index);
259 #endif // CA_ADAPTER_NFC
264 // stop selected interface adapter
265 CAStopAdapter(connType);
270 return CA_STATUS_FAILED;
273 u_arraylist_t *CAGetSelectedNetworkList()
275 return g_selectedNetworkList;
278 CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size)
280 OIC_LOG(DEBUG, TAG, "get network information.");
282 if (NULL == info || NULL == size)
284 OIC_LOG(ERROR, TAG, "Input parameter is invalid value");
286 return CA_STATUS_INVALID_PARAM;
289 return CAGetNetworkInfo(info, size);
292 CAResult_t CATerminateNetworkType()
294 OIC_LOG(DEBUG, TAG, "CATerminateNetworkType()");
295 if (NULL != g_selectedNetworkList)
297 u_arraylist_free(&g_selectedNetworkList);