From 46c59677c238a44ee90206ce0003d150376f3d00 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 15 Aug 2012 18:20:09 +0300 Subject: [PATCH] attrib: Fix naming and variable types of security requirements There's a single read/write requirement value so the variables should be named in singular form. Also, until there's e.g. an enum typedef for them a simple int shall do. --- attrib/att-database.h | 4 ++-- attrib/gatt-service.c | 16 ++++++++-------- src/attrib-server.c | 24 ++++++++++++------------ src/attrib-server.h | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/attrib/att-database.h b/attrib/att-database.h index e022eeca8..48c50e385 100644 --- a/attrib/att-database.h +++ b/attrib/att-database.h @@ -31,8 +31,8 @@ enum { struct attribute { uint16_t handle; bt_uuid_t uuid; - size_t read_reqs; - size_t write_reqs; + int read_req; /* Read requirement */ + int write_req; /* Write requirement */ uint8_t (*read_cb)(struct attribute *a, struct btd_device *device, gpointer user_data); uint8_t (*write_cb)(struct attribute *a, struct btd_device *device, diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c index a9de98c94..e8788d9e4 100644 --- a/attrib/gatt-service.c +++ b/attrib/gatt-service.c @@ -139,7 +139,7 @@ static struct attribute *add_service_declaration(struct btd_adapter *adapter, ATT_NOT_PERMITTED, atval, len); } -static int att_read_reqs(int authorization, int authentication, uint8_t props) +static int att_read_req(int authorization, int authentication, uint8_t props) { if (authorization == GATT_CHR_VALUE_READ || authorization == GATT_CHR_VALUE_BOTH) @@ -153,7 +153,7 @@ static int att_read_reqs(int authorization, int authentication, uint8_t props) return ATT_NONE; } -static int att_write_reqs(int authorization, int authentication, uint8_t props) +static int att_write_req(int authorization, int authentication, uint8_t props) { if (authorization == GATT_CHR_VALUE_WRITE || authorization == GATT_CHR_VALUE_BOTH) @@ -179,7 +179,7 @@ static gint find_callback(gconstpointer a, gconstpointer b) static gboolean add_characteristic(struct btd_adapter *adapter, uint16_t *handle, struct gatt_info *info) { - int read_reqs, write_reqs; + int read_req, write_req; uint16_t h = *handle; struct attribute *a; bt_uuid_t bt_uuid; @@ -191,14 +191,14 @@ static gboolean add_characteristic(struct btd_adapter *adapter, return FALSE; } - read_reqs = att_read_reqs(info->authorization, info->authentication, + read_req = att_read_req(info->authorization, info->authentication, info->props); - write_reqs = att_write_reqs(info->authorization, info->authentication, + write_req = att_write_req(info->authorization, info->authentication, info->props); /* TODO: static characteristic values are not supported, therefore a * callback must be always provided if a read/write property is set */ - if (read_reqs != ATT_NOT_PERMITTED) { + if (read_req != ATT_NOT_PERMITTED) { gpointer reqs = GUINT_TO_POINTER(ATTRIB_READ); if (!g_slist_find_custom(info->callbacks, reqs, @@ -208,7 +208,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter, } } - if (write_reqs != ATT_NOT_PERMITTED) { + if (write_req != ATT_NOT_PERMITTED) { gpointer reqs = GUINT_TO_POINTER(ATTRIB_WRITE); if (!g_slist_find_custom(info->callbacks, reqs, @@ -228,7 +228,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter, return FALSE; /* characteristic value */ - a = attrib_db_add(adapter, h++, &info->uuid, read_reqs, write_reqs, + a = attrib_db_add(adapter, h++, &info->uuid, read_req, write_req, NULL, 0); if (a == NULL) return FALSE; diff --git a/src/attrib-server.c b/src/attrib-server.c index bbed1a908..145fada87 100644 --- a/src/attrib-server.c +++ b/src/attrib-server.c @@ -339,7 +339,7 @@ static uint32_t attrib_create_sdp_new(struct gatt_server *server, static struct attribute *attrib_db_add_new(struct gatt_server *server, uint16_t handle, bt_uuid_t *uuid, - size_t read_reqs, size_t write_reqs, + int read_req, int write_req, const uint8_t *value, size_t len) { struct attribute *a; @@ -356,8 +356,8 @@ static struct attribute *attrib_db_add_new(struct gatt_server *server, a->data = g_memdup(value, len); a->handle = handle; a->uuid = *uuid; - a->read_reqs = read_reqs; - a->write_reqs = write_reqs; + a->read_req = read_req; + a->write_req = write_req; server->database = g_list_insert_sorted(server->database, a, attribute_cmp); @@ -456,7 +456,7 @@ static uint16_t read_by_group(struct gatt_channel *channel, uint16_t start, break; status = att_check_reqs(channel, ATT_OP_READ_BY_GROUP_REQ, - a->read_reqs); + a->read_req); if (status == 0x00 && a->read_cb) status = a->read_cb(a, channel->device, @@ -546,7 +546,7 @@ static uint16_t read_by_type(struct gatt_channel *channel, uint16_t start, continue; status = att_check_reqs(channel, ATT_OP_READ_BY_TYPE_REQ, - a->read_reqs); + a->read_req); if (status == 0x00 && a->read_cb) status = a->read_cb(a, channel->device, @@ -763,7 +763,7 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle, return enc_read_resp(config, sizeof(config), pdu, len); } - status = att_check_reqs(channel, ATT_OP_READ_REQ, a->read_reqs); + status = att_check_reqs(channel, ATT_OP_READ_REQ, a->read_req); if (status == 0x00 && a->read_cb) status = a->read_cb(a, channel->device, a->cb_user_data); @@ -809,7 +809,7 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle, pdu, len); } - status = att_check_reqs(channel, ATT_OP_READ_BLOB_REQ, a->read_reqs); + status = att_check_reqs(channel, ATT_OP_READ_BLOB_REQ, a->read_req); if (status == 0x00 && a->read_cb) status = a->read_cb(a, channel->device, a->cb_user_data); @@ -838,7 +838,7 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle, a = l->data; - status = att_check_reqs(channel, ATT_OP_WRITE_REQ, a->write_reqs); + status = att_check_reqs(channel, ATT_OP_WRITE_REQ, a->write_req); if (status) return enc_error_resp(ATT_OP_WRITE_REQ, handle, status, pdu, len); @@ -1431,9 +1431,9 @@ uint16_t attrib_db_find_avail(struct btd_adapter *adapter, bt_uuid_t *svc_uuid, } struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle, - bt_uuid_t *uuid, size_t read_reqs, - size_t write_reqs, - const uint8_t *value, size_t len) + bt_uuid_t *uuid, int read_req, + int write_req, const uint8_t *value, + size_t len) { GSList *l; @@ -1441,7 +1441,7 @@ struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle, if (l == NULL) return NULL; - return attrib_db_add_new(l->data, handle, uuid, read_reqs, write_reqs, + return attrib_db_add_new(l->data, handle, uuid, read_req, write_req, value, len); } diff --git a/src/attrib-server.h b/src/attrib-server.h index 3ec62ed18..214801700 100644 --- a/src/attrib-server.h +++ b/src/attrib-server.h @@ -25,8 +25,8 @@ uint16_t attrib_db_find_avail(struct btd_adapter *adapter, bt_uuid_t *svc_uuid, uint16_t nitems); struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle, - bt_uuid_t *uuid, size_t read_reqs, - size_t write_reqs, const uint8_t *value, + bt_uuid_t *uuid, int read_req, + int write_req, const uint8_t *value, size_t len); int attrib_db_update(struct btd_adapter *adapter, uint16_t handle, bt_uuid_t *uuid, const uint8_t *value, -- 2.47.3