* [PATCH 02/10] SAP: Fix some code style issue
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
@ 2012-05-25 14:20 ` Szymon Janc
2012-05-25 14:20 ` [PATCH 03/10] sap-dummy: Use constants when setting ongoing call status Szymon Janc
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
sap/sap-dummy.c | 14 +++++++-------
sap/server.c | 13 ++++++-------
2 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/sap/sap-dummy.c b/sap/sap-dummy.c
index e2032cf..679adbb 100644
--- a/sap/sap-dummy.c
+++ b/sap/sap-dummy.c
@@ -39,16 +39,16 @@
#define SAP_DUMMY_PATH "/org/bluez/test"
enum {
- SIM_DISCONNECTED= 0x00,
- SIM_CONNECTED = 0x01,
- SIM_POWERED_OFF = 0x02,
- SIM_MISSING = 0x03
+ SIM_DISCONNECTED = 0x00,
+ SIM_CONNECTED = 0x01,
+ SIM_POWERED_OFF = 0x02,
+ SIM_MISSING = 0x03
};
static DBusConnection *connection = NULL;
static int sim_card_conn_status = SIM_DISCONNECTED;
-static void *sap_data = NULL; /* SAP server private data.*/
+static void *sap_data = NULL; /* SAP server private data. */
static gboolean ongoing_call_status = FALSE;
static int max_msg_size_supported = 512;
@@ -113,7 +113,7 @@ void sap_transfer_apdu_req(void *sap_device, struct sap_parameter *param)
SAP_RESULT_ERROR_NOT_ACCESSIBLE, NULL, 0);
else
sap_transfer_apdu_rsp(sap_device, SAP_RESULT_OK,
- (uint8_t*)&apdu, sizeof(apdu));
+ (uint8_t *)&apdu, sizeof(apdu));
}
void sap_transfer_atr_req(void *sap_device)
@@ -133,7 +133,7 @@ void sap_transfer_atr_req(void *sap_device)
NULL, 0);
else
sap_transfer_atr_rsp(sap_device, SAP_RESULT_OK,
- (uint8_t*)&atr, sizeof(atr));
+ (uint8_t *)&atr, sizeof(atr));
}
void sap_power_sim_off_req(void *sap_device)
diff --git a/sap/server.c b/sap/server.c
index 776bf36..85c4b82 100644
--- a/sap/server.c
+++ b/sap/server.c
@@ -147,7 +147,7 @@ static int check_msg(struct sap_message *msg)
return -EBADMSG;
if (msg->param->id != SAP_PARAM_ID_COMMAND_APDU)
- if ( msg->param->id != SAP_PARAM_ID_COMMAND_APDU7816)
+ if (msg->param->id != SAP_PARAM_ID_COMMAND_APDU7816)
return -EBADMSG;
if (msg->param->len == 0x00)
@@ -230,8 +230,7 @@ static sdp_record_t *create_sap_record(uint8_t channel)
aproto = sdp_list_append(NULL, apseq);
sdp_set_access_protos(record, aproto);
- sdp_set_info_attr(record, "SIM Access Server",
- NULL, NULL);
+ sdp_set_info_attr(record, "SIM Access Server", NULL, NULL);
sdp_data_free(ch);
sdp_list_free(proto[0], NULL);
@@ -863,7 +862,7 @@ int sap_reset_sim_rsp(void *sap_device, uint8_t result)
return -EINVAL;
DBG("state %d pr 0x%02x result 0x%02x", conn->state,
- conn->processing_req, result);
+ conn->processing_req, result);
if (conn->processing_req != SAP_RESET_SIM_REQ)
return 0;
@@ -891,7 +890,7 @@ int sap_transfer_card_reader_status_rsp(void *sap_device, uint8_t result,
return -EINVAL;
DBG("state %d pr 0x%02x result 0x%02x", conn->state,
- conn->processing_req, result);
+ conn->processing_req, result);
if (conn->processing_req != SAP_TRANSFER_CARD_READER_STATUS_REQ)
return 0;
@@ -927,7 +926,7 @@ int sap_transport_protocol_rsp(void *sap_device, uint8_t result)
return -EINVAL;
DBG("state %d pr 0x%02x result 0x%02x", conn->state,
- conn->processing_req, result);
+ conn->processing_req, result);
if (conn->processing_req != SAP_SET_TRANSPORT_PROTOCOL_REQ)
return 0;
@@ -968,7 +967,7 @@ int sap_status_ind(void *sap_device, uint8_t status_change)
return -EINVAL;
DBG("state %d pr 0x%02x sc 0x%02x", conn->state, conn->processing_req,
- status_change);
+ status_change);
/* Might be need to change state to connected after ongoing call.*/
if (conn->state == SAP_STATE_CONNECT_MODEM_BUSY &&
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 03/10] sap-dummy: Use constants when setting ongoing call status
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
2012-05-25 14:20 ` [PATCH 02/10] SAP: Fix some code style issue Szymon Janc
@ 2012-05-25 14:20 ` Szymon Janc
2012-05-25 14:20 ` [PATCH 04/10] sap-dummy: Small refactor to sap_connect_req Szymon Janc
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This improves readbility of whan new ongoing call status is being set.
---
sap/sap-dummy.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sap/sap-dummy.c b/sap/sap-dummy.c
index 679adbb..9a21779 100644
--- a/sap/sap-dummy.c
+++ b/sap/sap-dummy.c
@@ -227,10 +227,10 @@ static DBusMessage *ongoing_call(DBusConnection *conn, DBusMessage *msg,
if (ongoing_call_status && !ongoing) {
/* An ongoing call has finished. Continue connection.*/
sap_status_ind(sap_data, SAP_STATUS_CHANGE_CARD_RESET);
- ongoing_call_status = ongoing;
+ ongoing_call_status = FALSE;
} else if (!ongoing_call_status && ongoing) {
/* An ongoing call has started.*/
- ongoing_call_status = ongoing;
+ ongoing_call_status = TRUE;
}
DBG("OngoingCall status set to %d", ongoing_call_status);
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 04/10] sap-dummy: Small refactor to sap_connect_req
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
2012-05-25 14:20 ` [PATCH 02/10] SAP: Fix some code style issue Szymon Janc
2012-05-25 14:20 ` [PATCH 03/10] sap-dummy: Use constants when setting ongoing call status Szymon Janc
@ 2012-05-25 14:20 ` Szymon Janc
2012-05-25 14:20 ` [PATCH 05/10] sap-dummy: Remove not needed includes Szymon Janc
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This makes function easier to read and more similar to rest of code.
---
sap/sap-dummy.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/sap/sap-dummy.c b/sap/sap-dummy.c
index 9a21779..238c5f3 100644
--- a/sap/sap-dummy.c
+++ b/sap/sap-dummy.c
@@ -60,26 +60,32 @@ void sap_connect_req(void *sap_device, uint16_t maxmsgsize)
sap_connect_rsp(sap_device, SAP_STATUS_CONNECTION_FAILED,
maxmsgsize);
return;
- } else if (max_msg_size_supported > maxmsgsize) {
+ }
+
+ if (max_msg_size_supported > maxmsgsize) {
sap_connect_rsp(sap_device, SAP_STATUS_MAX_MSG_SIZE_TOO_SMALL,
max_msg_size_supported);
return;
- } else if (max_msg_size_supported < maxmsgsize) {
+ }
+
+ if (max_msg_size_supported < maxmsgsize) {
sap_connect_rsp(sap_device,
SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED,
max_msg_size_supported);
return;
- } else if (ongoing_call_status) {
+ }
+
+ if (ongoing_call_status) {
sap_connect_rsp(sap_device, SAP_STATUS_OK_ONGOING_CALL,
max_msg_size_supported);
return;
- } else {
- sim_card_conn_status = SIM_CONNECTED;
- sap_data = sap_device;
-
- sap_connect_rsp(sap_device, SAP_STATUS_OK, maxmsgsize);
- sap_status_ind(sap_device, SAP_STATUS_CHANGE_CARD_RESET);
}
+
+ sim_card_conn_status = SIM_CONNECTED;
+ sap_data = sap_device;
+
+ sap_connect_rsp(sap_device, SAP_STATUS_OK, maxmsgsize);
+ sap_status_ind(sap_device, SAP_STATUS_CHANGE_CARD_RESET);
}
void sap_disconnect_req(void *sap_device, uint8_t linkloss)
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 05/10] sap-dummy: Remove not needed includes
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
` (2 preceding siblings ...)
2012-05-25 14:20 ` [PATCH 04/10] sap-dummy: Small refactor to sap_connect_req Szymon Janc
@ 2012-05-25 14:20 ` Szymon Janc
2012-05-25 14:20 ` [PATCH 06/10] SAP: " Szymon Janc
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
sap/sap-dummy.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/sap/sap-dummy.c b/sap/sap-dummy.c
index 238c5f3..fd185c9 100644
--- a/sap/sap-dummy.c
+++ b/sap/sap-dummy.c
@@ -26,9 +26,6 @@
#include <config.h>
#endif
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdint.h>
#include <glib.h>
#include <gdbus.h>
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 06/10] SAP: Remove not needed includes
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
` (3 preceding siblings ...)
2012-05-25 14:20 ` [PATCH 05/10] sap-dummy: Remove not needed includes Szymon Janc
@ 2012-05-25 14:20 ` Szymon Janc
2012-05-25 14:20 ` [PATCH 07/10] SAP: Remove not needed src field from struct sap_server Szymon Janc
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
sap/manager.c | 10 ----------
sap/server.c | 3 ---
2 files changed, 13 deletions(-)
diff --git a/sap/manager.c b/sap/manager.c
index a97f434..9fa9c56 100644
--- a/sap/manager.c
+++ b/sap/manager.c
@@ -22,18 +22,8 @@
#include <config.h>
#endif
-#include <errno.h>
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/sdp.h>
-#include <bluetooth/sdp_lib.h>
-
-#include <gdbus.h>
-
#include "log.h"
#include "adapter.h"
-#include "device.h"
#include "manager.h"
#include "server.h"
diff --git a/sap/server.c b/sap/server.c
index 85c4b82..aedbc60 100644
--- a/sap/server.c
+++ b/sap/server.c
@@ -28,11 +28,8 @@
#include <config.h>
#endif
-#include <stdio.h>
#include <errno.h>
#include <glib.h>
-#include <netinet/in.h>
-#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 07/10] SAP: Remove not needed src field from struct sap_server
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
` (4 preceding siblings ...)
2012-05-25 14:20 ` [PATCH 06/10] SAP: " Szymon Janc
@ 2012-05-25 14:20 ` Szymon Janc
2012-05-25 14:21 ` [PATCH 08/10] SAP: Remove one line of indentation in sap_io_destroy Szymon Janc
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:20 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
src is only used in sap_server_register, no need to keep in memory for
SAP session duration.
---
sap/server.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sap/server.c b/sap/server.c
index aedbc60..98440e8 100644
--- a/sap/server.c
+++ b/sap/server.c
@@ -72,7 +72,6 @@ struct sap_connection {
};
struct sap_server {
- bdaddr_t src;
char *path;
uint32_t record_id;
GIOChannel *listen_io;
@@ -1348,7 +1347,6 @@ int sap_server_register(const char *path, bdaddr_t *src)
return -ENOMEM;
}
- bacpy(&server->src, src);
server->path = g_strdup(path);
record = create_sap_record(SAP_SERVER_CHANNEL);
@@ -1357,7 +1355,7 @@ int sap_server_register(const char *path, bdaddr_t *src)
goto sdp_err;
}
- if (add_record_to_server(&server->src, record) < 0) {
+ if (add_record_to_server(src, record) < 0) {
error("Adding SAP SDP record to the SDP server failed.");
sdp_record_free(record);
goto sdp_err;
@@ -1367,7 +1365,7 @@ int sap_server_register(const char *path, bdaddr_t *src)
io = bt_io_listen(BT_IO_RFCOMM, NULL, connect_confirm_cb, server,
NULL, &gerr,
- BT_IO_OPT_SOURCE_BDADDR, &server->src,
+ BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_CHANNEL, SAP_SERVER_CHANNEL,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_HIGH,
BT_IO_OPT_MASTER, TRUE,
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 08/10] SAP: Remove one line of indentation in sap_io_destroy
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
` (5 preceding siblings ...)
2012-05-25 14:20 ` [PATCH 07/10] SAP: Remove not needed src field from struct sap_server Szymon Janc
@ 2012-05-25 14:21 ` Szymon Janc
2012-05-25 14:21 ` [PATCH 09/10] sap-dummy: Fix DBus connection leak if interface registration failed Szymon Janc
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
sap/server.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/sap/server.c b/sap/server.c
index 98440e8..00c540e 100644
--- a/sap/server.c
+++ b/sap/server.c
@@ -1111,28 +1111,28 @@ static gboolean sap_io_cb(GIOChannel *io, GIOCondition cond, gpointer data)
static void sap_io_destroy(void *data)
{
struct sap_connection *conn = data;
+ gboolean connected = FALSE;
DBG("conn %p", conn);
- if (conn && conn->io) {
- gboolean connected = FALSE;
+ if (!conn || !conn->io)
+ return;
- stop_guard_timer(conn);
+ stop_guard_timer(conn);
- if (conn->state != SAP_STATE_CONNECT_IN_PROGRESS &&
- conn->state != SAP_STATE_CONNECT_MODEM_BUSY)
- emit_property_changed(connection, server->path,
+ if (conn->state != SAP_STATE_CONNECT_IN_PROGRESS &&
+ conn->state != SAP_STATE_CONNECT_MODEM_BUSY)
+ emit_property_changed(connection, server->path,
SAP_SERVER_INTERFACE, "Connected",
DBUS_TYPE_BOOLEAN, &connected);
- if (conn->state == SAP_STATE_CONNECT_IN_PROGRESS ||
- conn->state == SAP_STATE_CONNECT_MODEM_BUSY ||
- conn->state == SAP_STATE_CONNECTED ||
- conn->state == SAP_STATE_GRACEFUL_DISCONNECT)
- sap_disconnect_req(NULL, 1);
+ if (conn->state == SAP_STATE_CONNECT_IN_PROGRESS ||
+ conn->state == SAP_STATE_CONNECT_MODEM_BUSY ||
+ conn->state == SAP_STATE_CONNECTED ||
+ conn->state == SAP_STATE_GRACEFUL_DISCONNECT)
+ sap_disconnect_req(NULL, 1);
- sap_conn_remove(conn);
- }
+ sap_conn_remove(conn);
}
static void sap_connect_cb(GIOChannel *io, GError *gerr, gpointer data)
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 09/10] sap-dummy: Fix DBus connection leak if interface registration failed
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
` (6 preceding siblings ...)
2012-05-25 14:21 ` [PATCH 08/10] SAP: Remove one line of indentation in sap_io_destroy Szymon Janc
@ 2012-05-25 14:21 ` Szymon Janc
2012-05-25 14:21 ` [PATCH 10/10] SAP: Remove not needed checks from disconnect_ind Szymon Janc
2012-05-27 19:42 ` [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Johan Hedberg
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
If DBus interface registration failed dbus connection should be
unreferenced.
---
sap/sap-dummy.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sap/sap-dummy.c b/sap/sap-dummy.c
index fd185c9..7ea4e92 100644
--- a/sap/sap-dummy.c
+++ b/sap/sap-dummy.c
@@ -342,6 +342,8 @@ int sap_init(void)
NULL, NULL) == FALSE) {
error("sap-dummy interface %s init failed on path %s",
SAP_DUMMY_IFACE, SAP_DUMMY_PATH);
+ dbus_connection_unref(connection);
+ connection = NULL;
return -1;
}
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 10/10] SAP: Remove not needed checks from disconnect_ind
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
` (7 preceding siblings ...)
2012-05-25 14:21 ` [PATCH 09/10] sap-dummy: Fix DBus connection leak if interface registration failed Szymon Janc
@ 2012-05-25 14:21 ` Szymon Janc
2012-05-27 19:42 ` [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Johan Hedberg
9 siblings, 0 replies; 11+ messages in thread
From: Szymon Janc @ 2012-05-25 14:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
disconnect_ind is an helper funtion and is always called with valid
connection and from valid state so there is no need to double check
that.
---
sap/server.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/sap/server.c b/sap/server.c
index 00c540e..c83e68a 100644
--- a/sap/server.c
+++ b/sap/server.c
@@ -274,18 +274,8 @@ static int disconnect_ind(void *sap_device, uint8_t disc_type)
struct sap_parameter *param = (struct sap_parameter *) msg->param;
size_t size = sizeof(struct sap_message);
- if (!conn)
- return -EINVAL;
-
DBG("data %p state %d disc_type 0x%02x", conn, conn->state, disc_type);
- if (conn->state != SAP_STATE_GRACEFUL_DISCONNECT &&
- conn->state != SAP_STATE_IMMEDIATE_DISCONNECT) {
- error("Processing error (state %d pr 0x%02x)", conn->state,
- conn->processing_req);
- return -EPERM;
- }
-
memset(buf, 0, sizeof(buf));
msg->id = SAP_DISCONNECT_IND;
msg->nparam = 0x01;
--
on behalf of ST-Ericsson
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg
2012-05-25 14:20 [PATCH 01/10] SAP: Remove not needed NULL pointer check in check_msg Szymon Janc
` (8 preceding siblings ...)
2012-05-25 14:21 ` [PATCH 10/10] SAP: Remove not needed checks from disconnect_ind Szymon Janc
@ 2012-05-27 19:42 ` Johan Hedberg
9 siblings, 0 replies; 11+ messages in thread
From: Johan Hedberg @ 2012-05-27 19:42 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, May 25, 2012, Szymon Janc wrote:
> Buffer passed to check_msg() is always valid.
> ---
> sap/server.c | 3 ---
> 1 file changed, 3 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 11+ messages in thread