Add new L2CAP socket API to get the maximum buffer size 41/306741/2
authorWootak Jung <wootak.jung@samsung.com>
Tue, 27 Feb 2024 04:41:27 +0000 (13:41 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 27 Feb 2024 05:01:42 +0000 (14:01 +0900)
Change-Id: I07346e76772c3d8379f2eb713bb55996fa1d3bba
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
include/bluetooth_internal.h
src/bluetooth-socket.c
tests/test/bt_unit_test.c
tests/test/bt_unit_test.h

index c04e89e366d3fa42378db4a213202aa980a712f1..fe15bf092f0abed854d5e4c0eb98172e73d160fc 100644 (file)
@@ -5836,6 +5836,22 @@ int bt_gatt_server_set_service_persistence(const char *uuid);
  */
 int bt_gatt_server_unset_service_persistence(const char *uuid);
 
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_L2CAP_SOCKET_MODULE
+ * @brief Gets the maximum buffer size.
+ *
+ * @param[out] size The maximum size of buffer
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_NOT_SUPPORTED Not supported
+ * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BT_ERROR_NOT_INITIALIZED Not initialized
+ *
+ * @see bt_socket_send_data_l2cap_channel()
+ */
+int bt_socket_get_l2cap_max_buffer_size(int *size);
+
 /**
  * @}
  */
index 3f7bb4672964fa8f78c47b5e829ce6f161bb848f..02050d9ea867b04ac590dbe9556f043c836ef24a 100644 (file)
@@ -509,6 +509,21 @@ int bt_socket_get_l2cap_psm(int socket_fd, int *psm)
        return ret; /* LCOV_EXCL_STOP */
 }
 
+int bt_socket_get_l2cap_max_buffer_size(int *size)
+{
+       int error_code = BT_ERROR_NONE;
+
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_LE_COC);
+       BT_CHECK_INIT_STATUS(); /* LCOV_EXCL_START */
+       BT_CHECK_INPUT_PARAMETER(size);
+
+       error_code = bluetooth_l2cap_le_get_max_buffer_size(size);
+       if (error_code != BT_ERROR_NONE)
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
+
+       return error_code; /* LCOV_EXCL_STOP */
+}
+
 int bt_socket_set_l2cap_channel_connection_state_changed_cb(
                                                bt_socket_l2cap_channel_connection_state_changed_cb callback, void *user_data)
 {
index d34176f8a97451aa84a2aa948e5d798380c5b5a4..2b178e8af05eaf656620a5d9648fb92879187485 100644 (file)
@@ -523,6 +523,8 @@ tc_table_t tc_socket[] = {
                , BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA_L2CAP_CHANNEL},
        {"bt_socket_get_l2cap_psm"
                , BT_UNIT_TEST_FUNCTION_SOCKET_GET_L2CAP_PSM},
+       {"bt_socket_get_l2cap_max_buffer_size"
+               , BT_UNIT_TEST_FUNCTION_SOCKET_GET_L2CAP_MAX_BUFFER_SIZE},
        {"bt_socket_set_l2cap_channel_connection_requested_cb"
                , BT_UNIT_TEST_FUNCTION_SOCKET_SET_L2CAP_CHANNEL_CONNECTION_REQUESTED_CB},
        {"bt_socket_unset_l2cap_channel_connection_requested_cb"
@@ -6698,6 +6700,15 @@ int test_input_callback(void *data)
                        }
                        break;
                }
+               case BT_UNIT_TEST_FUNCTION_SOCKET_GET_L2CAP_MAX_BUFFER_SIZE: {
+                       int size;
+                       ret = bt_socket_get_l2cap_max_buffer_size(&size);
+                       if (ret != BT_ERROR_NONE)
+                               TC_PRT("returns %s\n", __bt_get_error_message(ret));
+                       else
+                               TC_PRT("max buffer size: %d(0x%x)", size, size);
+                       break;
+               }
                case BT_UNIT_TEST_FUNCTION_SOCKET_SET_L2CAP_CHANNEL_CONNECTION_REQUESTED_CB:
                        ret = bt_socket_set_l2cap_channel_connection_requested_cb(
                                __bt_socket_connection_requested_cb, NULL);
index e046e87b65e6bab14cddb49a29ffb642703b0f7c..d5a1dbaad5603b430315b190aed43e774dccd37c 100644 (file)
@@ -220,6 +220,7 @@ typedef enum {
        BT_UNIT_TEST_FUNCTION_SOCKET_DISCONNECT_L2CAP_CHANNEL,
        BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA_L2CAP_CHANNEL,
        BT_UNIT_TEST_FUNCTION_SOCKET_GET_L2CAP_PSM,
+       BT_UNIT_TEST_FUNCTION_SOCKET_GET_L2CAP_MAX_BUFFER_SIZE,
        BT_UNIT_TEST_FUNCTION_SOCKET_SET_L2CAP_CHANNEL_CONNECTION_REQUESTED_CB,
        BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_L2CAP_CHANNEL_CONNECTION_REQUESTED_CB,
        BT_UNIT_TEST_FUNCTION_SOCKET_SET_L2CAP_CHANNEL_CONNECTION_STATE_CHANGED_CB,