Add the session timer to handle the exception case
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-agent.c
index 3224d32..d231908 100644 (file)
@@ -24,7 +24,9 @@
 #include <vconf.h>
 #include <bundle_internal.h>
 
+#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
 #include <tethering.h>
+#endif
 
 #include "bt-internal-types.h"
 #include "bt-service-common.h"
@@ -36,7 +38,7 @@
 #include "bt-service-device.h"
 #include "bt-service-audio.h"
 
-#ifdef TIZEN_FEATURE_BT_DPM
+#ifdef TIZEN_DPM_ENABLE
 #include "bt-service-dpm.h"
 #endif
 
@@ -259,15 +261,11 @@ static gboolean __pincode_request(GapAgentPrivate *agent, GDBusProxy *device)
        GVariant *reply_temp = NULL;
        GVariant *tmp_value;
        char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
-#ifdef TIZEN_FEATURE_BT_DPM
-       int pairing_state = DPM_STATUS_ERROR;
-#endif
 
        BT_DBG("+");
 
-#ifdef TIZEN_FEATURE_BT_DPM
-       _bt_dpm_get_bluetooth_pairing_state(&pairing_state);
-       if (pairing_state == DPM_RESTRICTED) {
+#ifdef TIZEN_DPM_ENABLE
+       if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
                BT_ERR("Not allow to pair the device");
                gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
                __bt_agent_release_memory();
@@ -369,15 +367,10 @@ static gboolean __passkey_request(GapAgentPrivate *agent, GDBusProxy *device)
        GVariant *reply = NULL;
        GVariant *reply_temp = NULL;
        GVariant *tmp_value;
-#ifdef TIZEN_FEATURE_BT_DPM
-       int pairing_state = DPM_STATUS_ERROR;
-#endif
-
        BT_DBG("+");
 
-#ifdef TIZEN_FEATURE_BT_DPM
-       _bt_dpm_get_bluetooth_pairing_state(&pairing_state);
-       if (pairing_state == DPM_RESTRICTED) {
+#ifdef TIZEN_DPM_ENABLE
+       if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
                BT_ERR("Not allow to pair the device");
                gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
                __bt_agent_release_memory();
@@ -503,14 +496,10 @@ static gboolean __confirm_request(GapAgentPrivate *agent, GDBusProxy *device,
        GVariant *reply_temp = NULL;
        GVariant *reply = NULL;
        GVariant *tmp_value;
-#ifdef TIZEN_FEATURE_BT_DPM
-               int pairing_state = DPM_STATUS_ERROR;
-#endif
        BT_DBG("+ passkey[%.6d]", passkey);
 
-#ifdef TIZEN_FEATURE_BT_DPM
-       _bt_dpm_get_bluetooth_pairing_state(&pairing_state);
-       if (pairing_state == DPM_RESTRICTED) {
+#ifdef TIZEN_DPM_ENABLE
+       if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
                BT_ERR("Not allow to pair the device");
                gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
                __bt_agent_release_memory();
@@ -589,10 +578,12 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
        GVariant *reply = NULL;
        GVariant *reply_temp = NULL;
        GVariant *tmp_value;
+#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
        bool enabled;
+       tethering_h tethering = NULL;
+#endif
        int result = BLUETOOTH_ERROR_NONE;
        int request_type = BT_AGENT_EVENT_AUTHORIZE_REQUEST;
-       tethering_h tethering = NULL;
 
        BT_DBG("+");
 
@@ -634,41 +625,43 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
              !strcasecmp(uuid, BNEP_UUID)) {
 
                BT_DBG("Network connection request: %s", uuid);
-               if (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);
+#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;
-                       }
+               if (ret != TETHERING_ERROR_NONE) {
+                       BT_ERR("Fail to create tethering: %d", ret);
+                       goto fail;
+               }
 
-                       enabled = tethering_is_enabled(tethering, TETHERING_TYPE_BT);
+               enabled = tethering_is_enabled(tethering, TETHERING_TYPE_BT);
 
-                       ret = tethering_destroy(tethering);
+               ret = tethering_destroy(tethering);
 
-                       if (ret != TETHERING_ERROR_NONE)
-                               BT_ERR("Fail to create tethering: %d", ret);
+               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;
-                       }
+               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);
@@ -711,7 +704,6 @@ fail:
 
                goto done;
        }
-       /* TODO: MAP? see above */
 
        if (_gap_agent_exist_osp_server(agent, BT_RFCOMM_SERVER,
                                        (char *)uuid) == TRUE) {
@@ -735,7 +727,6 @@ fail:
                request_type = BT_AGENT_EVENT_PBAP_REQUEST;
        else if (!strcasecmp(uuid, MAP_UUID))
                request_type = BT_AGENT_EVENT_MAP_REQUEST;
-       /* TODO: MAP is already here */
 
        if (trust) {
                BT_INFO("Trusted device, so authorize\n");