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 "uarraylist.h"
26 #include "cainterfacecontroller.h"
30 static u_arraylist_t *g_selectedNetworkList = NULL;
31 static uint32_t NETWORK_ETHERNET = CA_ETHERNET;
32 static uint32_t NETWORK_WIFI = CA_WIFI;
33 static uint32_t NETWORK_EDR = CA_EDR;
34 static uint32_t NETWORK_LE = CA_LE;
37 CAResult_t CAAddNetworkType(CAConnectivityType_t connectivityType)
39 if (g_selectedNetworkList == NULL)
41 OIC_LOG(DEBUG, TAG, "Create network list");
43 g_selectedNetworkList = u_arraylist_create();
45 if( g_selectedNetworkList == NULL )
47 return CA_MEMORY_ALLOC_FAILED;
51 CAResult_t res = CA_STATUS_OK;
52 switch (connectivityType)
57 #ifndef ETHERNET_ADAPTER
58 OIC_LOG(DEBUG, TAG, "Add network type(ETHERNET) - Not Supported");
59 return CA_NOT_SUPPORTED;
60 #endif /* ETHERNET_ADAPTER */
62 OIC_LOG(DEBUG, TAG, "Add network type(ETHERNET)");
63 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_ETHERNET))
65 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_ETHERNET);
74 OIC_LOG(DEBUG, TAG, "Add network type(WIFI) - Not Supported");
75 return CA_NOT_SUPPORTED;
76 #endif /* WIFI_ADAPTER */
78 OIC_LOG(DEBUG, TAG, "Add network type(WIFI)");
79 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_WIFI))
81 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_WIFI);
90 OIC_LOG(DEBUG, TAG, "Add network type(EDR) - Not Supported");
91 return CA_NOT_SUPPORTED;
92 #endif /* EDR_ADAPTER */
94 OIC_LOG(DEBUG, TAG, "Add network type(EDR)");
95 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_EDR))
97 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_EDR);
106 OIC_LOG(DEBUG, TAG, "Add network type(LE) - Not Supported");
107 return CA_NOT_SUPPORTED;
108 #endif /* LE_ADAPTER */
110 OIC_LOG(DEBUG, TAG, "Add network type(LE)");
111 if (!u_arraylist_contains(g_selectedNetworkList, &NETWORK_LE))
113 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_LE);
120 if (CA_STATUS_OK != res)
122 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
125 // start selected interface adapter
126 res = CAStartAdapter((CAConnectivityType_t)connectivityType);
131 CAResult_t CARemoveNetworkType(CAConnectivityType_t connectivityType)
134 CAConnectivityType_t connType;
136 if (g_selectedNetworkList == NULL)
138 OIC_LOG(DEBUG, TAG, "SelectedNetwork list is NULL");
140 return CA_STATUS_FAILED;
143 for (index = 0; index < u_arraylist_length(g_selectedNetworkList); index++)
145 void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
152 connType = *(CAConnectivityType_t *) ptrType;
154 if (connectivityType == connType)
156 switch (connectivityType)
160 #ifndef ETHERNET_ADAPTER
161 OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET) - Not Supported");
162 return CA_NOT_SUPPORTED;
165 OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET)");
166 u_arraylist_remove(g_selectedNetworkList, index);
167 #endif /* ETHERNET_ADAPTER */
173 OIC_LOG(DEBUG, TAG, "Remove network type(WIFI) - Not Supported");
174 return CA_NOT_SUPPORTED;
176 OIC_LOG(DEBUG, TAG, "Remove network type(WIFI)");
177 u_arraylist_remove(g_selectedNetworkList, index);
178 #endif /* WIFI_ADAPTER */
185 OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
186 return CA_NOT_SUPPORTED;
188 OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
189 u_arraylist_remove(g_selectedNetworkList, index);
190 #endif /* EDR_ADAPTER */
197 OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
198 return CA_NOT_SUPPORTED;
200 OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
201 u_arraylist_remove(g_selectedNetworkList, index);
202 #endif /* LE_ADAPTER */
207 // stop selected interface adapter
208 CAStopAdapter(connType);
213 return CA_STATUS_FAILED;
216 u_arraylist_t *CAGetSelectedNetworkList()
218 OIC_LOG(DEBUG, TAG, "CAGetSelectedNetworkList IN");
219 if (g_selectedNetworkList == NULL)
221 OIC_LOG(DEBUG, TAG, "SelectedNetwork list is NULL");
224 OIC_LOG(DEBUG, TAG, "CAGetSelectedNetworkList OUT");
225 return g_selectedNetworkList;
228 CAResult_t CAGetNetworkInformationInternal(CALocalConnectivity_t **info, uint32_t *size)
230 OIC_LOG(DEBUG, TAG, "get network information.");
232 if (info == NULL || size == NULL)
234 OIC_LOG(DEBUG, TAG, "Input parameter is invalid value");
236 return CA_STATUS_INVALID_PARAM;
239 return CAGetNetworkInfo(info, size);
242 CAResult_t CATerminateNetworkType()
244 OIC_LOG(DEBUG, TAG, "CATerminateNetworkType()");
246 if(g_selectedNetworkList != NULL)
248 u_arraylist_free(&g_selectedNetworkList);