mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-25 05:04:18 +08:00
Initial GAttrib functions
GAttrib aims to provide high level functions to hide GATT/ATT internals. GATT client and server shall use these functions to serialize ATT requests/responses.
This commit is contained in:
parent
b4ad35aafe
commit
fcc6c7788e
@ -79,6 +79,8 @@ sbc_sbcdec_LDADD = sbc/libsbc.la
|
||||
sbc_sbcenc_SOURCES = sbc/sbcenc.c sbc/formats.h
|
||||
sbc_sbcenc_LDADD = sbc/libsbc.la
|
||||
|
||||
attrib_sources = attrib/att.h attrib/att.c attrib/gattrib.h attrib/gattrib.c
|
||||
|
||||
if SNDFILE
|
||||
noinst_PROGRAMS += sbc/sbctester
|
||||
|
||||
@ -170,7 +172,8 @@ endif
|
||||
|
||||
if ATTRIBPLUGIN
|
||||
builtin_modules += attrib
|
||||
builtin_sources += attrib/main.c attrib/manager.h attrib/manager.c \
|
||||
builtin_sources += $(attrib_sources) attrib/main.c \
|
||||
attrib/manager.h attrib/manager.c \
|
||||
attrib/client.h attrib/client.c \
|
||||
attrib/example.h attrib/example.c
|
||||
endif
|
||||
|
41
attrib/att.c
Normal file
41
attrib/att.c
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
*
|
||||
* BlueZ - Bluetooth protocol stack for Linux
|
||||
*
|
||||
* Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/sdp.h>
|
||||
|
||||
#include "att.h"
|
||||
|
||||
int att_read_by_grp_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint8_t *pdu, int len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int att_find_by_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint8_t *pdu, int len)
|
||||
{
|
||||
return 0;
|
||||
}
|
121
attrib/att.h
Normal file
121
attrib/att.h
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
*
|
||||
* BlueZ - Bluetooth protocol stack for Linux
|
||||
*
|
||||
* Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ATT_H
|
||||
#define __ATT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* GATT Profile Attribute types */
|
||||
#define GATT_PRIM_SVC_UUID 0x2800
|
||||
#define GATT_SND_SVC_UUID 0x2801
|
||||
#define GATT_INCLUDE_UUID 0x2802
|
||||
#define GATT_CHARAC_UUID 0x2803
|
||||
|
||||
/* GATT Characteristic Types */
|
||||
#define GATT_CHARAC_DEVICE_NAME 0x2A00
|
||||
#define GATT_CHARAC_APPEARANCE 0x2A01
|
||||
#define GATT_CHARAC_PERIPHERAL_PRIV_FLAG 0x2A02
|
||||
#define GATT_CHARAC_RECONNECTION_ADDRESS 0x2A03
|
||||
#define GATT_CHARAC_PERIPHERAL_PREF_CONN 0x2A04
|
||||
#define GATT_CHARAC_SERVICE_CHANGED 0x2A05
|
||||
|
||||
/* GATT Characteristic Descriptors */
|
||||
#define GATT_CHARAC_EXT_PROPER_UUID 0x2900
|
||||
#define GATT_CHARAC_USER_DESC_UUID 0x2901
|
||||
#define GATT_CLIENT_CHARAC_CFG_UUID 0x2902
|
||||
#define GATT_SERVER_CHARAC_CFG_UUID 0x2903
|
||||
#define GATT_CHARAC_FMT_UUID 0x2904
|
||||
#define GATT_CHARAC_AGREG_FMT_UUID 0x2905
|
||||
|
||||
/* Attribute Protocol Opcodes */
|
||||
#define ATT_OP_ERROR 0x01
|
||||
#define ATT_OP_MTU_REQ 0x02
|
||||
#define ATT_OP_MTU_RESP 0x03
|
||||
#define ATT_OP_FIND_INFO_REQ 0x04
|
||||
#define ATT_OP_FIND_INFO_RESP 0x05
|
||||
#define ATT_OP_FIND_BY_TYPE_REQ 0x06
|
||||
#define ATT_OP_FIND_BY_TYPE_RESP 0x07
|
||||
#define ATT_OP_READ_BY_TYPE_REQ 0x08
|
||||
#define ATT_OP_READ_BY_TYPE_RESP 0x09
|
||||
#define ATT_OP_READ_REQ 0x0A
|
||||
#define ATT_OP_READ_RESP 0x0B
|
||||
#define ATT_OP_READ_BLOB_REQ 0x0C
|
||||
#define ATT_OP_READ_BLOB_RESP 0x0D
|
||||
#define ATT_OP_READ_MULTI_REQ 0x0E
|
||||
#define ATT_OP_READ_MULTI_RESP 0x0F
|
||||
#define ATT_OP_READ_BY_GROUP_REQ 0x10
|
||||
#define ATT_OP_READ_BY_GROUP_RESP 0x11
|
||||
#define ATT_OP_WRITE_REQ 0x12
|
||||
#define ATT_OP_WRITE_RESP 0x13
|
||||
#define ATT_OP_WRITE_CMD 0x14
|
||||
#define ATT_OP_PREP_WRITE_REQ 0x16
|
||||
#define ATT_OP_PREP_WRITE_RESP 0x17
|
||||
#define ATT_OP_EXEC_WRITE_REQ 0x18
|
||||
#define ATT_OP_EXEC_WRITE_RESP 0x19
|
||||
#define ATT_OP_HANDLE_NOTIFY 0x1B
|
||||
#define ATT_OP_HANDLE_IND 0x1D
|
||||
#define ATT_OP_HANDLE_CNF 0x1E
|
||||
#define ATT_OP_SIGNED_WRITE_CMD 0x94
|
||||
|
||||
/* Error codes for Error response PDU */
|
||||
#define ATT_ECODE_INVALID_HANDLE 0x01
|
||||
#define ATT_ECODE_READ_NOT_PERM 0x02
|
||||
#define ATT_ECODE_WRITE_NOT_PERM 0x03
|
||||
#define ATT_ECODE_INVALID_PDU 0x04
|
||||
#define ATT_ECODE_INSUFF_AUTHEN 0x05
|
||||
#define ATT_ECODE_REQ_NOT_SUPP 0x06
|
||||
#define ATT_ECODE_INVALID_OFFSET 0x07
|
||||
#define ATT_ECODE_INSUFF_AUTHO 0x08
|
||||
#define ATT_ECODE_PREP_QUEUE_FULL 0x09
|
||||
#define ATT_ECODE_ATTR_NOT_FOUND 0x0A
|
||||
#define ATT_ECODE_ATTR_NOT_LONG 0x0B
|
||||
#define ATT_ECODE_INSUFF_ENCR_KEY_SIZE 0x0C
|
||||
#define ATT_ECODE_INVAL_ATTR_VALUE_LEN 0x0D
|
||||
#define ATT_ECODE_UNLIKELY 0x0E
|
||||
#define ATT_ECODE_INSUFF_ENC 0x0F
|
||||
#define ATT_ECODE_UNSUPP_GRP_SIZE 0x10
|
||||
#define ATT_ECODE_INSUFF_RESOURCES 0x11
|
||||
|
||||
/* Characteristic Property bit field */
|
||||
#define ATT_CHAR_PROPER_BROADCAST 0x01
|
||||
#define ATT_CHAR_PROPER_READ 0x02
|
||||
#define ATT_CHAR_PROPER_WRITE_WITHOUT_RESP 0x04
|
||||
#define ATT_CHAR_PROPER_WRITE 0x08
|
||||
#define ATT_CHAR_PROPER_NOTIFY 0x10
|
||||
#define ATT_CHAR_PROPER_INDICATE 0x20
|
||||
#define ATT_CHAR_PROPER_AUTH 0x40
|
||||
#define ATT_CHAR_PROPER_EXT_PROPER 0x80
|
||||
|
||||
|
||||
int att_read_by_grp_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint8_t *pdu, int len);
|
||||
int att_find_by_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint8_t *pdu, int len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ATT_H */
|
92
attrib/gattrib.c
Normal file
92
attrib/gattrib.c
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
*
|
||||
* BlueZ - Bluetooth protocol stack for Linux
|
||||
*
|
||||
* Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "gattrib.h"
|
||||
|
||||
struct _GAttrib {
|
||||
GIOChannel *io;
|
||||
guint refs;
|
||||
};
|
||||
|
||||
GAttrib *g_attrib_new(GIOChannel *io)
|
||||
{
|
||||
struct _GAttrib *attrib;
|
||||
|
||||
attrib = g_new0(struct _GAttrib, 1);
|
||||
attrib->io = io;
|
||||
attrib->refs = 1;
|
||||
|
||||
return attrib;
|
||||
}
|
||||
|
||||
GAttrib *g_attrib_ref(GAttrib *attrib)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void g_attrib_unref(GAttrib *attrib)
|
||||
{
|
||||
}
|
||||
|
||||
guint g_attrib_send(GAttrib *attrib, guint8 opcode, const guint8 *pdu,
|
||||
guint16 len, GAttribResultFunc func,
|
||||
gpointer user_data, GDestroyNotify notify)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
gboolean g_attrib_cancel(GAttrib *attrib, guint id)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean g_attrib_cancel_all(GAttrib *attrib)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean g_attrib_set_debug(GAttrib *attrib,
|
||||
GAttribDebugFunc func, gpointer user_data)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
guint g_attrib_register(GAttrib *attrib, guint8 opcode,
|
||||
GAttribNotifyFunc func, gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gboolean g_attrib_unregister(GAttrib *attrib, guint id)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean g_attrib_unregister_all(GAttrib *attrib)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
65
attrib/gattrib.h
Normal file
65
attrib/gattrib.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
*
|
||||
* BlueZ - Bluetooth protocol stack for Linux
|
||||
*
|
||||
* Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
#ifndef __GATTRIB_H
|
||||
#define __GATTRIB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct _GAttrib;
|
||||
typedef struct _GAttrib GAttrib;
|
||||
|
||||
typedef void (*GAttribResultFunc) (guint8 status, const guint8 *pdu,
|
||||
guint16 len, gpointer user_data);
|
||||
typedef void (*GAttribDisconnectFunc)(gpointer user_data);
|
||||
typedef void (*GAttribDebugFunc)(const char *str, gpointer user_data);
|
||||
typedef void (*GAttribNotifyFunc)(const guint8 *pdu, gpointer user_data);
|
||||
|
||||
GAttrib *g_attrib_new(GIOChannel *io);
|
||||
GAttrib *g_attrib_ref(GAttrib *attrib);
|
||||
void g_attrib_unref(GAttrib *attrib);
|
||||
|
||||
gboolean g_attrib_set_disconnect_function(GAttrib *attrib,
|
||||
GAttribDisconnectFunc disconnect, gpointer user_data);
|
||||
|
||||
guint g_attrib_send(GAttrib *attrib, guint8 opcode, const guint8 *pdu,
|
||||
guint16 len, GAttribResultFunc func,
|
||||
gpointer user_data, GDestroyNotify notify);
|
||||
gboolean g_attrib_cancel(GAttrib *attrib, guint id);
|
||||
gboolean g_attrib_cancel_all(GAttrib *attrib);
|
||||
|
||||
gboolean g_attrib_set_debug(GAttrib *attrib,
|
||||
GAttribDebugFunc func, gpointer user_data);
|
||||
|
||||
guint g_attrib_register(GAttrib *attrib, guint8 opcode,
|
||||
GAttribNotifyFunc func, gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
|
||||
gboolean g_attrib_unregister(GAttrib *attrib, guint id);
|
||||
gboolean g_attrib_unregister_all(GAttrib *attrib);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user