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 *gSelectedNetworkList = 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(uint32_t ConnectivityType)
39 if (gSelectedNetworkList == NULL)
41 OIC_LOG_V(DEBUG, TAG, "Create network list");
43 gSelectedNetworkList = u_arraylist_create();
46 switch (ConnectivityType)
50 #ifndef ETHERNET_ADAPTER
51 OIC_LOG_V(DEBUG, TAG, "Add network type(ETHERNET) - Not Supported");
52 return CA_NOT_SUPPORTED;
53 #endif /* ETHERNET_ADAPTER */
55 OIC_LOG_V(DEBUG, TAG, "Add network type(ETHERNET)");
56 if (!u_arraylist_contains(gSelectedNetworkList, &NETWORK_ETHERNET))
58 u_arraylist_add(gSelectedNetworkList, &NETWORK_ETHERNET);
65 OIC_LOG_V(DEBUG, TAG, "Add network type(WIFI) - Not Supported");
66 return CA_NOT_SUPPORTED;
67 #endif /* WIFI_ADAPTER */
69 OIC_LOG_V(DEBUG, TAG, "Add network type(WIFI)");
70 if (!u_arraylist_contains(gSelectedNetworkList, &NETWORK_WIFI))
72 u_arraylist_add(gSelectedNetworkList, &NETWORK_WIFI);
79 OIC_LOG_V(DEBUG, TAG, "Add network type(EDR) - Not Supported");
80 return CA_NOT_SUPPORTED;
81 #endif /* EDR_ADAPTER */
83 OIC_LOG_V(DEBUG, TAG, "Add network type(EDR)");
84 if (!u_arraylist_contains(gSelectedNetworkList, &NETWORK_EDR))
86 u_arraylist_add(gSelectedNetworkList, &NETWORK_EDR);
93 OIC_LOG_V(DEBUG, TAG, "Add network type(LE) - Not Supported");
94 return CA_NOT_SUPPORTED;
95 #endif /* LE_ADAPTER */
97 OIC_LOG_V(DEBUG, TAG, "Add network type(LE)");
98 if (!u_arraylist_contains(gSelectedNetworkList, &NETWORK_LE))
100 u_arraylist_add(gSelectedNetworkList, &NETWORK_LE);
106 // start selected interface adapter
107 CAStartAdapter(ConnectivityType);
112 CAResult_t CARemoveNetworkType(uint32_t ConnectivityType)
117 if (gSelectedNetworkList == NULL)
119 OIC_LOG_V(DEBUG, TAG, "Selected network not found");
121 return CA_STATUS_FAILED;
124 for (index = 0; index < u_arraylist_length(gSelectedNetworkList); index++)
126 type = *(uint32_t*) u_arraylist_get(gSelectedNetworkList, index);
128 if(ConnectivityType == type)
130 switch (ConnectivityType)
134 #ifndef ETHERNET_ADAPTER
135 OIC_LOG_V(DEBUG, TAG, "Remove network type(ETHERNET) - Not Supported");
136 return CA_NOT_SUPPORTED;
139 OIC_LOG_V(DEBUG, TAG, "Remove network type(ETHERNET)");
140 u_arraylist_remove(gSelectedNetworkList, index);
141 #endif /* ETHERNET_ADAPTER */
147 OIC_LOG_V(DEBUG, TAG, "Remove network type(WIFI) - Not Supported");
148 return CA_NOT_SUPPORTED;
150 OIC_LOG_V(DEBUG, TAG, "Remove network type(WIFI)");
151 u_arraylist_remove(gSelectedNetworkList, index);
152 #endif /* WIFI_ADAPTER */
159 OIC_LOG_V(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
160 return CA_NOT_SUPPORTED;
162 OIC_LOG_V(DEBUG, TAG, "Remove network type(EDR)");
163 u_arraylist_remove(gSelectedNetworkList, index);
164 #endif /* EDR_ADAPTER */
171 OIC_LOG_V(DEBUG, TAG, "Remove network type(LE) - Not Supported");
172 return CA_NOT_SUPPORTED;
174 OIC_LOG_V(DEBUG, TAG, "Remove network type(LE)");
175 u_arraylist_remove(gSelectedNetworkList, index);
176 #endif /* LE_ADAPTER */
181 // stop selected interface adapter
182 CAStopAdapter(ConnectivityType);
189 u_arraylist_t *CAGetSelectedNetworkList()
191 OIC_LOG(DEBUG, TAG, "CAGetSelectedNetworkList IN");
192 if (gSelectedNetworkList == NULL)
194 OIC_LOG_V(DEBUG, TAG, "Selected network not found");
198 OIC_LOG(DEBUG, TAG, "CAGetSelectedNetworkList OUT");
199 return gSelectedNetworkList;
202 CAResult_t CAGetNetworkInformationInternal(CALocalConnectivity_t **info, uint32_t *size)
204 OIC_LOG_V(DEBUG, TAG, "get network information.");
206 return CAGetNetworkInfo(info, size);