"the reply timeout expired, or the network connection " \
"was broken."
+#define BATTERY_MONITOR_RFCOMM_INTERVAL 5
+
static GSList *rfcomm_clients;
typedef struct {
unsigned int idle_id;
} rfcomm_cb_data_t;
+static unsigned int rx_data = 0, tx_data = 0;
+static guint tx_tag = 0, rx_tag = 0;
+
static void __client_connected_cb(rfcomm_cb_data_t *cb_data,
char *dev_address, int result);
+static bool __rfcomm_record_tx_data(void)
+{
+ if (tx_data > 0) {
+ int ret = _bt_common_send_rfcomm_tx_details(tx_data);
+ if (ret == BLUETOOTH_ERROR_NONE) {
+ tx_data = 0;
+ return TRUE;
+ } else {
+ BT_ERR("RFCOMM tx data could not be registered");
+ }
+ }
+
+ tx_data = 0;
+ tx_tag = 0;
+
+ return FALSE;
+}
+
+static bool __rfcomm_record_rx_data(void)
+{
+ if (rx_data) {
+ int ret = _bt_common_send_rfcomm_rx_details(rx_data);
+ if (ret == BLUETOOTH_ERROR_NONE) {
+ rx_data = 0;
+ return TRUE;
+ } else {
+ BT_ERR("RFCOMM rx data could not be registered");
+ }
+ }
+
+ rx_data = 0;
+ rx_tag = 0;
+
+ return FALSE;
+}
+
static void __bt_free_cb_data(rfcomm_cb_data_t *cb_data)
{
BT_DBG("+");
GIOStatus status = G_IO_STATUS_NORMAL;
GError *err = NULL;
int fd;
- BT_DBG("");
retv_if(info == NULL, FALSE);
fd = g_io_channel_unix_get_fd(chan);
BT_ERR("IO Channel read is failed with %d", status);
g_free(buffer);
- if (err) {
- BT_ERR("IO Channel read error [%s]", err->message);
- if (status == G_IO_STATUS_ERROR &&
- __is_error_by_disconnect(err)) {
+ if (err || status == G_IO_STATUS_EOF) {
+ if (err)
+ BT_ERR("IO Channel read error [%s]", err->message);
+ if ((status == G_IO_STATUS_EOF) ||
+ (status == G_IO_STATUS_ERROR &&
+ __is_error_by_disconnect(err))) {
+
BT_ERR("cond : %d", cond);
- g_error_free(err);
+ if (err)
+ g_error_free(err);
conn_info = __get_conn_info_from_fd(info, fd);
if (conn_info == NULL) {
__rfcomm_client_disconnect(info);
return FALSE;
}
- g_error_free(err);
+ if (err)
+ g_error_free(err);
}
return TRUE;
}
result, &data_r,
event_info->cb, event_info->user_data);
+ if (bluetooth_get_battery_monitor_state()) {
+ if (rx_tag == 0) {
+ BT_INFO("Adding rfcomm rx timeout function for battery monitor");
+ rx_tag = g_timeout_add_seconds(BATTERY_MONITOR_RFCOMM_INTERVAL, (GSourceFunc)__rfcomm_record_rx_data, NULL);
+ }
+ rx_data += len;
+ }
+
g_free(buffer);
return TRUE;
}
return;
}
+void _bt_rfcomm_client_reset_timer(void)
+{
+ if (rx_tag > 0) {
+ rx_tag = 0;
+ g_source_remove(rx_tag);
+ }
+
+ if (tx_tag > 0) {
+ g_source_remove(tx_tag);
+ tx_tag = 0;
+ }
+
+ rx_data = 0;
+ tx_data = 0;
+}
+
int new_connection(const char *path, int fd, bluetooth_device_address_t *addr)
{
rfcomm_cb_data_t *info;
int id, object_id;
char *path;
- if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_CLIENT_CONNECT)
+ if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CLIENT_CONNECT)
== BLUETOOTH_ERROR_PERMISSION_DEINED) {
BT_ERR("Don't have a privilege to use this API");
return BLUETOOTH_ERROR_PERMISSION_DEINED;
/* In now, we only support to connecty using UUID */
connect_type = BT_RFCOMM_UUID;
- if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_CLIENT_CONNECT)
+ if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CLIENT_CONNECT)
== BLUETOOTH_ERROR_PERMISSION_DEINED) {
BT_ERR("Don't have a privilege to use this API");
return BLUETOOTH_ERROR_PERMISSION_DEINED;
BT_CHECK_ENABLED(return);
- if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_SOCKET_DISCONNECT)
+ if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_SOCKET_DISCONNECT)
== BLUETOOTH_ERROR_PERMISSION_DEINED) {
BT_ERR("Don't have a privilege to use this API");
return BLUETOOTH_ERROR_PERMISSION_DEINED;
BT_CHECK_ENABLED(return);
retv_if(socket_fd < 0, BLUETOOTH_ERROR_INVALID_PARAM);
- if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_SOCKET_DISCONNECT)
+ if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_SOCKET_DISCONNECT)
== BLUETOOTH_ERROR_PERMISSION_DEINED) {
BT_ERR("Don't have a privilege to use this API");
return BLUETOOTH_ERROR_PERMISSION_DEINED;
#else
static int __write_all(int fd, const char *buf, int len)
{
- int sent = 0;
+ int sent = 0, try = 0;
BT_DBG("+");
while (len > 0) {
written = write(fd, buf, len);
BT_DBG("written: %d", written);
if (written < 0) {
- if (errno == EINTR || errno == EAGAIN)
- continue;
+ if (errno == EINTR || errno == EAGAIN) {
+ try++;
+ if (try <= 49)
+ continue;
+ }
return -1;
}
len -= written;
buf += written;
sent += written;
+ try = 0;
}
BT_DBG("-");
return BLUETOOTH_ERROR_INVALID_PARAM;
}
- BT_DBG("FD : %d", fd);
-
retv_if(length <= 0, BLUETOOTH_ERROR_INVALID_PARAM);
switch (privilege_token) {
case 0:
- result = _bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_SOCKET_WRITE);
+ result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_SOCKET_WRITE);
if (result == BLUETOOTH_ERROR_NONE) {
privilege_token = 1; /* Have a permission */
written = write(fd, buf, length);
/*BT_DBG("Length %d, written = %d, balance(%d)",
length, written, length - written); */
+ if (written > 0 && bluetooth_get_battery_monitor_state()) {
+ if (tx_tag == 0) {
+ BT_INFO("Adding rfcomm tx timeout function for battery monitor");
+ tx_tag = g_timeout_add_seconds(BATTERY_MONITOR_RFCOMM_INTERVAL, (GSourceFunc)__rfcomm_record_tx_data, NULL);
+ }
+ tx_data += length;
+ }
return written;
#else
result = __write_all(fd, buf, length);
+ if (result > 0 && bluetooth_get_battery_monitor_state()) {
+ if (tx_tag == 0) {
+ BT_INFO("Adding rfcomm tx timeout function for battery monitor");
+ tx_tag = g_timeout_add_seconds(BATTERY_MONITOR_RFCOMM_INTERVAL, (GSourceFunc)__rfcomm_record_tx_data, NULL);
+ }
+ tx_data += length;
+ }
return result;
#endif
}