[Adapt: OAL]Implement socket_listen API 37/87737/1
authorAtul Rai <a.rai@samsung.com>
Wed, 31 Aug 2016 04:47:49 +0000 (10:17 +0530)
committerAtul Rai <a.rai@samsung.com>
Wed, 31 Aug 2016 04:47:49 +0000 (10:17 +0530)
This patch adds implementation for socket listen API is BT-OAL.

Change-Id: Ibed94ea3a61249fc06891156bd93fc7d0c4f416b
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-oal/include/oal-socket.h
bt-oal/oal-socket.c

index 448ff6b..3cb313a 100755 (executable)
@@ -86,6 +86,23 @@ oal_status_t socket_disable(void);
  */
 int socket_connect(oal_sock_type_t sock_type, oal_uuid_t* p_uuid, int channel, bt_address_t* bd);
 
+/**
+ * @fn int socket_listen(oal_sock_type_t sock_type, oal_uuid_t *p_uuid, char *svc_name, int channel);
+ * @brief Creates server socket and start listen for incomming connection.
+ *
+ * This API creates Server socket. It takes UUID and service name.
+ * It returns the server FD on success. There can be multiple SERVERs, with each server having its
+ * unique FD. This function is a synchronous call.
+ *
+ * @param[in]   sock_type  Bluetooth socket type to be connected
+ * @param[in]   p_uuid     UUID of the RFCOMM SERVER to be created
+ * @param[in]   channel    channel
+ * @param[in]   svc_name   Name for the server
+ * @return      Server Socket FD - Success
+ * @remark      None
+ */
+int socket_listen(oal_sock_type_t sock_type, oal_uuid_t *p_uuid, char *svc_name, int channel);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 59eb4bd..1410f38 100755 (executable)
@@ -384,6 +384,48 @@ int socket_connect(oal_sock_type_t sock_type, oal_uuid_t *p_uuid, int channel, b
        return sock_fd;
 }
 
+int socket_listen(oal_sock_type_t sock_type, oal_uuid_t *p_uuid, char *svc_name, int channel)
+{
+       int sock_fd = -1;
+       int srv_channel;
+       int ret = BT_STATUS_FAIL;
+
+       CHECK_OAL_SOCKET_ENABLED();
+       OAL_CHECK_PARAMETER(svc_name, return);
+       API_TRACE("svc_name: %s", svc_name);
+
+       switch (sock_type) {
+       case OAL_SOCK_RFCOMM:
+               if(channel < 0 )
+                       ret = socket_api->listen(BTSOCK_RFCOMM,
+                                       svc_name, p_uuid->uuid, 0, &sock_fd, 0);
+               else
+                       ret = socket_api->listen(BTSOCK_RFCOMM,
+                                       svc_name, p_uuid->uuid, channel, &sock_fd, 0);
+               break;
+       default:
+               BT_ERR("Socket type: %d not supported");
+       }
+
+       if(sock_fd < 0 || ret != BT_STATUS_SUCCESS) {
+               BT_ERR("Bluetooth socket creation failed");
+               return sock_fd;
+       }
+
+       BT_INFO("Bluetooth server socket created, sock_fd=%d", sock_fd);
+
+       /* Read server channel number sent by stack */
+       srv_channel = sock_wait_for_channel(sock_fd);
+       if(srv_channel < 0) {
+               BT_ERR("incorrect channel= %d", srv_channel);
+               return  -1;
+       }
+
+       BT_INFO("server channel= %d", srv_channel);
+
+       return sock_fd;
+}
+
 oal_status_t socket_enable()
 {
        const bt_interface_t *blued_api;