Android BLE Gatt返回错误对应宏

参考android源码stack/include/gatt_api.h

一般当onStatesChange回调出现 states不为0 既有错误的时候调用close gatt.close()释放一下GATT就应该可以解决问题的

#ifndef GATT_API_H
  #define GATT_API_H
   
  #include "bt_target.h"
  #include "gattdefs.h"
   
  /*****************************************************************************
  ** Constants
  *****************************************************************************/
  /* Success code and error codes */
  #define GATT_SUCCESS 0x00
  #define GATT_INVALID_HANDLE 0x01
  #define GATT_READ_NOT_PERMIT 0x02
  #define GATT_WRITE_NOT_PERMIT 0x03
  #define GATT_INVALID_PDU 0x04
  #define GATT_INSUF_AUTHENTICATION 0x05
  #define GATT_REQ_NOT_SUPPORTED 0x06
  #define GATT_INVALID_OFFSET 0x07
  #define GATT_INSUF_AUTHORIZATION 0x08
  #define GATT_PREPARE_Q_FULL 0x09
  #define GATT_NOT_FOUND 0x0a
  #define GATT_NOT_LONG 0x0b
  #define GATT_INSUF_KEY_SIZE 0x0c
  #define GATT_INVALID_ATTR_LEN 0x0d
  #define GATT_ERR_UNLIKELY 0x0e
  #define GATT_INSUF_ENCRYPTION 0x0f
  #define GATT_UNSUPPORT_GRP_TYPE 0x10
  #define GATT_INSUF_RESOURCE 0x11
   
   
  #define GATT_ILLEGAL_PARAMETER 0x87
  #define GATT_NO_RESOURCES 0x80
  #define GATT_INTERNAL_ERROR 0x81
  #define GATT_WRONG_STATE 0x82
  #define GATT_DB_FULL 0x83
  #define GATT_BUSY 0x84
  #define GATT_ERROR 0x85
  #define GATT_CMD_STARTED 0x86
  #define GATT_PENDING 0x88
  #define GATT_AUTH_FAIL 0x89
  #define GATT_MORE 0x8a
  #define GATT_INVALID_CFG 0x8b
  #define GATT_SERVICE_STARTED 0x8c
  #define GATT_ENCRYPED_MITM GATT_SUCCESS
  #define GATT_ENCRYPED_NO_MITM 0x8d
  #define GATT_NOT_ENCRYPTED 0x8e
  #define GATT_CONGESTED 0x8f
   
  /* 0xE0 ~ 0xFC reserved for future use */
  #define GATT_CCC_CFG_ERR 0xFD /* Client Characteristic Configuration Descriptor Improperly Configured */
  #define GATT_PRC_IN_PROGRESS 0xFE /* Procedure Already in progress */
  #define GATT_OUT_OF_RANGE 0xFF /* Attribute value out of range */
  typedef UINT8 tGATT_STATUS;
   
   
  #define GATT_RSP_ERROR 0x01
  #define GATT_REQ_MTU 0x02
  #define GATT_RSP_MTU 0x03
  #define GATT_REQ_FIND_INFO 0x04
  #define GATT_RSP_FIND_INFO 0x05
  #define GATT_REQ_FIND_TYPE_VALUE 0x06
  #define GATT_RSP_FIND_TYPE_VALUE 0x07
  #define GATT_REQ_READ_BY_TYPE 0x08
  #define GATT_RSP_READ_BY_TYPE 0x09
  #define GATT_REQ_READ 0x0A
  #define GATT_RSP_READ 0x0B
  #define GATT_REQ_READ_BLOB 0x0C
  #define GATT_RSP_READ_BLOB 0x0D
  #define GATT_REQ_READ_MULTI 0x0E
  #define GATT_RSP_READ_MULTI 0x0F
  #define GATT_REQ_READ_BY_GRP_TYPE 0x10
  #define GATT_RSP_READ_BY_GRP_TYPE 0x11
  #define GATT_REQ_WRITE 0x12 /* 0001-0010 (write)*/
  #define GATT_RSP_WRITE 0x13
  #define GATT_CMD_WRITE 0x52 /* changed in V4.0 01001-0010(write cmd)*/
  #define GATT_REQ_PREPARE_WRITE 0x16
  #define GATT_RSP_PREPARE_WRITE 0x17
  #define GATT_REQ_EXEC_WRITE 0x18
  #define GATT_RSP_EXEC_WRITE 0x19
  #define GATT_HANDLE_VALUE_NOTIF 0x1B
  #define GATT_HANDLE_VALUE_IND 0x1D
  #define GATT_HANDLE_VALUE_CONF 0x1E
  #define GATT_SIGN_CMD_WRITE 0xD2 /* changed in V4.0 1101-0010 (signed write) see write cmd above*/
  #define GATT_OP_CODE_MAX GATT_HANDLE_VALUE_CONF + 1 /* 0x1E = 30 + 1 = 31*/
   
   
  #define GATT_HANDLE_IS_VALID(x) ((x) != 0)
   
  #define GATT_CONN_UNKNOWN 0
  #define GATT_CONN_L2C_FAILURE 1 /* general L2cap failure */
  #define GATT_CONN_TIMEOUT HCI_ERR_CONNECTION_TOUT /* 0x08 connection timeout */
  #define GATT_CONN_TERMINATE_PEER_USER HCI_ERR_PEER_USER /* 0x13 connection terminate by peer user */
  #define GATT_CONN_TERMINATE_LOCAL_HOST HCI_ERR_CONN_CAUSE_LOCAL_HOST /* 0x16 connectionterminated by local host */
  #define GATT_CONN_FAIL_ESTABLISH HCI_ERR_CONN_FAILED_ESTABLISHMENT/* 0x03E connection fail to establish */
  #define GATT_CONN_LMP_TIMEOUT HCI_ERR_LMP_RESPONSE_TIMEOUT /* 0x22 connection fail for LMP response tout */
  #define GATT_CONN_CANCEL L2CAP_CONN_CANCEL /* 0x0100 L2CAP connection cancelled */
  typedef UINT16 tGATT_DISCONN_REASON;
   
  /* MAX GATT MTU size
  */
  #ifndef GATT_MAX_MTU_SIZE
  #define GATT_MAX_MTU_SIZE 517
  #endif
   
  /* max legth of an attribute value
  */
  #ifndef GATT_MAX_ATTR_LEN
  #define GATT_MAX_ATTR_LEN 600
  #endif
   
  /* default GATT MTU size over LE link
  */
  #define GATT_DEF_BLE_MTU_SIZE 23
   
  /* invalid connection ID
  */
  #define GATT_INVALID_CONN_ID 0xFFFF
   
  #ifndef GATT_CL_MAX_LCB
  #define GATT_CL_MAX_LCB 22
  #endif
   
  #ifndef GATT_MAX_SCCB
  #define GATT_MAX_SCCB 10
  #endif
   
   
  /* GATT notification caching timer, default to be three seconds
  */
  #ifndef GATTC_NOTIF_TIMEOUT
  #define GATTC_NOTIF_TIMEOUT 3
  #endif
   
  /*****************************************************************************
  ** GATT Structure Definition
  *****************************************************************************/
   
  /* Attribute permissions
  */
  #define GATT_PERM_READ (1 << 0) /* bit 0 */
  #define GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 */
  #define GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 */
  #define GATT_PERM_WRITE (1 << 4) /* bit 4 */
  #define GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 */
  #define GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 */
  #define GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 */
  #define GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 */
  typedef UINT16 tGATT_PERM;
   
  #define GATT_ENCRYPT_KEY_SIZE_MASK (0xF000) /* the MS nibble of tGATT_PERM; key size 7=0; size 16=9 */
   
  #define GATT_READ_ALLOWED (GATT_PERM_READ | GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM)
  #define GATT_READ_AUTH_REQUIRED (GATT_PERM_READ_ENCRYPTED)
  #define GATT_READ_MITM_REQUIRED (GATT_PERM_READ_ENC_MITM)
  #define GATT_READ_ENCRYPTED_REQUIRED (GATT_PERM_READ_ENCRYPTED | GATT_PERM_READ_ENC_MITM)
   
   
  #define GATT_WRITE_ALLOWED (GATT_PERM_WRITE | GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM | \
  GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM)
   
  #define GATT_WRITE_AUTH_REQUIRED (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_SIGNED)
   
  #define GATT_WRITE_MITM_REQUIRED (GATT_PERM_WRITE_ENC_MITM | GATT_PERM_WRITE_SIGNED_MITM)
   
  #define GATT_WRITE_ENCRYPTED_PERM (GATT_PERM_WRITE_ENCRYPTED | GATT_PERM_WRITE_ENC_MITM)
   
  #define GATT_WRITE_SIGNED_PERM (GATT_PERM_WRITE_SIGNED | GATT_PERM_WRITE_SIGNED_MITM)
   
   
  /* Characteristic properties
  */
  #define GATT_CHAR_PROP_BIT_BROADCAST (1 << 0)
  #define GATT_CHAR_PROP_BIT_READ (1 << 1)
  #define GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2)
  #define GATT_CHAR_PROP_BIT_WRITE (1 << 3)
  #define GATT_CHAR_PROP_BIT_NOTIFY (1 << 4)
  #define GATT_CHAR_PROP_BIT_INDICATE (1 << 5)
  #define GATT_CHAR_PROP_BIT_AUTH (1 << 6)
  #define GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7)
  typedef UINT8 tGATT_CHAR_PROP;
   
   
  /* Format of the value of a characteristic. enumeration type
  */
  enum
  {
  GATT_FORMAT_RES, /* rfu */
  GATT_FORMAT_BOOL, /* 0x01 boolean */
  GATT_FORMAT_2BITS, /* 0x02 2 bit */
  GATT_FORMAT_NIBBLE, /* 0x03 nibble */
  GATT_FORMAT_UINT8, /* 0x04 uint8 */
  GATT_FORMAT_UINT12, /* 0x05 uint12 */
  GATT_FORMAT_UINT16, /* 0x06 uint16 */
  GATT_FORMAT_UINT24, /* 0x07 uint24 */
  GATT_FORMAT_UINT32, /* 0x08 uint32 */
  GATT_FORMAT_UINT48, /* 0x09 uint48 */
  GATT_FORMAT_UINT64, /* 0x0a uint64 */
  GATT_FORMAT_UINT128, /* 0x0B uint128 */
  GATT_FORMAT_SINT8, /* 0x0C signed 8 bit integer */
  GATT_FORMAT_SINT12, /* 0x0D signed 12 bit integer */
  GATT_FORMAT_SINT16, /* 0x0E signed 16 bit integer */
  GATT_FORMAT_SINT24, /* 0x0F signed 24 bit integer */
  GATT_FORMAT_SINT32, /* 0x10 signed 32 bit integer */
  GATT_FORMAT_SINT48, /* 0x11 signed 48 bit integer */
  GATT_FORMAT_SINT64, /* 0x12 signed 64 bit integer */
  GATT_FORMAT_SINT128, /* 0x13 signed 128 bit integer */
  GATT_FORMAT_FLOAT32, /* 0x14 float 32 */
  GATT_FORMAT_FLOAT64, /* 0x15 float 64*/
  GATT_FORMAT_SFLOAT, /* 0x16 IEEE-11073 16 bit SFLOAT */
  GATT_FORMAT_FLOAT, /* 0x17 IEEE-11073 32 bit SFLOAT */
  GATT_FORMAT_DUINT16, /* 0x18 IEEE-20601 format */
  GATT_FORMAT_UTF8S, /* 0x19 UTF-8 string */
  GATT_FORMAT_UTF16S, /* 0x1a UTF-16 string */
  GATT_FORMAT_STRUCT, /* 0x1b Opaque structure*/
  GATT_FORMAT_MAX /* 0x1c or above reserved */
  };
  typedef UINT8 tGATT_FORMAT;

你可能感兴趣的:(Android;BLE)