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 ******************************************************************/
21 #include "cainterfacecontroller_singlethread.h"
25 #include "canetworkconfigurator.h"
26 #include "uarraylist.h"
31 static u_arraylist_t *g_selectedNetworkList = NULL;
32 static uint32_t NETWORK_ETHERNET = CA_ETHERNET;
33 static uint32_t NETWORK_WIFI = CA_WIFI;
34 static uint32_t NETWORK_EDR = CA_EDR;
35 static uint32_t NETWORK_LE = CA_LE;
37 CAResult_t CAAddNetworkType(CAConnectivityType_t connectivityType)
39 OIC_LOG(DEBUG, TAG, "IN");
40 if (g_selectedNetworkList == NULL)
42 g_selectedNetworkList = u_arraylist_create();
44 if (NULL == g_selectedNetworkList)
46 return CA_MEMORY_ALLOC_FAILED;
49 CAResult_t res = CA_STATUS_OK;
50 switch (connectivityType)
55 #ifndef ETHERNET_ADAPTER
56 OIC_LOG(DEBUG, TAG, "Add network type(ETHERNET) - Not Supported");
57 return CA_NOT_SUPPORTED;
58 #endif /* ETHERNET_ADAPTER */
60 OIC_LOG(DEBUG, TAG, "Add network type(ETHERNET)");
61 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_ETHERNET))
63 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_ETHERNET);
64 if (CA_STATUS_OK != res)
66 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
77 OIC_LOG(DEBUG, TAG, "Add network type(WIFI) - Not Supported");
78 return CA_NOT_SUPPORTED;
79 #endif /* WIFI_ADAPTER */
81 OIC_LOG(DEBUG, TAG, "Add network type(WIFI)");
82 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_WIFI))
84 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_WIFI);
85 if (CA_STATUS_OK != res)
87 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
98 OIC_LOG(DEBUG, TAG, "Add network type(EDR) - Not Supported");
99 return CA_NOT_SUPPORTED;
100 #endif /* EDR_ADAPTER */
102 OIC_LOG(DEBUG, TAG, "Add network type(EDR)");
103 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_EDR))
105 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_EDR);
106 if (CA_STATUS_OK != res)
108 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
119 OIC_LOG(DEBUG, TAG, "Add network type(LE) - Not Supported");
120 return CA_NOT_SUPPORTED;
121 #endif /* LE_ADAPTER */
123 OIC_LOG(DEBUG, TAG, "Add network type(LE)");
124 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_LE))
126 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_LE);
127 if (CA_STATUS_OK != res)
129 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
138 // start selected interface adapter
139 res = CAStartAdapter((CAConnectivityType_t)connectivityType);
140 OIC_LOG(DEBUG, TAG, "OUT");
144 CAResult_t CARemoveNetworkType(CAConnectivityType_t connectivityType)
146 OIC_LOG(DEBUG, TAG, "IN");
148 if (g_selectedNetworkList == NULL)
150 OIC_LOG(DEBUG, TAG, "Selected network not found");
152 return CA_STATUS_FAILED;
156 for (index = 0; index < u_arraylist_length(g_selectedNetworkList); index++)
158 void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
164 CAConnectivityType_t connType = *(CAConnectivityType_t *) ptrType;
166 if (connectivityType == connType)
168 switch (connectivityType)
172 #ifndef ETHERNET_ADAPTER
173 OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET) - Not Supported");
174 return CA_NOT_SUPPORTED;
177 OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET)");
178 u_arraylist_remove(g_selectedNetworkList, index);
179 #endif /* ETHERNET_ADAPTER */
185 OIC_LOG(DEBUG, TAG, "Remove network type(WIFI) - Not Supported");
186 return CA_NOT_SUPPORTED;
188 OIC_LOG(DEBUG, TAG, "Remove network type(WIFI)");
189 u_arraylist_remove(g_selectedNetworkList, index);
190 #endif /* WIFI_ADAPTER */
197 OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
198 return CA_NOT_SUPPORTED;
200 OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
201 u_arraylist_remove(g_selectedNetworkList, index);
202 #endif /* EDR_ADAPTER */
209 OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
210 return CA_NOT_SUPPORTED;
212 OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
213 u_arraylist_remove(g_selectedNetworkList, index);
214 #endif /* LE_ADAPTER */
219 // stop selected interface adapter
220 CAStopAdapter(connType);
227 u_arraylist_t *CAGetSelectedNetworkList()
229 return g_selectedNetworkList;
232 CAResult_t CAGetNetworkInformationInternal(CALocalConnectivity_t **info, uint32_t *size)
234 OIC_LOG(DEBUG, TAG, "get network information.");
236 if (info == NULL || size == NULL)
238 OIC_LOG(DEBUG, TAG, "Input parameter is invalid value");
240 return CA_STATUS_INVALID_PARAM;
243 return CAGetNetworkInfo(info, size);
246 CAResult_t CATerminateNetworkType()
248 OIC_LOG(DEBUG, TAG, "CATerminateNetworkType()");
249 if(g_selectedNetworkList != NULL)
251 u_arraylist_free(&g_selectedNetworkList);