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;
31 static uint32_t NETWORK_IP = CA_ADAPTER_IP;
32 static uint32_t NETWORK_RFCOMM = CA_ADAPTER_RFCOMM_BTEDR;
33 static uint32_t NETWORK_GATT = CA_ADAPTER_GATT_BTLE;
36 static uint32_t NETWORK_RA = CA_ADAPTER_REMOTE_ACCESS;
40 static uint32_t NETWORK_TCP = CA_ADAPTER_TCP;
43 CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
45 if (NULL == g_selectedNetworkList)
47 OIC_LOG(DEBUG, TAG, "Create network list");
49 g_selectedNetworkList = u_arraylist_create();
51 if (NULL == g_selectedNetworkList)
53 return CA_MEMORY_ALLOC_FAILED;
57 switch (transportType)
61 OIC_LOG(DEBUG, TAG, "Add network type(IP) - Not Supported");
62 return CA_NOT_SUPPORTED;
63 #endif /* IP_ADAPTER */
65 OIC_LOG(DEBUG, TAG, "Add network type(IP)");
66 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_IP))
70 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_IP);
73 case CA_ADAPTER_RFCOMM_BTEDR:
75 OIC_LOG(DEBUG, TAG, "Add network type(EDR) - Not Supported");
76 return CA_NOT_SUPPORTED;
77 #endif /* EDR_ADAPTER */
79 OIC_LOG(DEBUG, TAG, "Add network type(EDR)");
80 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RFCOMM))
84 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RFCOMM);
87 case CA_ADAPTER_GATT_BTLE:
89 OIC_LOG(DEBUG, TAG, "Add network type(LE) - Not Supported");
90 return CA_NOT_SUPPORTED;
91 #endif /* LE_ADAPTER */
93 OIC_LOG(DEBUG, TAG, "Add network type(LE)");
94 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_GATT))
98 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_GATT);
102 case CA_ADAPTER_REMOTE_ACCESS:
104 OIC_LOG(DEBUG, TAG, "Add network type(RA)");
105 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RA))
109 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RA);
111 #endif /* RA_ADAPTER */
116 OIC_LOG(DEBUG, TAG, "Add network type(TCP)");
117 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_TCP))
121 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_TCP);
123 #endif /* TCP_ADAPTER */
131 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
132 return CA_STATUS_FAILED;
134 // start selected interface adapter
135 CAResult_t result = CAStartAdapter(transportType);
139 OIC_LOG(DEBUG, TAG, "This adapter is already enabled");
143 CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType)
145 if (NULL == g_selectedNetworkList)
147 OIC_LOG(ERROR, TAG, "SelectedNetwork list is NULL");
149 return CA_STATUS_FAILED;
152 uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList);
153 for (uint32_t index = 0; index < selectedNetworkLength; index++)
155 void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
161 CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
163 if (transportType == connType)
165 switch (transportType)
169 OIC_LOG(DEBUG, TAG, "Remove network type(IP) - Not Supported");
170 return CA_NOT_SUPPORTED;
173 OIC_LOG(DEBUG, TAG, "Remove network type(IP)");
174 u_arraylist_remove(g_selectedNetworkList, index);
175 #endif /* IP_ADAPTER */
178 case CA_ADAPTER_RFCOMM_BTEDR:
180 OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
181 return CA_NOT_SUPPORTED;
183 OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
184 u_arraylist_remove(g_selectedNetworkList, index);
185 #endif /* EDR_ADAPTER */
188 case CA_ADAPTER_GATT_BTLE:
190 OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
191 return CA_NOT_SUPPORTED;
193 OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
194 u_arraylist_remove(g_selectedNetworkList, index);
195 #endif /* LE_ADAPTER */
199 case CA_ADAPTER_REMOTE_ACCESS:
200 OIC_LOG(DEBUG, TAG, "Remove network type(RA)");
201 u_arraylist_remove(g_selectedNetworkList, index);
203 #endif /* RA_ADAPTER */
207 OIC_LOG(DEBUG, TAG, "Remove network type(TCP)");
208 u_arraylist_remove(g_selectedNetworkList, index);
210 #endif /* TCP_ADAPTER */
216 // stop selected interface adapter
217 CAStopAdapter(connType);
222 return CA_STATUS_FAILED;
225 u_arraylist_t *CAGetSelectedNetworkList()
227 return g_selectedNetworkList;
230 CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size)
232 OIC_LOG(DEBUG, TAG, "get network information.");
234 if (NULL == info || NULL == size)
236 OIC_LOG(ERROR, TAG, "Input parameter is invalid value");
238 return CA_STATUS_INVALID_PARAM;
241 return CAGetNetworkInfo(info, size);
244 CAResult_t CATerminateNetworkType()
246 OIC_LOG(DEBUG, TAG, "CATerminateNetworkType()");
247 if (NULL != g_selectedNetworkList)
249 u_arraylist_free(&g_selectedNetworkList);