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 "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_CI = CA_ADAPTER_CLOUD_INTERFACE;
43 CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
45 OIC_LOG(DEBUG, TAG, "IN");
46 if (NULL == g_selectedNetworkList)
48 OIC_LOG(DEBUG, TAG, "Create network list");
50 g_selectedNetworkList = u_arraylist_create();
52 if (NULL == g_selectedNetworkList)
54 return CA_MEMORY_ALLOC_FAILED;
58 switch (transportType)
62 OIC_LOG(DEBUG, TAG, "Add network type(IP) - Not Supported");
63 return CA_NOT_SUPPORTED;
64 #endif /* IP_ADAPTER */
66 OIC_LOG(DEBUG, TAG, "Add network type(IP)");
67 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_IP))
71 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_IP);
74 case CA_ADAPTER_RFCOMM_BTEDR:
76 OIC_LOG(DEBUG, TAG, "Add network type(EDR) - Not Supported");
77 return CA_NOT_SUPPORTED;
78 #endif /* EDR_ADAPTER */
80 OIC_LOG(DEBUG, TAG, "Add network type(EDR)");
81 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RFCOMM))
85 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RFCOMM);
88 case CA_ADAPTER_GATT_BTLE:
90 OIC_LOG(DEBUG, TAG, "Add network type(LE) - Not Supported");
91 return CA_NOT_SUPPORTED;
92 #endif /* LE_ADAPTER */
94 OIC_LOG(DEBUG, TAG, "Add network type(LE)");
95 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_GATT))
99 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_GATT);
103 case CA_ADAPTER_REMOTE_ACCESS:
105 OIC_LOG(DEBUG, TAG, "Add network type(RA)");
106 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RA))
110 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RA);
112 #endif /* RA_ADAPTER */
115 case CA_ADAPTER_CLOUD_INTERFACE:
117 OIC_LOG(DEBUG, TAG, "Add network type(CI)");
118 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_CI))
122 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_CI);
124 #endif /* CI_ADAPTER */
132 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
133 return CA_STATUS_FAILED;
135 // start selected interface adapter
136 CAResult_t result = CAStartAdapter(transportType);
137 OIC_LOG(DEBUG, TAG, "OUT");
141 OIC_LOG(DEBUG, TAG, "This adapter is already enabled");
145 CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType)
147 OIC_LOG(DEBUG, TAG, "IN");
149 if (NULL == g_selectedNetworkList)
151 OIC_LOG(ERROR, TAG, "SelectedNetwork list is NULL");
153 return CA_STATUS_FAILED;
156 uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList);
157 for (uint32_t index = 0; index < selectedNetworkLength; index++)
159 void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
165 CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
167 if (transportType == connType)
169 switch (transportType)
173 OIC_LOG(DEBUG, TAG, "Remove network type(IP) - Not Supported");
174 return CA_NOT_SUPPORTED;
177 OIC_LOG(DEBUG, TAG, "Remove network type(IP)");
178 u_arraylist_remove(g_selectedNetworkList, index);
179 #endif /* IP_ADAPTER */
182 case CA_ADAPTER_RFCOMM_BTEDR:
184 OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
185 return CA_NOT_SUPPORTED;
187 OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
188 u_arraylist_remove(g_selectedNetworkList, index);
189 #endif /* EDR_ADAPTER */
192 case CA_ADAPTER_GATT_BTLE:
194 OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
195 return CA_NOT_SUPPORTED;
197 OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
198 u_arraylist_remove(g_selectedNetworkList, index);
199 #endif /* LE_ADAPTER */
203 case CA_ADAPTER_REMOTE_ACCESS:
204 OIC_LOG(DEBUG, TAG, "Remove network type(RA)");
205 u_arraylist_remove(g_selectedNetworkList, index);
207 #endif /* RA_ADAPTER */
210 case CA_ADAPTER_CLOUD_INTERFACE:
211 OIC_LOG(DEBUG, TAG, "Remove network type(RA)");
212 u_arraylist_remove(g_selectedNetworkList, index);
214 #endif /* CI_ADAPTER */
220 // stop selected interface adapter
221 CAStopAdapter(connType);
226 return CA_STATUS_FAILED;
229 u_arraylist_t *CAGetSelectedNetworkList()
231 return g_selectedNetworkList;
234 CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size)
236 OIC_LOG(DEBUG, TAG, "get network information.");
238 if (NULL == info || NULL == size)
240 OIC_LOG(ERROR, TAG, "Input parameter is invalid value");
242 return CA_STATUS_INVALID_PARAM;
245 return CAGetNetworkInfo(info, size);
248 CAResult_t CATerminateNetworkType()
250 OIC_LOG(DEBUG, TAG, "CATerminateNetworkType()");
251 if (NULL != g_selectedNetworkList)
253 u_arraylist_free(&g_selectedNetworkList);