diff --git a/src/attrib-server.c b/src/attrib-server.c
index d987d76..219c7c9 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
#include "attrib-server.h"
-static GSList *database = NULL;
static GSList *servers = NULL;
struct gatt_server {
struct att_data_list *adl;
struct attribute *a;
struct group_elem *cur, *old = NULL;
- GSList *l, *groups;
+ GSList *l, *groups, *database;
uint16_t length, last_handle, last_size = 0;
uint8_t status;
int i;
ATT_ECODE_UNSUPP_GRP_TYPE, pdu, len);
last_handle = end;
+ database = channel->server->database;
for (l = database, groups = NULL, cur = NULL; l; l = l->next) {
a = l->data;
uint8_t *pdu, int len)
{
struct att_data_list *adl;
- GSList *l, *types;
+ GSList *l, *types, *database;
struct attribute *a;
uint16_t num, length;
uint8_t status;
return enc_error_resp(ATT_OP_READ_BY_TYPE_REQ, start,
ATT_ECODE_INVALID_HANDLE, pdu, len);
+ database = channel->server->database;
for (l = database, length = 0, types = NULL; l; l = l->next) {
a = l->data;
return length;
}
-static int find_info(uint16_t start, uint16_t end, uint8_t *pdu, int len)
+static int find_info(struct gatt_channel *channel, uint16_t start, uint16_t end,
+ uint8_t *pdu, int len)
{
struct attribute *a;
struct att_data_list *adl;
- GSList *l, *info;
+ GSList *l, *info, *database;
uint8_t format, last_type = BT_UUID_UNSPEC;
uint16_t length, num;
int i;
return enc_error_resp(ATT_OP_FIND_INFO_REQ, start,
ATT_ECODE_INVALID_HANDLE, pdu, len);
+ database = channel->server->database;
for (l = database, info = NULL, num = 0; l; l = l->next) {
a = l->data;
return length;
}
-static int find_by_type(uint16_t start, uint16_t end, bt_uuid_t *uuid,
- const uint8_t *value, int vlen, uint8_t *opdu, int mtu)
+static int find_by_type(struct gatt_channel *channel, uint16_t start,
+ uint16_t end, bt_uuid_t *uuid, const uint8_t *value,
+ int vlen, uint8_t *opdu, int mtu)
{
struct attribute *a;
struct att_range *range;
- GSList *l, *matches;
+ GSList *l, *matches, *database;
int len;
if (start > end || start == 0x0000)
ATT_ECODE_INVALID_HANDLE, opdu, mtu);
/* Searching first requested handle number */
+ database = channel->server->database;
for (l = database, matches = NULL, range = NULL; l; l = l->next) {
a = l->data;
uint16_t cccval;
guint h = handle;
- l = g_slist_find_custom(database, GUINT_TO_POINTER(h), handle_cmp);
+ l = g_slist_find_custom(channel->server->database,
+ GUINT_TO_POINTER(h), handle_cmp);
if (!l)
return enc_error_resp(ATT_OP_READ_REQ, handle,
ATT_ECODE_INVALID_HANDLE, pdu, len);
uint16_t cccval;
guint h = handle;
- l = g_slist_find_custom(database, GUINT_TO_POINTER(h), handle_cmp);
+ l = g_slist_find_custom(channel->server->database,
+ GUINT_TO_POINTER(h), handle_cmp);
if (!l)
return enc_error_resp(ATT_OP_READ_BLOB_REQ, handle,
ATT_ECODE_INVALID_HANDLE, pdu, len);
GSList *l;
guint h = handle;
- l = g_slist_find_custom(database, GUINT_TO_POINTER(h), handle_cmp);
+ l = g_slist_find_custom(channel->server->database,
+ GUINT_TO_POINTER(h), handle_cmp);
if (!l)
return enc_error_resp(ATT_OP_WRITE_REQ, handle,
ATT_ECODE_INVALID_HANDLE, pdu, len);
goto done;
}
- length = find_info(start, end, opdu, channel->mtu);
+ length = find_info(channel, start, end, opdu, channel->mtu);
break;
case ATT_OP_WRITE_REQ:
length = dec_write_req(ipdu, len, &start, value, &vlen);
goto done;
}
- length = find_by_type(start, end, &uuid, value, vlen,
+ length = find_by_type(channel, start, end, &uuid, value, vlen,
opdu, channel->mtu);
break;
case ATT_OP_HANDLE_CNF:
server = l->data;
servers = g_slist_remove(servers, server);
gatt_server_free(server);
-
- g_slist_free_full(database, attrib_free);
}
uint32_t attrib_create_sdp(uint16_t handle, const char *name)
uint16_t attrib_db_find_avail(uint16_t nitems)
{
+ struct gatt_server *server;
uint16_t handle;
GSList *l;
+ DBG("Deprecated function!");
+
g_assert(nitems > 0);
- for (l = database, handle = 0; l; l = l->next) {
+ server = get_default_gatt_server();
+ if (server == NULL)
+ return 0;
+
+ for (l = server->database, handle = 0; l; l = l->next) {
struct attribute *a = l->data;
if (handle && (bt_uuid_cmp(&a->uuid, &prim_uuid) == 0 ||
int attrib_db_update(uint16_t handle, bt_uuid_t *uuid, const uint8_t *value,
int len, struct attribute **attr)
{
+ struct gatt_server *server;
struct attribute *a;
GSList *l;
guint h = handle;
+ DBG("Deprecated function!");
+
+ server = get_default_gatt_server();
+ if (server == NULL)
+ return -ENOENT;
+
DBG("handle=0x%04x", handle);
- l = g_slist_find_custom(database, GUINT_TO_POINTER(h), handle_cmp);
+ l = g_slist_find_custom(server->database, GUINT_TO_POINTER(h),
+ handle_cmp);
if (!l)
return -ENOENT;
int attrib_db_del(uint16_t handle)
{
+ struct gatt_server *server;
struct attribute *a;
GSList *l;
guint h = handle;
+ DBG("Deprecated function!");
+
+ server = get_default_gatt_server();
+ if (server == NULL)
+ return -ENOENT;
+
DBG("handle=0x%04x", handle);
- l = g_slist_find_custom(database, GUINT_TO_POINTER(h), handle_cmp);
+ l = g_slist_find_custom(server->database, GUINT_TO_POINTER(h),
+ handle_cmp);
if (!l)
return -ENOENT;
a = l->data;
- database = g_slist_remove(database, a);
+ server->database = g_slist_remove(server->database, a);
g_free(a->data);
g_free(a);