PROJECT(bt-service C)
#Include Source files for bluetooth service common files only
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
-SET(SRCS
-marshal.c
-./services/bt-service-main.c
-./services/bt-service-common.c
-./services/bt-service-event-sender.c
-./services/bt-service-util.c
-./services/bt-request-handler.c
-./services/adapter/bt-service-core-adapter.c
-./services/adapter/bt-service-core-adapter-le.c
-./services/device/bt-service-core-device.c
-./services/bt-service-event-receiver.c
-./services/bt-service-dpm.c
-./services/bt-service-agent-util.c
-./services/hid/bt-service-hidhost.c
-./services/socket/bt-service-socket.c
-./services/rfcomm/bt-service-rfcomm.c
-./services/audio/bt-service-audio.c
-./services/audio/hf/bt-service-hf.c
-./services/audio/a2dp_src/bt-service-a2dp-src.c
-./services/audio/a2dp_sink/bt-service-a2dp-sink.c
-./services/health/bt-service-hdp.c
-./services/audio/avrcp/bt-service-avrcp-tg.c
-./services/audio/avrcp/bt-service-avrcp-ctrl.c
-./services/gatt/bt-service-gatt.c
-./services/obex/bt-service-obex-agent.c
-./services/obex/bt-service-obex-server.c
-./services/obex/bt-service-map-client.c
-./services/obex/bt-service-opp-client.c
-./services/obex/bt-service-pbap.c
-./services/obex/bt-service-gap-agent.c
-./services/obex/bt-service-network.c
-./services/obex/bt-service-avrcp.c
-./services/obex/bt-service-agent.c
-./services/obex/bt-service-obex-event-receiver.c
-./services/obex/bt-service-oob.c
-)
-ELSE ()
SET(SRCS
marshal.c
./services/bt-service-main.c
./services/audio/avrcp/bt-service-avrcp-ctrl.c
./services/gatt/bt-service-gatt.c
)
+
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
+LIST(APPEND SRCS ./services/obex/bt-service-obex-agent.c)
+LIST(APPEND SRCS ./services/obex/bt-service-obex-server.c)
+LIST(APPEND SRCS ./services/obex/bt-service-map-client.c)
+LIST(APPEND SRCS ./services/obex/bt-service-opp-client.c)
+LIST(APPEND SRCS ./services/obex/bt-service-pbap.c)
+LIST(APPEND SRCS ./services/obex/bt-service-gap-agent.c)
+LIST(APPEND SRCS ./services/obex/bt-service-avrcp.c)
+LIST(APPEND SRCS ./services/obex/bt-service-agent.c)
+LIST(APPEND SRCS ./services/obex/bt-service-obex-event-receiver.c)
+LIST(APPEND SRCS ./services/obex/bt-service-oob.c)
+ENDIF()
+
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_PAN_NAP")
+LIST(APPEND SRCS ./services/pan_nap/bt-service-pan-nap-event-receiver.c)
+LIST(APPEND SRCS ./services/pan_nap/bt-service-network.c)
ENDIF()
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/obex/include)
ENDIF()
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_PAN_NAP")
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/pan_nap/include)
+ENDIF()
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal/include)
LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal)
#include <oal-manager.h>
#include <oal-adapter-mgr.h>
+#ifdef TIZEN_FEATURE_BT_PAN_NAP
+#include "bt-service-network.h"
+#endif
/*This file will contain state machines related to adapter and remote device */
/* Global variables */
_bt_audio_start_auto_connect(FALSE);
#endif
+#ifndef TIZEN_TV
__bt_set_local_name();
+#endif
_bt_set_discovery_status(FALSE);
return BLUETOOTH_ERROR_NONE;
_bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_ENABLED,
g_variant_new("(i)", result));
+#ifndef TIZEN_TV
__bt_set_local_name();
+#endif
BT_DBG("-");
return BLUETOOTH_ERROR_NONE;
}
BT_DBG("status : %d", status);
BT_DBG("le_status : %d", le_status);
+#if !defined(TIZEN_FEATURE_BT_OBEX)&&!defined(TIZEN_FEATURE_BT_PAN_NAP)
#ifndef TIZEN_FEATURE_BT_USB_DONGLE
{
adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
}
#endif
+#endif
if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
BT_ERR("Fail to register media player");
+#ifdef TIZEN_FEATURE_BT_OBEX
if (_bt_register_obex_server() != BLUETOOTH_ERROR_NONE)
BT_ERR("Fail to init obex server");
+#endif
-#ifdef TIZEN_BT_PAN_NAP_ENABLED
+#ifdef TIZEN_FEATURE_BT_PAN_NAP
if (_bt_network_activate() != BLUETOOTH_ERROR_NONE)
BT_ERR("Fail to activate network");
#endif
#include "bt-service-oob.h"
#endif
+#ifdef TIZEN_FEATURE_BT_PAN_NAP
+#include "bt-service-network.h"
+#endif
/* For AVRCP target role */
static char *current_sender_playing = NULL;
__bt_service_get_parameters(in_param2,
&service_type, sizeof(int));
+#if defined(TIZEN_FEATURE_BT_PAN_NAP)
+ if ((service_type == BLUETOOTH_NAP_SERVICE)||(service_type == BLUETOOTH_NAP_SERVER_SERVICE)) {
+ connected =_bt_is_nap_panu_device_connected(&address, service_type);
+ }
+ else
+ {
+ connected = _bt_is_device_connected(&address, service_type);
+ }
+#else
connected = _bt_is_device_connected(&address, service_type);
+#endif
BT_DBG("is_connected: %d", connected);
g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
break;
result = _bt_set_scan_parameters(&scan_params);
break;
}
+#ifdef TIZEN_FEATURE_BT_PAN_NAP
+ case BT_NETWORK_ACTIVATE:
+ BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
+ result = _bt_network_activate();
+ break;
+ case BT_NETWORK_DEACTIVATE:
+ result = _bt_network_deactivate();
+ break;
+ case BT_NETWORK_CONNECT: {
+ bluetooth_device_address_t address = { {0} };
+ int role;
+
+ __bt_service_get_parameters(in_param1,
+ &address, sizeof(bluetooth_device_address_t));
+ __bt_service_get_parameters(in_param2,
+ &role, sizeof(int));
+
+ result = _bt_network_connect(request_id, role, &address);
+ if (result != BLUETOOTH_ERROR_NONE) {
+ g_array_append_vals(*out_param1, &address,
+ sizeof(bluetooth_device_address_t));
+ }
+ break;
+ }
+ case BT_NETWORK_DISCONNECT: {
+ bluetooth_device_address_t address = { {0} };
+
+ __bt_service_get_parameters(in_param1,
+ &address, sizeof(bluetooth_device_address_t));
+
+ result = _bt_network_disconnect(request_id, &address);
+ if (result != BLUETOOTH_ERROR_NONE) {
+ g_array_append_vals(*out_param1, &address,
+ sizeof(bluetooth_device_address_t));
+ }
+ break;
+ }
+ case BT_NETWORK_SERVER_DISCONNECT: {
+ bluetooth_device_address_t address = { {0} };
+
+ __bt_service_get_parameters(in_param1,
+ &address, sizeof(bluetooth_device_address_t));
+
+ result = _bt_network_server_disconnect(request_id, &address);
+ if (result != BLUETOOTH_ERROR_NONE) {
+ g_array_append_vals(*out_param1, &address,
+ sizeof(bluetooth_device_address_t));
+ }
+ break;
+ }
+
+#endif
default:
BT_INFO("UnSupported function [%d]", function_name);
result = BLUETOOTH_ERROR_NOT_SUPPORT;
#include "bt-internal-types.h"
#include "bt-service-common.h"
#include "bt-request-handler.h"
+#ifdef TIZEN_FEATURE_BT_OBEX
+#include "bt-service-obex-event.h"
+#endif
+#ifdef TIZEN_FEATURE_BT_PAN_NAP
+#include "bt-service-pan-nap-event.h"
+#endif
#include "bt-service-event.h"
#include "bt-service-util.h"
_bt_deinit_service_event_sender();
_bt_service_unregister();
_bt_service_cynara_deinit();
+#ifdef TIZEN_FEATURE_BT_OBEX
+ _bt_deinit_obex_event_receiver();
+#endif
+#ifdef TIZEN_FEATURE_BT_PAN_NAP
+ _bt_deinit_pan_nap_event_receiver();
+#endif
_bt_cleanup_profiles();
oal_bt_deinit();
BT_ERR("Fail to init cynara");
return EXIT_FAILURE;
}
-#ifdef TIZEN_FEATURE_BT_OBEX
- /* Event reciever Init */
- if (_bt_init_service_event_receiver() != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to init event reciever");
- return 0;
- }
-#endif
/* Event sender Init */
if (_bt_init_service_event_sender() != BLUETOOTH_ERROR_NONE) {
BT_ERR("Fail to init event sender");
BT_ERR("Fail to init core event sender");
return 0;
}
+#ifdef TIZEN_FEATURE_BT_PAN_NAP
+ /* Event reciever Init */
+ if (_bt_init_pan_nap_event_receiver() != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Fail to init PAN NAP reciever");
+ return 0;
+ }
+#endif
+#ifdef TIZEN_FEATURE_BT_OBEX
+ /* Event reciever Init */
+ if (_bt_init_obex_event_receiver() != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Fail to init obex event reciever");
+ return 0;
+ }
+#endif
if (_bt_service_register() != BLUETOOTH_ERROR_NONE) {
BT_ERR("Fail to register service");
#include "bt-service-common.h"
#include "bt-service-util.h"
-#ifdef TIZEN_FEATURE_BT_OBEX
-static GSList *req_list = NULL;
+#if defined(TIZEN_FEATURE_BT_OBEX) ||defined(TIZEN_FEATURE_BT_PAN_NAP)
+static GSList *req_list = NULL;
/* available request id : 0 ~ 244 */
#define BT_REQUEST_ID_RANGE_MAX 245
+static gboolean req_id_used[BT_REQUEST_ID_RANGE_MAX];
+#endif
+
+#ifdef TIZEN_FEATURE_BT_OBEX
static int assigned_id;
-static gboolean req_id_used[BT_REQUEST_ID_RANGE_MAX];
+
bt_plugin_info_t *headed_plugin_info = NULL;
return assigned_id;
}
+#endif
+#if defined(TIZEN_FEATURE_BT_OBEX) ||defined(TIZEN_FEATURE_BT_PAN_NAP)
void _bt_delete_request_id(int request_id)
{
req_id_used[request_id] = FALSE;
}
+#endif
+#ifdef TIZEN_FEATURE_BT_OBEX
void _bt_init_request_list(void)
{
_bt_clear_request_list();
return BLUETOOTH_ERROR_NONE;
}
+#endif
+#if defined(TIZEN_FEATURE_BT_OBEX) ||defined(TIZEN_FEATURE_BT_PAN_NAP)
request_info_t *_bt_get_request_info(int req_id)
{
GSList *l;
return BLUETOOTH_ERROR_NOT_FOUND;
}
+#endif
+
+#if TIZEN_FEATURE_BT_OBEX
void _bt_clear_request_list(void)
{
if (req_list) {
void _bt_free_remote_dev(bt_remote_dev_info_t * dev_info);
-invocation_info_t* _bt_get_request_info_data(int service_function, char *address);
#ifdef TIZEN_FEATURE_BT_OBEX
void __bt_get_auth_info(GVariant *reply, char *auth_info);
#endif
int _bt_get_ad_data_by_type(char *in_data, int in_len,
char in_type, char **data, int *data_len);
+invocation_info_t* _bt_get_request_info_data(int service_function, char *address);
+
#ifdef TIZEN_FEATURE_BT_OBEX
struct bluetooth_headed_plugin_t {
int (*bt_launch_dpmpopup) (char *mode);
extern bt_plugin_info_t *headed_plugin_info;
+#endif
+#if defined(TIZEN_FEATURE_BT_OBEX)||defined(TIZEN_FEATURE_BT_PAN_NAP)
GDBusConnection *_bt_gdbus_get_system_gconn(void);
#endif
void *_bt_network_connected_profile(void *connection, unsigned char *address);
+gboolean _bt_is_nap_panu_device_connected(bluetooth_device_address_t *address, int service_type);
+
int _bt_is_network_connected(void *connection, unsigned char *address,
gboolean *is_connected);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb
};
-#ifdef TIZEN_FEATURE_BT_OBEX
+#if defined(TIZEN_FEATURE_BT_OBEX) ||defined(TIZEN_FEATURE_BT_PAN_NAP)
typedef struct {
int req_id;
int service_function;
GDBusMethodInvocation *context;
} request_info_t;
+request_info_t *_bt_get_request_info(int req_id);
+
+int _bt_delete_request_list(int req_id);
+
+#endif
+
+#ifdef TIZEN_FEATURE_BT_OBEX
void _bt_init_request_id(void);
int _bt_insert_request_list(int req_id, int service_function,
char *name, GDBusMethodInvocation *context);
-int _bt_delete_request_list(int req_id);
-
-request_info_t *_bt_get_request_info(int req_id);
void _bt_clear_request_list(void);
#include "bt-service-gap-agent.h"
#include "bt-service-core-adapter.h"
#include "bt-service-event.h"
-//#include "bt-service-rfcomm-server.h"
#include "bt-service-device.h"
#include "bt-service-audio.h"
goto done;
}
- if (!strcasecmp(uuid, NAP_UUID) ||
- !strcasecmp(uuid, GN_UUID) ||
- !strcasecmp(uuid, BNEP_UUID)) {
-
- BT_DBG("Network connection request: %s", uuid);
-#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
- {
- if (nap_connected_device_count >=
- BT_PAN_MAX_CONNECTION) {
- BT_ERR("Max connection exceeded");
- goto fail;
- }
- int ret;
- ret = tethering_create(&tethering);
-
- if (ret != TETHERING_ERROR_NONE) {
- BT_ERR("Fail to create tethering: %d", ret);
- goto fail;
- }
-
- enabled = tethering_is_enabled(tethering, TETHERING_TYPE_BT);
-
- ret = tethering_destroy(tethering);
-
- if (ret != TETHERING_ERROR_NONE)
- BT_ERR("Fail to create tethering: %d", ret);
-
- if (enabled != true) {
- BT_ERR("BT tethering is not enabled");
- goto fail;
- }
- }
-#endif
-
- gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
- NULL);
- goto done;
-#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
-fail:
- gap_agent_reply_authorize(agent, GAP_AGENT_REJECT,
- NULL);
-
- goto done;
-#endif
- }
-
reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
if (reply_temp == NULL) {
gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
static guint event_id;
static guint session_reinit_timer;
-guint nap_connected_device_count = 0;
typedef struct {
bt_remote_dev_info_t *dev_info;
void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
void _bt_opp_client_event_deinit(void);
void _bt_map_client_event_deinit(void);
-void _bt_handle_network_client_event(GVariant *msg_iter,
- const char *path);
void _bt_map_on_transfer_finished(const char *transfer_object_path, const int error);
static void __bt_free_cache_info(bt_cache_info_t *cache_info)
return BLUETOOTH_ERROR_NONE;
}
-void __bt_set_device_values(gboolean connected, int state)
-{
- int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
-
- if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
- BT_ERR("vconf_get_int failed");
-
- if (connected == TRUE)
- bt_device_state |= state;
- else if (bt_device_state & state)
- bt_device_state ^= state;
-
- if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
- BT_ERR("vconf_set_int failed");
-}
-
void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
{
BT_DBG("+");
g_variant_unref(value);
}
-void _bt_handle_network_server_event(GVariant *msg, const char *member)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char *address = NULL;
- char *device = NULL;
- GVariant *param = NULL;
- ret_if(member == NULL);
- if (strcasecmp(member, "PeerConnected") == 0) {
- g_variant_get(msg, "(ss)", &device, &address);
-
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- param = g_variant_new("(iss)", result, device, address);
- _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
- param);
- g_free(device);
- g_free(address);
- nap_connected_device_count++;
- } else if (strcasecmp(member, "PeerDisconnected") == 0) {
- g_variant_get(msg, "(ss)", &device, &address);
- nap_connected_device_count--;
- if (nap_connected_device_count == 0)
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- param = g_variant_new("(iss)", result, device, address);
- _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
- param);
- g_free(device);
- g_free(address);
- }
-}
-
-void _bt_handle_network_client_event(GVariant *msg,
- const char *path)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_NONE;
- gboolean property_flag = FALSE;
- char *property = NULL;
- GVariant *val = NULL;
- GVariantIter value_iter;
- GVariant *param = NULL;
- g_variant_iter_init(&value_iter, msg);
- while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
- if (strcasecmp(property, "Connected") == 0) {
- int event = BLUETOOTH_EVENT_NONE;
- char *address;
-
- g_variant_get(val, "b", &property_flag);
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("property_flag %d", property_flag);
- if (property_flag == TRUE) {
- event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
- nap_connected_device_count++;
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- } else {
- event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
- nap_connected_device_count--;
- if (nap_connected_device_count == 0)
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- }
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_NETWORK_EVENT, event,
- param);
-
- g_free(address);
- }
- }
- BT_DBG("-");
-}
void _bt_handle_agent_event(GVariant *msg, const char *member)
{
static int subs_interface_added_id = -1;
static int subs_interface_removed_id = -1;
- static int subs_name_owner_id = -1;
- static int subs_property_id = -1;
- static int subs_adapter_id = -1;
- static int subs_gatt_id = -1;
if (subscribe) {
if (subs_interface_added_id == -1) {
__bt_manager_event_filter,
NULL, NULL);
}
- if (subs_name_owner_id == -1) {
- subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_FREEDESKTOP_INTERFACE,
- BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_property_id == -1) {
- subs_property_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_PROPERTIES_INTERFACE,
- BT_PROPERTIES_CHANGED, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_adapter_id == -1) {
- subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_ADAPTER_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_gatt_id == -1) {
- subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_GATT_CHAR_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
+
} else {
if (subs_interface_added_id != -1) {
g_dbus_connection_signal_unsubscribe(conn,
subs_interface_removed_id);
subs_interface_removed_id = -1;
}
- if (subs_name_owner_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_name_owner_id);
- subs_name_owner_id = -1;
- }
- if (subs_property_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_property_id);
- subs_property_id = -1;
- }
- if (subs_adapter_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
- subs_adapter_id = -1;
- }
- if (subs_gatt_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
- subs_gatt_id = -1;
- }
}
return 0;
}
return 0;
}
-int _bt_register_network_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_serv_id = -1;
- static int subs_client_id = -1;
- if (subscribe) {
- if (subs_serv_id == -1) {
- subs_serv_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_NETWORK_SERVER_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_client_id == -1) {
- subs_client_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_NETWORK_CLIENT_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_serv_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_serv_id);
- subs_serv_id = -1;
- }
- if (subs_client_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_client_id);
- subs_client_id = -1;
- }
- }
- return 0;
-}
int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
int subscribe)
case BT_DEVICE_EVENT:
_bt_register_device_subscribe_signal(g_conn, TRUE);
break;
- case BT_NETWORK_EVENT:
- _bt_register_network_subscribe_signal(g_conn, TRUE);
- break;
case BT_OPP_SERVER_EVENT:
BT_ERR("BT_OPP_SERVER_EVENT: register service event");
_bt_register_opp_server_subscribe_signal(g_conn, TRUE);
_bt_register_manager_subscribe_signal(g_conn, FALSE);
_bt_register_device_subscribe_signal(g_conn, FALSE);
_bt_register_input_subscribe_signal(g_conn, FALSE);
- _bt_register_network_subscribe_signal(g_conn, FALSE);
break;
case BT_OPP_SERVER_EVENT:
_bt_register_opp_server_subscribe_signal(g_conn, FALSE);
if (_bt_register_service_event(manager_conn,
BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
goto fail;
- if (_bt_register_service_event(manager_conn,
- BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
- goto fail;
-
if (_bt_register_service_event(manager_conn,
- BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
+ BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
goto fail;
-
return BLUETOOTH_ERROR_NONE;
fail:
if (manager_conn) {
}
/* To receive the event from bluez */
-int _bt_init_service_event_receiver(void)
+int _bt_init_obex_event_receiver(void)
{
BT_DBG("+");
return BLUETOOTH_ERROR_NONE;
}
-void _bt_deinit_service_event_receiver(void)
+void _bt_deinit_obex_event_receiver(void)
{
BT_DBG("+");
*/
-#ifndef _BT_SERVICE_EVENT_H_
-#define _BT_SERVICE_EVENT_H_
+#ifndef _BT_SERVICE_OBEX_EVENT_H_
+#define _BT_SERVICE_OBEX_EVENT_H_
#include <sys/types.h>
int _bt_init_service_event_sender(void);
void _bt_deinit_service_event_sender(void);
-//int _bt_init_service_event_receiver(void);
-void _bt_deinit_service_event_receiver(void);
+int _bt_init_obex_event_receiver(void);
+void _bt_deinit_obex_event_receiver(void);
int _bt_opp_client_event_init(void);
void _bt_opp_client_event_deinit(void);
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <dlog.h>
+#include <string.h>
+#include <stdio.h>
+#include <syspopup_caller.h>
+#include <net_connection.h>
+
+#include "bluetooth-api.h"
+#include "bt-service-network.h"
+#include "bt-service-common.h"
+#include "bt-service-event.h"
+#include "bt-service-util.h"
+#include "bt-internal-types.h"
+
+void _bt_util_addr_type_to_addr_net_string(char *address,
+ unsigned char *addr)
+{
+ ret_if(address == NULL);
+ ret_if(addr == NULL);
+
+ snprintf(address, BT_ADDRESS_STR_LEN, "%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", addr[0],
+ addr[1], addr[2], addr[3], addr[4], addr[5]);
+}
+
+static connection_profile_h __bt_get_net_profile(void *connection,
+ connection_iterator_type_e type,
+ unsigned char *address)
+{
+ int result;
+ gchar **split_string;
+ char net_address[BT_ADDRESS_STR_LEN + 1] = { 0 };
+ char *profile_name = NULL;
+ connection_profile_iterator_h profile_iter;
+ connection_profile_h profile_h;
+ connection_profile_type_e profile_type;
+
+ retv_if(connection == NULL, NULL);
+ retv_if(address == NULL, NULL);
+
+ BT_DBG("net_conn: %x", connection);
+
+ _bt_util_addr_type_to_addr_net_string(net_address, address);
+
+ result = connection_get_profile_iterator(connection,
+ type,
+ &profile_iter);
+ if (result != CONNECTION_ERROR_NONE) {
+ BT_ERR("Fail to get profile iterator [%d]", result);
+ return NULL;
+ }
+
+ while (connection_profile_iterator_has_next(profile_iter)) {
+ profile_name = NULL;
+ profile_h = NULL;
+ split_string = NULL;
+
+ if (connection_profile_iterator_next(profile_iter,
+ &profile_h) != CONNECTION_ERROR_NONE) {
+ BT_ERR("Fail to get profile handle");
+ return NULL;
+ }
+
+ if (connection_profile_get_type(profile_h,
+ &profile_type) != CONNECTION_ERROR_NONE) {
+ BT_ERR("Fail to get profile type");
+ continue;
+ }
+
+ if (profile_type != CONNECTION_PROFILE_TYPE_BT)
+ continue;
+
+ if (connection_profile_get_name(profile_h,
+ &profile_name) != CONNECTION_ERROR_NONE) {
+ BT_ERR("Fail to get profile name");
+ return NULL;
+ }
+
+ split_string = g_strsplit(profile_name, "_", 3);
+
+ g_free(profile_name);
+
+ if (g_strv_length(split_string) < 3)
+ continue;
+
+ if (g_ascii_strcasecmp(split_string[2], net_address) == 0) {
+ BT_DBG("matched profile");
+ g_strfreev(split_string);
+ return profile_h;
+ }
+
+ g_strfreev(split_string);
+ }
+ BT_DBG("-");
+
+ return NULL;
+}
+
+int _bt_is_network_connected(void *connection, unsigned char *address,
+ gboolean *is_connected)
+{
+ void *handle = NULL;
+ handle = __bt_get_net_profile(connection,
+ CONNECTION_ITERATOR_TYPE_CONNECTED,
+ address);
+ if (handle)
+ *is_connected = TRUE;
+ else
+ *is_connected = FALSE;
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static void __bt_network_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *g_error = NULL;
+ GVariant *out_param1 = NULL;
+ GVariant *reply = NULL;
+ bluetooth_device_address_t device_addr = { {0} };
+ int result = BLUETOOTH_ERROR_NONE;
+ bt_function_data_t *func_data;
+ request_info_t *req_info;
+
+ reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("Network Connect Dbus Call Error");
+ if (g_error) {
+ BT_ERR("Error: %s\n", g_error->message);
+ g_clear_error(&g_error);
+ }
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ g_variant_unref(reply);
+
+ func_data = user_data;
+ if (func_data == NULL) {
+ /* Send reply */
+ BT_ERR("func_data == NULL");
+ goto done;
+ }
+
+ BT_ERR("func_data->req_id: %d", func_data->req_id);
+ req_info = _bt_get_request_info(func_data->req_id);
+ if (req_info == NULL) {
+ BT_ERR("req_info == NULL");
+ goto done;
+ }
+
+ if (req_info->context == NULL)
+ goto done;
+
+ _bt_convert_addr_string_to_type(device_addr.addr,
+ func_data->address);
+
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
+
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("iv", result, out_param1));
+
+ _bt_delete_request_list(req_info->req_id);
+
+done:
+ if (func_data) {
+ g_free(func_data->address);
+ g_free(func_data);
+ }
+}
+
+static void __bt_network_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *g_error = NULL;
+ GVariant *out_param1 = NULL;
+ GVariant *reply = NULL;
+ bluetooth_device_address_t device_addr = { {0} };
+ int result = BLUETOOTH_ERROR_NONE;
+ bt_function_data_t *func_data;
+ request_info_t *req_info;
+
+ reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("Network Disconnect Dbus Call Error");
+ if (g_error) {
+ BT_ERR("Error: %s\n", g_error->message);
+ g_clear_error(&g_error);
+ }
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ g_variant_unref(reply);
+
+ func_data = user_data;
+ if (func_data == NULL) {
+ /* Send reply */
+ BT_ERR("func_data == NULL");
+ goto done;
+ }
+ BT_ERR("func_data->req_id: %d", func_data->req_id);
+ req_info = _bt_get_request_info(func_data->req_id);
+ if (req_info == NULL) {
+ BT_ERR("req_info == NULL");
+ goto done;
+ }
+
+ if (g_error != NULL) {
+ BT_ERR("Network Connect Dbus Call Error: %s\n", g_error->message);
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ if (req_info->context == NULL)
+ goto done;
+
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
+
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("iv", result, out_param1));
+
+ _bt_delete_request_list(req_info->req_id);
+
+done:
+ if (func_data) {
+ g_free(func_data->address);
+ g_free(func_data);
+ }
+}
+
+int _bt_network_activate(void)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+ char *adapter_path;
+ GVariant *result = NULL;
+ GError *err = NULL;
+ GDBusConnection *conn;
+ GDBusProxy *server_proxy;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_path = _bt_get_adapter_path();
+ retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ server_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ adapter_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
+ g_free(adapter_path);
+
+ if (server_proxy == NULL) {
+ BT_ERR("Failed to get the network server proxy\n");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ result = g_dbus_proxy_call_sync(server_proxy, "Register",
+ g_variant_new("(ss)", NAP_UUID_NAME, NET_BRIDGE_INTERFACE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+ if (result == NULL) {
+ if (err != NULL) {
+ g_dbus_error_strip_remote_error(err);
+ BT_ERR("Network server register Error: %s\n", err->message);
+ if (g_strcmp0(err->message, "Already Exists") == 0)
+ ret = BLUETOOTH_ERROR_ALREADY_INITIALIZED;
+ else
+ ret = BLUETOOTH_ERROR_INTERNAL;
+
+ g_error_free(err);
+ }
+ } else {
+ g_variant_unref(result);
+ }
+
+ g_object_unref(server_proxy);
+
+ return ret;
+}
+
+int _bt_network_deactivate(void)
+{
+ char *adapter_path;
+ GVariant *result = NULL;
+ GError *err = NULL;
+ GDBusConnection *conn;
+ GDBusProxy *server_proxy;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_path = _bt_get_adapter_path();
+ retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ server_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ adapter_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
+ g_free(adapter_path);
+
+ if (server_proxy == NULL) {
+ BT_ERR("Failed to get the network server proxy\n");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ result = g_dbus_proxy_call_sync(server_proxy, "Unregister",
+ g_variant_new("(s)", NAP_UUID_NAME),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+ if (result == NULL) {
+ if (err != NULL) {
+ g_dbus_error_strip_remote_error(err);
+ BT_ERR("Network server unregister Error: %s\n", err->message);
+ if (g_strcmp0(err->message,
+ "Operation currently not available") == 0) {
+ ret = BLUETOOTH_ERROR_ALREADY_DEACTIVATED;
+ } else {
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ }
+ g_error_free(err);
+ }
+ } else {
+ g_variant_unref(result);
+ }
+
+ g_object_unref(server_proxy);
+
+ return ret;
+}
+
+int _bt_network_connect(int request_id, int role,
+ bluetooth_device_address_t *device_address)
+{
+ const gchar *device_path = NULL;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ char remote_role[BLUETOOTH_UUID_STRING_MAX] = { 0 };
+ bt_function_data_t *func_data;
+ GDBusProxy *adapter_proxy;
+ GDBusProxy *profile_proxy;
+ GDBusConnection *conn;
+ GVariant *result = NULL;
+ GError*err = NULL;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ switch (role) {
+ case BLUETOOTH_NETWORK_PANU_ROLE:
+ g_strlcpy(remote_role, PANU_UUID_NAME, BLUETOOTH_UUID_STRING_MAX);
+ break;
+
+ case BLUETOOTH_NETWORK_NAP_ROLE:
+ g_strlcpy(remote_role, NAP_UUID_NAME, BLUETOOTH_UUID_STRING_MAX);
+ break;
+
+ case BLUETOOTH_NETWORK_GN_ROLE:
+ g_strlcpy(remote_role, GN_UUID_NAME, BLUETOOTH_UUID_STRING_MAX);
+ break;
+ default:
+ BT_ERR("Unknown role");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ adapter_proxy = _bt_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &err);
+ if (result == NULL) {
+ BT_ERR("Error occurred in call to FindDevice");
+ if (err) {
+ BT_ERR("Error: %s", err->message);
+ g_clear_error(&err);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ device_path = g_variant_get_string(result, NULL);
+ if (device_path == NULL) {
+ BT_ERR("No paired device");
+ g_variant_unref(result);
+ return BLUETOOTH_ERROR_NOT_PAIRED;
+ }
+
+ profile_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL);
+
+ g_variant_unref(result);
+ retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ func_data = g_malloc0(sizeof(bt_function_data_t));
+ func_data->address = g_strdup(address);
+ func_data->req_id = request_id;
+
+ g_dbus_proxy_call(profile_proxy, "Connect",
+ g_variant_new("(s)", remote_role),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__bt_network_connect_cb,
+ func_data);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_network_disconnect(int request_id,
+ bluetooth_device_address_t *device_address)
+{
+ const gchar *device_path = NULL;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ bt_function_data_t *func_data;
+ GDBusProxy *adapter_proxy;
+ GDBusProxy *profile_proxy;
+ GDBusConnection *conn;
+ GVariant *result = NULL;
+ GError*err = NULL;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ adapter_proxy = _bt_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &err);
+ if (result == NULL) {
+ BT_ERR("Error occurred in call to FindDevice");
+ if (err) {
+ BT_ERR("Error: %s", err->message);
+ g_clear_error(&err);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ device_path = g_variant_get_string(result, NULL);
+ if (device_path == NULL) {
+ BT_ERR("No paired device");
+ g_variant_unref(result);
+ return BLUETOOTH_ERROR_NOT_PAIRED;
+ }
+
+ profile_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL);
+
+ g_variant_unref(result);
+ retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ func_data = g_malloc0(sizeof(bt_function_data_t));
+ func_data->address = g_strdup(address);
+ func_data->req_id = request_id;
+
+ g_dbus_proxy_call(profile_proxy, "Disconnect",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__bt_network_disconnect_cb,
+ func_data);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_network_server_disconnect(int request_id,
+ bluetooth_device_address_t *device_address)
+{
+ gchar *adapter_path = NULL;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ bt_function_data_t *func_data;
+ GDBusProxy *profile_proxy;
+ GDBusConnection *conn;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_path = _bt_get_adapter_path();
+ if (adapter_path == NULL) {
+ BT_ERR("No adapter found");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ profile_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ adapter_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
+ g_free(adapter_path);
+ retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ func_data = g_malloc0(sizeof(bt_function_data_t));
+
+ func_data->address = g_strdup(address);
+ func_data->req_id = request_id;
+
+ g_dbus_proxy_call(profile_proxy, "Disconnect",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__bt_network_disconnect_cb,
+ func_data);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+gboolean _bt_is_nap_panu_device_connected(bluetooth_device_address_t *address, int service_type)
+{
+ char *object_path = NULL;
+ GDBusProxy *device_proxy = NULL;
+ GVariant *tmp_value = NULL;
+ GVariant *result = NULL;
+ GError *error = NULL;
+ gboolean is_connected=true;
+ GVariant *value = NULL;
+ GDBusConnection *conn = NULL;
+
+
+ BT_DBG("+ %d",service_type);
+
+ conn=_bt_gdbus_get_system_gconn();
+ if(conn == NULL)
+ {
+ BT_DBG("_bt_gdbus_get_system_gconn returned NULL");
+ return is_connected;
+ }
+
+
+ if (service_type == BLUETOOTH_NAP_SERVER_SERVICE) {
+
+ object_path = _bt_get_adapter_path();
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
+ g_free(object_path);
+ if (device_proxy == NULL) {
+ BT_DBG("Device don't have this service");
+ return is_connected;
+ }
+
+ result = g_dbus_proxy_call_sync(device_proxy, "GetProperties",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result == NULL) {
+ BT_ERR("[GetProperties] Error occured in Proxy call");
+ if (error) {
+ BT_ERR("%s", error->message);
+ g_error_free(error);
+ }
+ is_connected = FALSE;
+ g_object_unref(device_proxy);
+ return is_connected;
+ }
+ g_variant_get(result , "(@a{sv})", &value);
+ g_variant_unref(result);
+
+ if (value) {
+ tmp_value = g_variant_lookup_value(value,
+ "Connected",
+ G_VARIANT_TYPE_BOOLEAN);
+ if (tmp_value) {
+ is_connected = g_variant_get_boolean(tmp_value);
+ BT_ERR("%d IsConnected >>>>",is_connected);
+ g_variant_unref(tmp_value);
+ }
+ g_variant_unref(value);
+ }
+ else
+ {
+ BT_ERR("Value is NULL");
+ }
+ } else if (service_type == BLUETOOTH_NAP_SERVICE) {
+ _bt_is_network_connected(_bt_get_net_conn(),
+ address->addr, &is_connected);
+ }
+
+ BT_DBG("-");
+ return true; //force it till conenction manager is fully supported
+
+}
+
+
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <string.h>
+#include <dlog.h>
+#include <vconf.h>
+#include "bt-service-common.h"
+#include <vconf-internal-bt-keys.h>
+#include "bt-service-event.h"
+//#include "bt-service-device.h"
+
+guint nap_connected_device_count = 0;
+static GDBusConnection *manager_conn;
+
+void bt_set_device_values(gboolean connected, int state)
+{
+ int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
+
+ if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
+ BT_ERR("vconf_get_int failed");
+
+ if (connected == TRUE)
+ bt_device_state |= state;
+ else if (bt_device_state & state)
+ bt_device_state ^= state;
+
+ if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
+ BT_ERR("vconf_set_int failed");
+}
+
+void _bt_handle_network_server_event(GVariant *msg, const char *member)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ char *address = NULL;
+ char *device = NULL;
+ GVariant *param = NULL;
+ ret_if(member == NULL);
+
+ BT_DBG("_bt_handle_network_server_event Event handler called >>>>>>>>>>>>>");
+ if (strcasecmp(member, "PeerConnected") == 0) {
+ g_variant_get(msg, "(ss)", &device, &address);
+
+ bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_PAN_CONNECTED);
+ param = g_variant_new("(iss)", result, device, address);
+ _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
+ param);
+ g_free(device);
+ g_free(address);
+ nap_connected_device_count++;
+ } else if (strcasecmp(member, "PeerDisconnected") == 0) {
+ g_variant_get(msg, "(ss)", &device, &address);
+ nap_connected_device_count--;
+ if (nap_connected_device_count == 0)
+ bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_PAN_CONNECTED);
+ param = g_variant_new("(iss)", result, device, address);
+ _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
+ param);
+ g_free(device);
+ g_free(address);
+ }
+}
+
+static void __bt_manager_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ if (signal_name == NULL)
+ return;
+
+ if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
+ _bt_handle_network_server_event(parameters, signal_name);
+ }
+ return;
+}
+
+int _bt_register_network_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ {
+ return -1;
+ }
+
+ static int subs_serv_id = -1;
+ static int subs_client_id = -1;
+
+ if (subscribe) {
+ if (subs_serv_id == -1) {
+ BT_DBG("_bt_register_network_subscribe_signal SUBSCRIBE SERVER SUCCESS>>>>>>>>>>>>>>>>>>>>> ..");
+ subs_serv_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_NETWORK_SERVER_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_client_id == -1) {
+ BT_DBG("_bt_register_network_subscribe_signal SUBSCRIBE CLIENT SUCCESS>>>>>>>>>>>>>>>>>>>>> ..");
+ subs_client_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_NETWORK_CLIENT_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_serv_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_serv_id);
+ subs_serv_id = -1;
+ }
+ if (subs_client_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_client_id);
+ subs_client_id = -1;
+ }
+ }
+ return 0;
+}
+
+static int __bt_init_manager_receiver(void)
+{
+ BT_DBG("+");
+
+ GError *error = NULL;
+
+ if (manager_conn == NULL) {
+ manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (error != NULL) {
+ BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
+ g_clear_error(&error);
+ }
+
+ retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+ }
+
+ if(_bt_register_network_subscribe_signal(manager_conn, TRUE)==-1)
+ {
+ BT_DBG("_bt_register_network_subscribe_signal Failed..");
+ goto fail;
+ }
+
+
+ return BLUETOOTH_ERROR_NONE;
+fail:
+ if (manager_conn) {
+ g_object_unref(manager_conn);
+ manager_conn = NULL;
+ }
+
+ BT_DBG("-");
+
+ return BLUETOOTH_ERROR_INTERNAL;
+}
+
+/* To receive the event from bluez */
+int _bt_init_pan_nap_event_receiver(void)
+{
+ BT_DBG("+");
+
+ int result;
+
+ result = __bt_init_manager_receiver();
+ retv_if(result != BLUETOOTH_ERROR_NONE, result);
+
+ BT_DBG("-");
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_deinit_pan_nap_event_receiver(void)
+{
+ BT_DBG("+");
+
+ _bt_register_network_subscribe_signal(manager_conn, FALSE);
+
+ if (manager_conn) {
+ g_object_unref(manager_conn);
+ manager_conn = NULL;
+ }
+
+ BT_DBG("-");
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#ifndef _BT_SERVICE_PAN_NAP_EVENT_H_
+#define _BT_SERVICE_PAN_NAP_EVENT_H_
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+int _bt_init_pan_nap_event_receiver(void);
+void _bt_deinit_pan_nap_event_receiver(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_BT_SERVICE_EVENT_H_*/
+
%build
export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
export CFLAGS="$CFLAGS -DTIZEN_FEATURE_BT_OBEX"
+export CFLAGS="$CFLAGS -DTIZEN_FEATURE_BT_PAN_NAP"
export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"