summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaejin Woo <tt.woo@samsung.com>2013-10-23 17:21:15 +0900
committerTaejin Woo <tt.woo@samsung.com>2013-10-23 17:21:15 +0900
commit039bf095a7af6fa2cf32e2eb594d1e0eea5482ff (patch)
tree5ba030487a4fd92fca7a28dc057a85f11f094345
parentb22c0099d5f0e1328c548b2502f2fed83c8286c2 (diff)
downloadbluetooth-tizen_2.2.tar.gz
bluetooth-tizen_2.2.tar.bz2
bluetooth-tizen_2.2.zip
To implement GATT SDK API, we should provide some requirements such like connect_le, set_characteristic_request. Change-Id: I86ad5cdb1d2d8fd36f54f6779bb4473dccfba673
-rw-r--r--include/bluetooth.h34
-rw-r--r--src/bluetooth-common.c24
-rw-r--r--src/bluetooth-device.c40
-rw-r--r--src/bluetooth-gatt.c45
-rw-r--r--test/bt_unit_test.c88
5 files changed, 229 insertions, 2 deletions
diff --git a/include/bluetooth.h b/include/bluetooth.h
index 23b0871..b72e291 100644
--- a/include/bluetooth.h
+++ b/include/bluetooth.h
@@ -457,6 +457,7 @@ typedef struct
bool is_bonded; /**< The bonding state */
char **service_uuid; /**< The UUID list of service */
int service_count; /**< The number of services */
+ unsigned char device_type; /**< The Device Type of Remote Device */
} bt_adapter_device_discovery_info_s;
/**
@@ -1804,6 +1805,14 @@ int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed
*/
int bt_device_unset_connection_state_changed_cb(void);
+typedef void (*bt_device_gatt_state_changed_cb)(int result, void *user_data);
+
+int bt_device_connect_le(bt_device_gatt_state_changed_cb callback, const char *address);
+
+int bt_device_disconnect_le(bt_device_gatt_state_changed_cb callback, const char *address);
+
+int bt_device_read_rssi_value(const char *address);
+
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE
* @brief Registers a rfcomm socket with a specific UUID.
@@ -2470,6 +2479,20 @@ int bt_nap_disconnect_all(void);
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE
+ * @brief Disconnects the specified PANU(Personal Area Networking User) which is connected to you.
+ * @param[in] remote_address The remote address
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #BT_ERROR_NOT_ENABLED Not enabled
+ * @retval #BT_ERROR_OPERATION_FAILED Operation failed
+ * @pre The Bluetooth NAP service must be activated with bt_nap_activate().
+ * @see bt_nap_activate()
+ */
+int bt_nap_disconnect(const char *remote_address);
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE
* @brief Registers a callback function that will be invoked when the connection state changes.
* @param[in] callback The callback function to register
* @param[in] user_data The user data to be passed to the callback function
@@ -3898,6 +3921,7 @@ int bt_gatt_unset_characteristic_changed_cb(bt_gatt_attribute_h service);
*/
int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, char **uuid, unsigned char **value, int *value_length);
+typedef void (*bt_gatt_characteristic_write_cb) (bt_gatt_attribute_h handle);
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Sets the value of characteristic.
@@ -3915,6 +3939,11 @@ int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, c
*/
int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic, const unsigned char *value, int value_length);
+
+int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, const unsigned char *value,
+ int value_length, unsigned char request, bt_gatt_characteristic_write_cb callback);
+
+
/**
* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE
* @brief Clones the attribute handle.
@@ -3940,6 +3969,11 @@ int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h* clone, bt_gatt_attribute
*/
int bt_gatt_destroy_attribute_handle(bt_gatt_attribute_h handle);
+typedef void (*bt_gatt_characteristic_read_cb) (bt_gatt_attribute_h handle,
+ unsigned char *value, int value_length, void *user_data);
+int bt_gatt_read_characteristic_value(bt_gatt_attribute_h char_handle,
+ bt_gatt_characteristic_read_cb callback);
+
/**
* @}
*/
diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c
index 7d01ba3..2126981 100644
--- a/src/bluetooth-common.c
+++ b/src/bluetooth-common.c
@@ -469,6 +469,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
int i;
int call_id;
int *avrcp_mode;
+ int *le_conn_state;
+ short *rssi_value;
bluetooth_rfcomm_connection_t *connection_ind = NULL;
bluetooth_rfcomm_disconnection_t *disconnection_ind = NULL;
bt_socket_connection_s rfcomm_connection;
@@ -1039,6 +1041,27 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
if (device_addr != NULL)
free(device_addr);
break;
+ case BLUETOOTH_EVENT_GATT_CONNECTED:
+ BT_INFO("BLUETOOTH_EVENT_GATT_CONNECTED");
+ le_conn_state = (int *)(param->param_data);
+
+ ((bt_device_gatt_state_changed_cb)bt_event_slot_container[event_index].callback)
+ (*le_conn_state, bt_event_slot_container[event_index].user_data);
+ break;
+ case BLUETOOTH_EVENT_GATT_DISCONNECTED:
+ BT_INFO("BLUETOOTH_EVENT_GATT_DISCONNECTED");
+ le_conn_state = (int *)(param->param_data);
+
+ ((bt_device_gatt_state_changed_cb)bt_event_slot_container[event_index].callback)
+ (*le_conn_state, bt_event_slot_container[event_index].user_data);
+ break;
+ case BLUETOOTH_EVENT_GATT_RSSI:
+ BT_INFO("BLUETOOTH_EVENT_GATT_RSSI");
+ rssi_value = (short *)(param->param_data);
+
+ ((bt_device_gatt_state_changed_cb)bt_event_slot_container[event_index].callback)
+ (*rssi_value, bt_event_slot_container[event_index].user_data);
+ break;
case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
BT_INFO("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
svc_char = (bt_gatt_discovered_char_t *)(param->param_data);
@@ -1117,6 +1140,7 @@ static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discove
(*discovery_info)->rssi = (int)source_info->rssi;
(*discovery_info)->is_bonded = (bool)source_info->paired;
+ (*discovery_info)->device_type = (unsigned char)source_info->device_type;
return BT_ERROR_NONE;
}
diff --git a/src/bluetooth-device.c b/src/bluetooth-device.c
index 2fc478d..3c17967 100644
--- a/src/bluetooth-device.c
+++ b/src/bluetooth-device.c
@@ -278,6 +278,46 @@ int bt_device_unset_connection_state_changed_cb(void)
return BT_ERROR_NONE;
}
+int bt_device_connect_le(bt_device_gatt_state_changed_cb callback, const char *address)
+{
+ int ret;
+ bluetooth_device_address_t bd_addr = { {0,} };
+
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(address);
+
+ _bt_set_cb(BT_EVENT_GATT_CONNECTION_STATUS, callback, NULL);
+
+ _bt_convert_address_to_hex(&bd_addr, address);
+
+ ret = _bt_get_error_code(bluetooth_connect_le(&bd_addr));
+
+ if (ret != BT_ERROR_NONE) {
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+ }
+ return ret;
+}
+
+int bt_device_disconnect_le(bt_device_gatt_state_changed_cb callback, const char *address)
+{
+ int ret;
+ bluetooth_device_address_t bd_addr = { {0,} };
+
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(address);
+
+ _bt_convert_address_to_hex(&bd_addr, address);
+
+ _bt_set_cb(BT_EVENT_GATT_CONNECTION_STATUS, callback, NULL);
+
+ ret = _bt_get_error_code(bluetooth_disconnect_le(&bd_addr));
+
+ if (ret != BT_ERROR_NONE) {
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+ }
+ return ret;
+}
+
int bt_device_read_rssi_value(const char *address)
{
int ret;
diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c
index 19315c4..0e50c30 100644
--- a/src/bluetooth-gatt.c
+++ b/src/bluetooth-gatt.c
@@ -259,6 +259,31 @@ int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic,
return ret;
}
+int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic,
+ const unsigned char *value, int value_length,
+ unsigned char request, bt_gatt_characteristic_write_cb callback)
+{
+ int ret;
+
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(characteristic);
+ BT_CHECK_INPUT_PARAMETER(value);
+
+ if (value_length <= 0)
+ return BT_ERROR_INVALID_PARAMETER;
+
+ ret = _bt_get_error_code(bluetooth_gatt_set_characteristics_value((const char *)characteristic,
+ (const guint8 *)value, value_length, request));
+
+ if (ret != BT_ERROR_NONE) {
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+ } else {
+ _bt_set_cb(BT_EVENT_GATT_WRITE_CHARACTERISTIC, callback, characteristic);
+ }
+
+ return ret;
+}
+
int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h *clone,
bt_gatt_attribute_h origin)
{
@@ -283,3 +308,23 @@ int bt_gatt_destroy_attribute_handle(bt_gatt_attribute_h handle)
return error;
}
+
+int bt_gatt_read_characteristic_value(bt_gatt_attribute_h characteristic,
+ bt_gatt_characteristic_read_cb callback)
+{
+ int ret;
+
+ BT_CHECK_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(characteristic);
+ BT_CHECK_INPUT_PARAMETER(callback);
+
+ ret = _bt_get_error_code(bluetooth_gatt_read_characteristic_value((const char *)characteristic));
+
+ if (ret != BT_ERROR_NONE) {
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+ } else {
+ _bt_set_cb(BT_EVENT_GATT_READ_CHARACTERISTIC, callback, NULL);
+ }
+
+ return ret;
+}
diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c
index aab0584..6976008 100644
--- a/test/bt_unit_test.c
+++ b/test/bt_unit_test.c
@@ -136,6 +136,7 @@ tc_table_t tc_table[] = {
{"bt_nap_activate" , 110},
{"bt_nap_deactivate" , 111},
{"bt_nap_disconnect_all" , 112},
+ {"bt_nap_disconnect" , 113},
/* Device functions */
{"bt_device_set_authorization (true)" , 120},
@@ -147,7 +148,10 @@ tc_table_t tc_table[] = {
{"bt_device_foreach_connected_profiles" , 126},
{"bt_device_set_bond_created_cb" , 127},
{"bt_device_create_bond" , 128},
- {"bt_device_is_connected_profiles", 129},
+ {"bt_device_connect_le" , 129},
+ {"bt_device_disconnect_le" , 130},
+ {"bt_device_read_rssi_value" , 131},
+ {"bt_device_is_connected_profiles", 132},
/* Gatt functions */
{"bt_gatt_foreach_primary_services" , 140},
@@ -158,6 +162,7 @@ tc_table_t tc_table[] = {
{"bt_gatt_unset_characteristic_changed_cb" , 145},
{"bt_gatt_get_characteristic_declaration" , 146},
{"bt_gatt_set_characteristic_value" , 147},
+ {"bt_gatt_read_characteristic_value" , 148},
/* AVRCP functions */
{"bt_avrcp_target_initialize" , 160},
@@ -256,6 +261,7 @@ static void __bt_adapter_device_discovery_state_changed_cb(int result,
TC_PRT("rssi: %d", discovery_info->rssi);
TC_PRT("is_bonded: %d", discovery_info->is_bonded);
TC_PRT("service_count: %d", discovery_info->service_count);
+ TC_PRT("device type: %u", discovery_info->device_type);
if (discovery_info->service_uuid == NULL) {
TC_PRT("No uuids");
@@ -373,6 +379,11 @@ bool __bt_device_connected_profile(bt_profile_e profile, void *user_data)
return true;
}
+void __bt_device_le_connection_status_cb(int result, void *user_data)
+{
+ TC_PRT("Callback: LE Conneciton Status %d", result);
+}
+
void __bt_device_bond_created_cb(int result, bt_device_info_s *device_info, void *user_data)
{
if(result == BT_ERROR_NONE)
@@ -454,6 +465,27 @@ void __bt_gatt_characteristic_changed_cb(bt_gatt_attribute_h characteristic, uns
return;
}
+void __bt_gatt_char_write_cb(bt_gatt_attribute_h handle)
+{
+ TC_PRT("__bt_gatt_char_write_cb");
+ return;
+}
+
+void __bt_gatt_char_read_cb(bt_gatt_attribute_h handle, unsigned char *value, int value_length, void *user_data)
+{
+ int i;
+
+ TC_PRT("__bt_gatt_char_read_cb");
+
+ TC_PRT("value_length %d", value_length);
+
+ for (i = 0; i < value_length; i++) {
+ TC_PRT("value %c", value[i]);
+ }
+
+ return;
+}
+
void __bt_avrcp_target_connection_state_changed_cb(bool connected, const char *remote_address, void *user_data)
{
TC_PRT("__bt_avrcp_target_connection_state_changed_cb");
@@ -1014,6 +1046,18 @@ int test_input_callback(void *data)
}
break;
+ case 113: {
+ char *address;
+
+ address = g_strdup("00:1B:66:01:23:1C");
+
+ ret = bt_nap_disconnect(address);
+ if (ret < BT_ERROR_NONE) {
+ TC_PRT("failed with [0x%04x]", ret);
+ }
+ break;
+ }
+
case 120: {
char *address;
@@ -1099,6 +1143,37 @@ int test_input_callback(void *data)
case 129 : {
char *address;
+
+ address = g_strdup(DEVICE_ADDRESS);
+ ret = bt_device_connect_le(__bt_device_le_connection_status_cb, address);
+ if (ret < BT_ERROR_NONE) {
+ TC_PRT("failed with [0x%04x]", ret);
+ }
+ break;
+ }
+
+ case 130 : {
+ char *address;
+
+ address = g_strdup(DEVICE_ADDRESS);
+
+ ret = bt_device_disconnect_le(__bt_device_le_connection_status_cb,address);
+ if (ret < BT_ERROR_NONE) {
+ TC_PRT("failed with [0x%04x]", ret);
+ }
+ break;
+ }
+ case 131 : {
+ char *address;
+ address = g_strdup(DEVICE_ADDRESS);
+ ret = bt_device_read_rssi_value(address);
+ if (ret < BT_ERROR_NONE)
+ TC_PRT("failed with [0x%04x]", ret);
+ break;
+ }
+
+ case 132 : {
+ char *address;
int i = 0;
bool is_connected_state = false;
address = g_strdup("D8:57:EF:C1:F4:ED");
@@ -1209,7 +1284,16 @@ int test_input_callback(void *data)
case 147: {
unsigned char value[5] = { 0, 1, 2, 3, 4 };
- ret = bt_gatt_set_characteristic_value(characteristics_services[0], value, 5);
+ ret = bt_gatt_set_characteristic_value_request(characteristics_services[0], value, 5, 1,
+ __bt_gatt_char_write_cb);
+ if (ret < BT_ERROR_NONE) {
+ TC_PRT("failed with [0x%04x]", ret);
+ }
+ break;
+ }
+
+ case 148 : {
+ ret = bt_gatt_read_characteristic_value(characteristics_services[0], __bt_gatt_char_read_cb);
if (ret < BT_ERROR_NONE) {
TC_PRT("failed with [0x%04x]", ret);
}