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;
35 CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
37 OIC_LOG(DEBUG, TAG, "IN");
38 if (NULL == g_selectedNetworkList)
40 OIC_LOG(DEBUG, TAG, "Create network list");
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 (transportType)
54 OIC_LOG(DEBUG, TAG, "Add network type(IP) - Not Supported");
55 return CA_NOT_SUPPORTED;
56 #endif /* IP_ADAPTER */
58 OIC_LOG(DEBUG, TAG, "Add network type(IP)");
59 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_IP))
63 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_IP);
66 case CA_ADAPTER_RFCOMM_BTEDR:
68 OIC_LOG(DEBUG, TAG, "Add network type(EDR) - Not Supported");
69 return CA_NOT_SUPPORTED;
70 #endif /* EDR_ADAPTER */
72 OIC_LOG(DEBUG, TAG, "Add network type(EDR)");
73 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RFCOMM))
77 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RFCOMM);
80 case CA_ADAPTER_GATT_BTLE:
82 OIC_LOG(DEBUG, TAG, "Add network type(LE) - Not Supported");
83 return CA_NOT_SUPPORTED;
84 #endif /* LE_ADAPTER */
86 OIC_LOG(DEBUG, TAG, "Add network type(LE)");
87 if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_GATT))
91 res = u_arraylist_add(g_selectedNetworkList, &NETWORK_GATT);
97 if (CA_STATUS_OK != res)
99 OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
102 // start selected interface adapter
103 res = CAStartAdapter(transportType);
104 OIC_LOG(DEBUG, TAG, "OUT");
108 OIC_LOG(DEBUG, TAG, "This adapter is already enabled");
112 CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType)
114 OIC_LOG(DEBUG, TAG, "IN");
116 if (NULL == g_selectedNetworkList)
118 OIC_LOG(ERROR, TAG, "SelectedNetwork list is NULL");
120 return CA_STATUS_FAILED;
123 uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList);
124 for (uint32_t index = 0; index < selectedNetworkLength; index++)
126 void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
132 CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
134 if (transportType == connType)
136 switch (transportType)
140 OIC_LOG(DEBUG, TAG, "Remove network type(IP) - Not Supported");
141 return CA_NOT_SUPPORTED;
144 OIC_LOG(DEBUG, TAG, "Remove network type(IP)");
145 u_arraylist_remove(g_selectedNetworkList, index);
146 #endif /* IP_ADAPTER */
149 case CA_ADAPTER_RFCOMM_BTEDR:
151 OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
152 return CA_NOT_SUPPORTED;
154 OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
155 u_arraylist_remove(g_selectedNetworkList, index);
156 #endif /* EDR_ADAPTER */
159 case CA_ADAPTER_GATT_BTLE:
161 OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
162 return CA_NOT_SUPPORTED;
164 OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
165 u_arraylist_remove(g_selectedNetworkList, index);
166 #endif /* LE_ADAPTER */
173 // stop selected interface adapter
174 CAStopAdapter(connType);
179 return CA_STATUS_FAILED;
182 u_arraylist_t *CAGetSelectedNetworkList()
184 return g_selectedNetworkList;
187 CAResult_t CAGetNetworkInformationInternal(CAEndpoint_t **info, uint32_t *size)
189 OIC_LOG(DEBUG, TAG, "get network information.");
191 if (NULL == info || NULL == size)
193 OIC_LOG(ERROR, TAG, "Input parameter is invalid value");
195 return CA_STATUS_INVALID_PARAM;
198 return CAGetNetworkInfo(info, size);
201 CAResult_t CATerminateNetworkType()
203 OIC_LOG(DEBUG, TAG, "CATerminateNetworkType()");
204 if (NULL != g_selectedNetworkList)
206 u_arraylist_free(&g_selectedNetworkList);