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 the APIs to start and stop RFCOMM server.
28 #include <bluetooth.h>
30 #include "caedrinterface.h"
31 #include "caadapterutils.h"
32 #include "caedrutils.h"
36 #include "caedrdevicelist.h"
38 static int32_t g_maxPendingConnections = 10;
41 * Storing RfcommserverUUID
43 static int g_serverFD = -1;
45 CAResult_t CAEDRServerStart()
47 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
49 bool isRunning = false;
50 bt_error_e err = bt_adapter_is_service_used(OIC_EDR_SERVICE_ID, &isRunning);
51 if (BT_ERROR_NONE != err)
53 OIC_LOG_V(ERROR, EDR_ADAPTER_TAG,
54 "Unable to find whether service is already running or not! error num[%x]", err);
55 return CA_STATUS_FAILED;
60 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Service is already running with this UUID!");
61 return CA_SERVER_STARTED_ALREADY;
65 // Registers a rfcomm socket with a specific service_uuid.
66 err = bt_socket_create_rfcomm(OIC_EDR_SERVICE_ID, &socketFD);
67 if (BT_ERROR_NONE != err)
69 OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed to create rfcomm socket!, error num [%x]", err);
70 return CA_STATUS_FAILED;
73 // Start listening and accepting
74 err = bt_socket_listen_and_accept_rfcomm(socketFD, g_maxPendingConnections);
75 if (BT_ERROR_NONE != err)
77 OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed in listen rfcomm socket!, error num [%x]", err);
79 bt_socket_destroy_rfcomm(socketFD);
80 return CA_STATUS_FAILED;
83 g_serverFD = socketFD;
85 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
89 CAResult_t CAEDRServerStop()
91 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
95 bt_error_e err = bt_socket_destroy_rfcomm(g_serverFD);
97 if (BT_ERROR_NONE != err)
99 OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed close server socket!, error num [%x]", err);
100 return CA_STATUS_FAILED;
105 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
109 CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle)
111 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "CAEDRServerInitialize");
115 void CAEDRServerTerminate()
117 // This is just a dummy
118 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "CAEDRServerTerminate");
121 CAResult_t CAEDRManagerReadData(void)
123 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
124 OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
125 return CA_NOT_SUPPORTED;