X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-gap-agent.c;h=dccf480b5b4f380286e5a0b5f347fdf2c1886ee5;hb=1fa07edcd0e77a445700975773db3300f556caf5;hp=bf81920c2ffc956507bf60fb8ae344e59a8eedc4;hpb=449d38c6b737be52e1e166ed281bf8c778847e62;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-gap-agent.c b/bt-service/bt-service-gap-agent.c old mode 100755 new mode 100644 index bf81920..dccf480 --- a/bt-service/bt-service-gap-agent.c +++ b/bt-service/bt-service-gap-agent.c @@ -112,10 +112,6 @@ gboolean _gap_agent_register_osp_server(GapAgentPrivate *agent, return FALSE; server = g_malloc0(sizeof(bt_agent_osp_server_t)); - - /* Fix : NULL_RETURNS */ - retv_if(server == NULL, FALSE); - server->type = type; if (type == BT_RFCOMM_SERVER) { server->uuid = g_strdup(uuid); @@ -169,8 +165,6 @@ gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept, BT_DBG("+"); GapAgentPrivate *priv = agent; - - /* Fix : NULL_RETURNS */ retv_if(priv == NULL, FALSE); if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION && @@ -215,8 +209,6 @@ gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept, BT_DBG("+"); GapAgentPrivate *priv = agent; - - /* Fix : NULL_RETURNS */ retv_if(priv == NULL, FALSE); if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION && @@ -261,8 +253,6 @@ gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept BT_DBG("+"); GapAgentPrivate *priv = agent; - - /* Fix : NULL_RETURNS */ retv_if(priv == NULL, FALSE); if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION && @@ -307,8 +297,6 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept, BT_DBG("+"); GapAgentPrivate *priv = agent; - - /* Fix : NULL_RETURNS */ retv_if(priv == NULL, FALSE); if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION && @@ -316,15 +304,20 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept, if (accept == GAP_AGENT_ACCEPT) { g_dbus_method_invocation_return_value(priv->reply_context, NULL); } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) { - bluetooth_device_address_t addr = {{0,}}; + bluetooth_device_address_t addr = { { 0, } }; int result; _bt_convert_addr_string_to_type(addr.addr, priv->authorize_addr); - result = _bt_set_authorization(&addr, TRUE); + /* Do not set device as Trusted*/ + /* result = _bt_set_authorization(&addr, TRUE); */ + result = _bt_set_trust_profile(&addr, + _bt_get_trusted_profile_enum(priv->uuid), + TRUE); if (result == BLUETOOTH_ERROR_NONE) { - BT_INFO("[%s] Device added to trusted", priv->authorize_addr); + BT_INFO("[%s] Profile added as trusted for Device[%s]", + priv->uuid, priv->authorize_addr); } g_dbus_method_invocation_return_value(priv->reply_context, NULL); @@ -335,8 +328,28 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept, GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL, "CanceledbyUser"); break; + case GAP_AGENT_REJECT: { + bluetooth_device_address_t addr = { { 0, } }; + int result; + + _bt_convert_addr_string_to_type(addr.addr, + priv->authorize_addr); + + /* Set Profile as blocked */ + result = _bt_set_trust_profile(&addr, + _bt_get_trusted_profile_enum(priv->uuid), + FALSE); + if (result == BLUETOOTH_ERROR_NONE) { + BT_INFO("[%s] Profile added as blocked for Device[%s]", + priv->uuid, priv->authorize_addr); + } + + g_dbus_method_invocation_return_error(priv->reply_context, + GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT, + "Authorization request rejected"); + break; + } case GAP_AGENT_TIMEOUT: - case GAP_AGENT_REJECT: default: g_dbus_method_invocation_return_error(priv->reply_context, GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT, @@ -357,9 +370,13 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept, ret = FALSE; } - priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION; - priv->reply_context = NULL; - memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr)); + if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION) { + priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION; + priv->reply_context = NULL; + memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr)); + g_free(priv->uuid); + priv->uuid = NULL; + } BT_DBG("-"); @@ -395,8 +412,10 @@ gboolean _gap_agent_register(GapAgentPrivate *agent) reply = g_dbus_proxy_call_sync(agent_manager, "RegisterAgent", #ifdef TIZEN_BT_IO_CAPA_NO_INPUT_OUTPUT g_variant_new("(os)", priv->path, "NoInputNoOutput"), +#elif defined(TIZEN_BT_IO_CAPA_DISPLAY_ONLY) + g_variant_new("(os)", priv->path, "DisplayOnly"), #else - g_variant_new("(os)", priv->path, "DisplayYesNo"), + g_variant_new("(os)", priv->path, "KeyboardDisplay"), #endif G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); @@ -466,7 +485,7 @@ static gboolean __gap_agent_unregister(GapAgentPrivate *agent) } reply = g_dbus_proxy_call_sync(agent_manager, "UnregisterAgent", - g_variant_new("o", priv->path), + g_variant_new("(o)", priv->path), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); g_object_unref(agent_manager); @@ -489,53 +508,53 @@ static gboolean __gap_agent_unregister(GapAgentPrivate *agent) static const gchar gap_agent_bluez_introspection_xml[] = "" " " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " " " -" " +" " " " " " +" " +" " +" " +" " " " -" " +" " " " -" " -" " -" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " " " -" " -" " -" " -" " +" " +" " " " -" " +" " " " +" " " " -" " +" " " " -" " " " -" " +" " " " +" " " " -" " -" " -" " +" " +" " " " " " " " " " -" " -" " -" " +" " +" " +" " " " " " ""; @@ -596,7 +615,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection, if (!agent->cb.passkey_func) return; - conn = _bt_get_system_gconn(); + conn = _bt_gdbus_get_system_gconn(); if (conn == NULL) return; @@ -629,9 +648,8 @@ static void __bt_gap_agent_method(GDBusConnection *connection, addr += 4; g_strlcpy(agent->pairing_addr, addr, sizeof(agent->pairing_addr)); - while ((pos = strchr(agent->pairing_addr, '_')) != NULL) { + while ((pos = strchr(agent->pairing_addr, '_')) != NULL) *pos = ':'; - } } agent->cb.pincode_func(agent, device); @@ -662,7 +680,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection, if (!priv->cb.passkey_func) return; - conn = _bt_get_system_gconn(); + conn = _bt_gdbus_get_system_gconn(); if (conn == NULL) return; @@ -695,9 +713,8 @@ static void __bt_gap_agent_method(GDBusConnection *connection, addr += 4; g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr)); - while ((pos = strchr(priv->pairing_addr, '_')) != NULL) { + while ((pos = strchr(priv->pairing_addr, '_')) != NULL) *pos = ':'; - } } priv->cb.passkey_func(priv, device); @@ -719,7 +736,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection, g_variant_get(parameters, "(&ouq)", &path, &passkey, &entered); BT_INFO("Request passkey display :sender %s priv->busname %s" - " Device Path :%s, Passkey: %d, Entered: %d", + " Device Path :%s, Passkey: %06d, Entered: %d", sender, priv->busname, path, passkey, entered); /* Do not show popup for Key event while typing*/ @@ -734,7 +751,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection, if (!priv->cb.display_func) return; - conn = _bt_get_system_gconn(); + conn = _bt_gdbus_get_system_gconn(); if (conn == NULL) return; @@ -778,8 +795,8 @@ static void __bt_gap_agent_method(GDBusConnection *connection, return; g_variant_get(parameters, "(&ou)", &path, &passkey); - BT_INFO("Request passkey confirmation, Device Path :%s, Passkey: %d", - path, passkey); + BT_INFO_C("### Request passkey confirmation"); + INFO_SECURE("Device Path :%s, Passkey: %d", path, passkey); BT_DBG("Sender: [%s] priv->busname: [%s]", sender, priv->busname); /* Need to check @@ -791,7 +808,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection, if (!priv->cb.confirm_func) return; - conn = _bt_get_system_gconn(); + conn = _bt_gdbus_get_system_gconn(); if (conn == NULL) return; @@ -824,9 +841,8 @@ static void __bt_gap_agent_method(GDBusConnection *connection, addr += 4; g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr)); - while ((pos = strchr(priv->pairing_addr, '_')) != NULL) { + while ((pos = strchr(priv->pairing_addr, '_')) != NULL) *pos = ':'; - } } priv->cb.confirm_func(priv, device, passkey); @@ -859,7 +875,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection, if (!priv->cb.authorize_func) return; - conn = _bt_get_system_gconn(); + conn = _bt_gdbus_get_system_gconn(); if (conn == NULL) return; @@ -885,6 +901,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection, priv->exec_type = GAP_AGENT_EXEC_AUTHORZATION; priv->reply_context = invocation; + priv->uuid = g_strdup(uuid); addr = strstr(path, "dev_"); if (addr != NULL) { @@ -893,9 +910,8 @@ static void __bt_gap_agent_method(GDBusConnection *connection, g_strlcpy(priv->authorize_addr, addr, sizeof(priv->authorize_addr)); - while ((pos = strchr(priv->authorize_addr, '_')) != NULL) { + while ((pos = strchr(priv->authorize_addr, '_')) != NULL) *pos = ':'; - } } priv->cb.authorize_func(priv, device, uuid); @@ -1035,7 +1051,6 @@ void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb, GDBusNodeInfo *node_info; GError *error = NULL; - priv->path = g_strdup(path); @@ -1046,13 +1061,16 @@ void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb, BT_DBG("path is [%s]", path); - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - if (error) { - ERR("Unable to connect to gdbus: %s", error->message); - g_clear_error(&error); + if (connection == NULL) { + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!connection) { + if (error) { + ERR("Unable to connect to gdbus: %s", error->message); + g_clear_error(&error); + } + g_dbus_node_info_unref(node_info); + return; } - return; } if (gap_agent_id == -1) { @@ -1096,8 +1114,8 @@ void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb, priv->busname = NULL; } else { priv->busname = g_strdup(g_dbus_proxy_get_name(proxy)); - g_object_unref(proxy); BT_DBG("Busname: %s", priv->busname); + g_object_unref(proxy); } } @@ -1105,17 +1123,20 @@ void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb, void _gap_agent_reset_dbus(GapAgentPrivate *agent) { GapAgentPrivate *priv = agent; - - /* Fix : NULL_RETURNS */ if (priv == NULL) - return ; + return; __gap_agent_unregister(agent); if (gap_agent_id > 0) { g_dbus_connection_unregister_object(connection, gap_agent_id); - gap_agent_id = 0; + gap_agent_id = -1; + } + + if (connection) { + g_object_unref(connection); + connection = NULL; } if (priv->osp_servers) { @@ -1124,9 +1145,6 @@ void _gap_agent_reset_dbus(GapAgentPrivate *agent) priv->osp_servers = NULL; } - g_object_ref(priv->adapter); - priv->adapter = NULL; - g_free(priv->path); priv->path = NULL; @@ -1138,8 +1156,8 @@ gboolean _gap_agent_exist_osp_server(GapAgentPrivate *agent, int type, char *uui { GapAgentPrivate *priv = agent; - /* Fix : NULL_RETURNS */ - retv_if(priv == NULL, FALSE); + if (priv == NULL) + return FALSE; if (__gap_agent_find_server(priv->osp_servers, type, uuid) != NULL) { @@ -1159,9 +1177,8 @@ bt_agent_osp_server_t *_gap_agent_get_osp_server(GapAgentPrivate *agent, int typ osp_serv = __gap_agent_find_server(priv->osp_servers, type, uuid); - if (!osp_serv) { + if (!osp_serv) return NULL; - } return osp_serv; } @@ -1169,8 +1186,6 @@ bt_agent_osp_server_t *_gap_agent_get_osp_server(GapAgentPrivate *agent, int typ gchar* _gap_agent_get_path(GapAgentPrivate *agent) { GapAgentPrivate *priv = agent; - - /* Fix : NULL_RETURNS */ if (priv == NULL) return NULL; @@ -1181,17 +1196,12 @@ gboolean _gap_agent_is_canceled(GapAgentPrivate *agent) { GapAgentPrivate *priv = agent; - /* Fix : NULL_RETURNS */ - retv_if(priv == NULL, FALSE); - return priv->canceled; } void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value) { GapAgentPrivate *priv = agent; - - /* Fix : NULL_RETURNS */ if (priv == NULL) return;