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 ******************************************************************/
24 * This file provides helper functions for EDR adapter.
27 #include "caedrutils.h"
29 #include <bluetooth.h>
32 #include "uarraylist.h"
35 * Pending devices list for data transfer.
37 static u_arraylist_t *g_deviceStateList = NULL;
39 bool CAEDRIsServiceSupported(const char **serviceUUID, int32_t serviceCount,
40 const char *matchService)
42 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
44 if (NULL == serviceUUID || 0 == serviceCount || NULL == matchService)
46 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Invalid input");
50 for (int i = 0; i < serviceCount; i++)
52 if (!strcasecmp(serviceUUID[i], matchService))
54 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Service found !");
59 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
63 CAConnectedDeviceInfo_t *CAEDRGetDeviceInfoFromAddress(const char *remoteAddress)
65 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "CAEDRGetDeviceInfoFromAddress");
69 OIC_LOG(ERROR, EDR_ADAPTER_TAG, "remoteAddress is null");
73 uint32_t length = u_arraylist_length(g_deviceStateList);
74 for (uint32_t index = 0; index < length; index++)
76 CAConnectedDeviceInfo_t* deviceInfo =
77 (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
80 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "deviceInfo object is null");
84 if (!strcmp((const char*) deviceInfo->address, remoteAddress))
92 CAResult_t CAEDRAddDeviceInfoToList(const char *remoteAddress, CAConnectedDeviceInfo_t *deviceInfo)
96 OIC_LOG(ERROR, EDR_ADAPTER_TAG, "remoteAddress is null");
97 return CA_STATUS_INVALID_PARAM;
102 OIC_LOG(ERROR, EDR_ADAPTER_TAG, "deviceInfo is null");
103 return CA_STATUS_INVALID_PARAM;
106 for (int i = 0; i < CA_MACADDR_SIZE; i++)
108 deviceInfo->address[i] = (uint8_t) remoteAddress[i];
111 if (!g_deviceStateList)
113 g_deviceStateList = u_arraylist_create();
114 if (!g_deviceStateList)
116 OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create Device list");
117 return CA_STATUS_FAILED;
121 if (!u_arraylist_add(g_deviceStateList, (void *) deviceInfo))
123 OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Add Device to list");
124 return CA_STATUS_FAILED;