component/bt : new architectecture

1st compile ok
This commit is contained in:
Tian Hao
2016-11-15 20:56:15 +08:00
parent 118984283a
commit 521ef3f579
98 changed files with 5321 additions and 4170 deletions
+159
View File
@@ -0,0 +1,159 @@
/******************************************************************************
*
* Copyright (C) 2002-2012 Broadcom Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/******************************************************************************
*
* This file contains HID protocol definitions
*
******************************************************************************/
#ifndef HIDDEFS_H
#define HIDDEFS_H
#include "sdp_api.h"
/*
** tHID_STATUS: HID result codes, returned by HID and device and host functions.
*/
enum
{
HID_SUCCESS,
HID_ERR_NOT_REGISTERED,
HID_ERR_ALREADY_REGISTERED,
HID_ERR_NO_RESOURCES,
HID_ERR_NO_CONNECTION,
HID_ERR_INVALID_PARAM,
HID_ERR_UNSUPPORTED,
HID_ERR_UNKNOWN_COMMAND,
HID_ERR_CONGESTED,
HID_ERR_CONN_IN_PROCESS,
HID_ERR_ALREADY_CONN,
HID_ERR_DISCONNECTING,
HID_ERR_SET_CONNABLE_FAIL,
/* Device specific error codes */
HID_ERR_HOST_UNKNOWN,
HID_ERR_L2CAP_FAILED,
HID_ERR_AUTH_FAILED,
HID_ERR_SDP_BUSY,
HID_ERR_GATT,
HID_ERR_INVALID = 0xFF
};
typedef UINT8 tHID_STATUS;
#define HID_L2CAP_CONN_FAIL (0x0100) /* Connection Attempt was made but failed */
#define HID_L2CAP_REQ_FAIL (0x0200) /* L2CAP_ConnectReq API failed */
#define HID_L2CAP_CFG_FAIL (0x0400) /* L2CAP Configuration was rejected by peer */
/* Define the HID transaction types
*/
#define HID_TRANS_HANDSHAKE (0)
#define HID_TRANS_CONTROL (1)
#define HID_TRANS_GET_REPORT (4)
#define HID_TRANS_SET_REPORT (5)
#define HID_TRANS_GET_PROTOCOL (6)
#define HID_TRANS_SET_PROTOCOL (7)
#define HID_TRANS_GET_IDLE (8)
#define HID_TRANS_SET_IDLE (9)
#define HID_TRANS_DATA (10)
#define HID_TRANS_DATAC (11)
#define HID_GET_TRANS_FROM_HDR(x) ((x >> 4) & 0x0f)
#define HID_GET_PARAM_FROM_HDR(x) (x & 0x0f)
#define HID_BUILD_HDR(t,p) (UINT8)((t << 4) | (p & 0x0f))
/* Parameters for Handshake
*/
#define HID_PAR_HANDSHAKE_RSP_SUCCESS (0)
#define HID_PAR_HANDSHAKE_RSP_NOT_READY (1)
#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_REP_ID (2)
#define HID_PAR_HANDSHAKE_RSP_ERR_UNSUPPORTED_REQ (3)
#define HID_PAR_HANDSHAKE_RSP_ERR_INVALID_PARAM (4)
#define HID_PAR_HANDSHAKE_RSP_ERR_UNKNOWN (14)
#define HID_PAR_HANDSHAKE_RSP_ERR_FATAL (15)
/* Parameters for Control
*/
#define HID_PAR_CONTROL_NOP (0)
#define HID_PAR_CONTROL_HARD_RESET (1)
#define HID_PAR_CONTROL_SOFT_RESET (2)
#define HID_PAR_CONTROL_SUSPEND (3)
#define HID_PAR_CONTROL_EXIT_SUSPEND (4)
#define HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG (5)
/* Different report types in get, set, data
*/
#define HID_PAR_REP_TYPE_MASK (0x03)
#define HID_PAR_REP_TYPE_OTHER (0x00)
#define HID_PAR_REP_TYPE_INPUT (0x01)
#define HID_PAR_REP_TYPE_OUTPUT (0x02)
#define HID_PAR_REP_TYPE_FEATURE (0x03)
/* Parameters for Get Report
*/
/* Buffer size in two bytes after Report ID */
#define HID_PAR_GET_REP_BUFSIZE_FOLLOWS (0x08)
/* Parameters for Protocol Type
*/
#define HID_PAR_PROTOCOL_MASK (0x01)
#define HID_PAR_PROTOCOL_REPORT (0x01)
#define HID_PAR_PROTOCOL_BOOT_MODE (0x00)
#define HID_PAR_REP_TYPE_MASK (0x03)
/* Descriptor types in the SDP record
*/
#define HID_SDP_DESCRIPTOR_REPORT (0x22)
#define HID_SDP_DESCRIPTOR_PHYSICAL (0x23)
typedef struct desc_info
{
UINT16 dl_len;
UINT8 *dsc_list;
} tHID_DEV_DSCP_INFO;
#define HID_SSR_PARAM_INVALID 0xffff
typedef struct sdp_info
{
char svc_name[HID_MAX_SVC_NAME_LEN]; /*Service Name */
char svc_descr[HID_MAX_SVC_DESCR_LEN]; /*Service Description*/
char prov_name[HID_MAX_PROV_NAME_LEN]; /*Provider Name.*/
UINT16 rel_num; /*Release Number */
UINT16 hpars_ver; /*HID Parser Version.*/
UINT16 ssr_max_latency; /* HIDSSRHostMaxLatency value, if HID_SSR_PARAM_INVALID not used*/
UINT16 ssr_min_tout; /* HIDSSRHostMinTimeout value, if HID_SSR_PARAM_INVALID not used* */
UINT8 sub_class; /*Device Subclass.*/
UINT8 ctry_code; /*Country Code.*/
UINT16 sup_timeout;/* Supervisory Timeout */
tHID_DEV_DSCP_INFO dscp_info; /* Descriptor list and Report list to be set in the SDP record.
This parameter is used if HID_DEV_USE_GLB_SDP_REC is set to FALSE.*/
tSDP_DISC_REC *p_sdp_layer_rec;
} tHID_DEV_SDP_INFO;
#endif
+236
View File
@@ -0,0 +1,236 @@
/******************************************************************************
*
* Copyright (C) 2002-2012 Broadcom Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#ifndef HIDH_API_H
#define HIDH_API_H
#include "hiddefs.h"
#include "sdp_api.h"
/*****************************************************************************
** Constants
*****************************************************************************/
enum {
HID_SDP_NO_SERV_UUID = (SDP_ILLEGAL_PARAMETER+1),
HID_SDP_MANDATORY_MISSING
};
/* Attributes mask values to be used in HID_HostAddDev API */
#define HID_VIRTUAL_CABLE 0x0001
#define HID_NORMALLY_CONNECTABLE 0x0002
#define HID_RECONN_INIT 0x0004
#define HID_SDP_DISABLE 0x0008
#define HID_BATTERY_POWER 0x0010
#define HID_REMOTE_WAKE 0x0020
#define HID_SUP_TOUT_AVLBL 0x0040
#define HID_SSR_MAX_LATENCY 0x0080
#define HID_SSR_MIN_TOUT 0x0100
#define HID_SEC_REQUIRED 0x8000
#define HID_ATTR_MASK_IGNORE 0
/*****************************************************************************
** Type Definitions
*****************************************************************************/
typedef void (tHID_HOST_SDP_CALLBACK) (UINT16 result, UINT16 attr_mask,
tHID_DEV_SDP_INFO *sdp_rec );
/* HID-HOST returns the events in the following table to the application via tHID_HOST_DEV_CALLBACK
HID_HDEV_EVT_OPEN Connected to device with Interrupt and Control Channels in OPEN state.
Data = NA
HID_HDEV_EVT_CLOSE Connection with device is closed. Data=reason code.
HID_HDEV_EVT_RETRYING Lost connection is being re-connected.
Data=Retrial number
HID_HDEV_EVT_IN_REPORT Device sent an input report Data=Report Type pdata= pointer to BT_HDR
(GKI buffer having report data.)
HID_HDEV_EVT_HANDSHAKE Device sent SET_REPORT Data=Result-code pdata=NA.
HID_HDEV_EVT_VC_UNPLUG Device sent Virtual Unplug Data=NA. pdata=NA.
*/
enum
{
HID_HDEV_EVT_OPEN,
HID_HDEV_EVT_CLOSE,
HID_HDEV_EVT_RETRYING,
HID_HDEV_EVT_INTR_DATA,
HID_HDEV_EVT_INTR_DATC,
HID_HDEV_EVT_CTRL_DATA,
HID_HDEV_EVT_CTRL_DATC,
HID_HDEV_EVT_HANDSHAKE,
HID_HDEV_EVT_VC_UNPLUG
};
typedef void (tHID_HOST_DEV_CALLBACK) (UINT8 dev_handle,
BD_ADDR addr,
UINT8 event, /* Event from HID-DEVICE. */
UINT32 data, /* Integer data corresponding to the event.*/
BT_HDR *p_buf ); /* Pointer data corresponding to the event. */
/*****************************************************************************
** External Function Declarations
*****************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/*******************************************************************************
**
** Function HID_HostGetSDPRecord
**
** Description This function reads the device SDP record.
**
** Returns tHID_STATUS
**
*******************************************************************************/
extern tHID_STATUS HID_HostGetSDPRecord (BD_ADDR addr,
tSDP_DISCOVERY_DB *p_db,
UINT32 db_len,
tHID_HOST_SDP_CALLBACK *sdp_cback );
/*******************************************************************************
**
** Function HID_HostRegister
**
** Description This function registers HID-Host with lower layers.
**
** Returns tHID_STATUS
**
*******************************************************************************/
extern tHID_STATUS HID_HostRegister (tHID_HOST_DEV_CALLBACK *dev_cback);
/*******************************************************************************
**
** Function HID_HostDeregister
**
** Description This function is called when the host is about power down.
**
** Returns tHID_STATUS
**
*******************************************************************************/
extern tHID_STATUS HID_HostDeregister(void);
/*******************************************************************************
**
** Function HID_HostAddDev
**
** Description This is called so HID-host may manage this device.
**
** Returns tHID_STATUS
**
*******************************************************************************/
extern tHID_STATUS HID_HostAddDev (BD_ADDR addr, UINT16 attr_mask,
UINT8 *handle );
/*******************************************************************************
**
** Function HID_HostRemoveDev
**
** Description This removes the device from list devices that host has to manage.
**
** Returns tHID_STATUS
**
*******************************************************************************/
extern tHID_STATUS HID_HostRemoveDev (UINT8 dev_handle );
/*******************************************************************************
**
** Function HID_HostOpenDev
**
** Description This function is called when the user wants to initiate a
** connection attempt to a device.
**
** Returns void
**
*******************************************************************************/
extern tHID_STATUS HID_HostOpenDev (UINT8 dev_handle );
/*******************************************************************************
**
** Function HID_HostWriteDev
**
** Description This function is called when the host has a report to send.
**
** Returns void
**
*******************************************************************************/
extern tHID_STATUS HID_HostWriteDev(UINT8 dev_handle, UINT8 t_type,
UINT8 param, UINT16 data,
UINT8 report_id, BT_HDR *pbuf);
/*******************************************************************************
**
** Function HID_HostCloseDev
**
** Description This function disconnects the device.
**
** Returns void
**
*******************************************************************************/
extern tHID_STATUS HID_HostCloseDev(UINT8 dev_handle );
/*******************************************************************************
** Function HID_HostInit
**
** Description This function initializes the control block and trace variable
**
** Returns void
*******************************************************************************/
extern void HID_HostInit(void);
/*******************************************************************************
** Function HID_HostSetSecurityLevel
**
** Description This function sets the security level for the devices which
** are marked by application as requiring security
**
** Returns tHID_STATUS
*******************************************************************************/
extern tHID_STATUS HID_HostSetSecurityLevel( char serv_name[], UINT8 sec_lvl );
/*******************************************************************************
**
** Function hid_known_hid_device
**
** Description This function checks if this device is of type HID Device
**
** Returns TRUE if device exists else FALSE
**
*******************************************************************************/
BOOLEAN hid_known_hid_device (BD_ADDR bd_addr);
/*******************************************************************************
**
** Function HID_HostSetTraceLevel
**
** Description This function sets the trace level for HID Host. If called with
** a value of 0xFF, it simply reads the current trace level.
**
** Returns the new (current) trace level
**
*******************************************************************************/
extern UINT8 HID_HostSetTraceLevel (UINT8 new_level);
#ifdef __cplusplus
}
#endif
#endif /* HIDH_API_H */
+248
View File
@@ -0,0 +1,248 @@
/******************************************************************************
*
* Copyright (C) 1999-2012 Broadcom Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/****************************************************************************
*
* This file contains definitions for the RFCOMM protocol
*
****************************************************************************/
#ifndef RFCDEFS_H
#define RFCDEFS_H
#define PORT_MAX_RFC_PORTS 31
/*
** If nothing is negotiated MTU should be 127
*/
#define RFCOMM_DEFAULT_MTU 127
/*
** Define used by RFCOMM TS frame types
*/
#define RFCOMM_SABME 0x2F
#define RFCOMM_UA 0x63
#define RFCOMM_DM 0x0F
#define RFCOMM_DISC 0x43
#define RFCOMM_UIH 0xEF
/*
** Defenitions for the TS control frames
*/
#define RFCOMM_CTRL_FRAME_LEN 3
#define RFCOMM_MIN_OFFSET 5 /* ctrl 2 , len 1 or 2 bytes, credit 1 byte */
#define RFCOMM_DATA_OVERHEAD (RFCOMM_MIN_OFFSET + 1) /* add 1 for checksum */
#define RFCOMM_EA 1
#define RFCOMM_EA_MASK 0x01
#define RFCOMM_CR_MASK 0x02
#define RFCOMM_SHIFT_CR 1
#define RFCOMM_SHIFT_DLCI 2
#define RFCOMM_SHIFT_DLCI2 6
#define RFCOMM_PF 0x10
#define RFCOMM_PF_MASK 0x10
#define RFCOMM_PF_OFFSET 4
#define RFCOMM_SHIFT_LENGTH1 1
#define RFCOMM_SHIFT_LENGTH2 7
#define RFCOMM_SHIFT_MX_CTRL_TYPE 2
#define RFCOMM_INITIATOR_CMD 1
#define RFCOMM_INITIATOR_RSP 0
#define RFCOMM_RESPONDER_CMD 0
#define RFCOMM_RESPONDER_RSP 1
#define RFCOMM_PARSE_CTRL_FIELD(ea, cr, dlci, p_data) \
{ \
ea = *p_data & RFCOMM_EA; \
cr = (*p_data & RFCOMM_CR_MASK) >> RFCOMM_SHIFT_CR; \
dlci = *p_data++ >> RFCOMM_SHIFT_DLCI; \
if (!ea) dlci += *p_data++ << RFCOMM_SHIFT_DLCI2; \
}
#define RFCOMM_FORMAT_CTRL_FIELD(p_data, ea, cr, dlci) \
*p_data++ = ea | cr | (dlci << RFCOMM_SHIFT_DLCI)
#define RFCOMM_PARSE_TYPE_FIELD(type, pf, p_data) \
{ \
type = *p_data & ~RFCOMM_PF_MASK; \
pf = (*p_data++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET;\
}
#define RFCOMM_FORMAT_TYPE_FIELD(p_data, type, pf) \
*p_data++ = (type | (pf << RFCOMM_PF_OFFSET)) \
{ \
type = *p_data & ~RFCOMM_PF_MASK; \
pf = (*p_data++ & RFCOMM_PF_MASK) >> RFCOMM_PF_OFFSET;\
}
#define RFCOMM_PARSE_LEN_FIELD(ea, length, p_data) \
{ \
ea = (*p_data & RFCOMM_EA); \
length = (*p_data++ >> RFCOMM_SHIFT_LENGTH1); \
if (!ea) length += (*p_data++ << RFCOMM_SHIFT_LENGTH2); \
}
#define RFCOMM_FRAME_IS_CMD(initiator, cr) \
(( (initiator) && !(cr)) || (!(initiator) && (cr)))
#define RFCOMM_FRAME_IS_RSP(initiator, cr) \
(( (initiator) && (cr)) || (!(initiator) && !(cr)))
#define RFCOMM_CR(initiator, is_command) \
(( ( (initiator) && (is_command)) \
|| (!(initiator) && !(is_command))) << 1)
#define RFCOMM_I_CR(is_command) ((is_command) ? 0x02 : 0x00)
#define RFCOMM_MAX_DLCI 61
#define RFCOMM_VALID_DLCI(dlci) \
(((dlci) == 0) || (((dlci) >= 2) && ((dlci) <= RFCOMM_MAX_DLCI)))
/* Port Negotiation (PN) */
#define RFCOMM_PN_DLCI_MASK 0x3F
#define RFCOMM_PN_FRAM_TYPE_UIH 0x00
#define RFCOMM_PN_FRAME_TYPE_MASK 0x0F
#define RFCOMM_PN_CONV_LAYER_MASK 0xF0
#define RFCOMM_PN_CONV_LAYER_TYPE_1 0
#define RFCOMM_PN_CONV_LAYER_CBFC_I 0xF0
#define RFCOMM_PN_CONV_LAYER_CBFC_R 0xE0
#define RFCOMM_PN_PRIORITY_MASK 0x3F
#define RFCOMM_PN_PRIORITY_0 0
#define RFCOMM_PN_K_MASK 0x07
#define RFCOMM_T1_DSEC 0 /* None negotiable in RFCOMM */
#define RFCOMM_N2 0 /* Number of retransmissions */
#define RFCOMM_K 0 /* Window size */
#define RFCOMM_K_MAX 7 /* Max value of K for credit based flow control */
#define RFCOMM_MSC_FC 0x02 /* Flow control*/
#define RFCOMM_MSC_RTC 0x04 /* Ready to communicate*/
#define RFCOMM_MSC_RTR 0x08 /* Ready to receive*/
#define RFCOMM_MSC_IC 0x40 /* Incomming call indicator*/
#define RFCOMM_MSC_DV 0x80 /* Data Valid*/
#define RFCOMM_MSC_SHIFT_BREAK 4
#define RFCOMM_MSC_BREAK_MASK 0xF0
#define RFCOMM_MSC_BREAK_PRESENT_MASK 0x02
#define RFCOMM_BAUD_RATE_2400 0x00
#define RFCOMM_BAUD_RATE_4800 0x01
#define RFCOMM_BAUD_RATE_7200 0x02
#define RFCOMM_BAUD_RATE_9600 0x03
#define RFCOMM_BAUD_RATE_19200 0x04
#define RFCOMM_BAUD_RATE_38400 0x05
#define RFCOMM_BAUD_RATE_57600 0x06
#define RFCOMM_BAUD_RATE_115200 0x07
#define RFCOMM_BAUD_RATE_230400 0x08
#define RFCOMM_5_BITS 0x00
#define RFCOMM_6_BITS 0x01
#define RFCOMM_7_BITS 0x02
#define RFCOMM_8_BITS 0x03
#define RFCOMM_RPN_BITS_MASK 0x03
#define RFCOMM_RPN_BITS_SHIFT 0
#define RFCOMM_ONESTOPBIT 0x00
#define RFCOMM_ONE5STOPBITS 0x01
#define RFCOMM_RPN_STOP_BITS_MASK 0x01
#define RFCOMM_RPN_STOP_BITS_SHIFT 2
#define RFCOMM_PARITY_NO 0x00
#define RFCOMM_PARITY_YES 0x01
#define RFCOMM_RPN_PARITY_MASK 0x01
#define RFCOMM_RPN_PARITY_SHIFT 3
#define RFCOMM_ODD_PARITY 0x00
#define RFCOMM_EVEN_PARITY 0x01
#define RFCOMM_MARK_PARITY 0x02
#define RFCOMM_SPACE_PARITY 0x03
#define RFCOMM_RPN_PARITY_TYPE_MASK 0x03
#define RFCOMM_RPN_PARITY_TYPE_SHIFT 4
#define RFCOMM_FC_OFF 0x00
#define RFCOMM_FC_XONXOFF_ON_INPUT 0x01
#define RFCOMM_FC_XONXOFF_ON_OUTPUT 0x02
#define RFCOMM_FC_RTR_ON_INPUT 0x04
#define RFCOMM_FC_RTR_ON_OUTPUT 0x08
#define RFCOMM_FC_RTC_ON_INPUT 0x10
#define RFCOMM_FC_RTC_ON_OUTPUT 0x20
#define RFCOMM_FC_MASK 0x3F
#define RFCOMM_RPN_PM_BIT_RATE 0x0001
#define RFCOMM_RPN_PM_DATA_BITS 0x0002
#define RFCOMM_RPN_PM_STOP_BITS 0x0004
#define RFCOMM_RPN_PM_PARITY 0x0008
#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010
#define RFCOMM_RPN_PM_XON_CHAR 0x0020
#define RFCOMM_RPN_PM_XOFF_CHAR 0x0040
#define RFCOMM_RPN_PM_XONXOFF_ON_INPUT 0x0100
#define RFCOMM_RPN_PM_XONXOFF_ON_OUTPUT 0x0200
#define RFCOMM_RPN_PM_RTR_ON_INPUT 0x0400
#define RFCOMM_RPN_PM_RTR_ON_OUTPUT 0x0800
#define RFCOMM_RPN_PM_RTC_ON_INPUT 0x1000
#define RFCOMM_RPN_PM_RTC_ON_OUTPUT 0x2000
#define RFCOMM_RPN_PM_MASK 0x3F7F
#define RFCOMM_RLS_ERROR 0x01
#define RFCOMM_RLS_OVERRUN 0x02
#define RFCOMM_RLS_PARITY 0x04
#define RFCOMM_RLS_FRAMING 0x08
/* Multiplexor channel uses DLCI 0 */
#define RFCOMM_MX_DLCI 0
/*
** Define RFCOMM Multiplexer message types
*/
#define RFCOMM_MX_PN 0x80
#define RFCOMM_MX_PN_LEN 8
#define RFCOMM_MX_CLD 0xC0
#define RFCOMM_MX_CLD_LEN 0
#define RFCOMM_MX_TEST 0x20
#define RFCOMM_MX_FCON 0xA0
#define RFCOMM_MX_FCON_LEN 0
#define RFCOMM_MX_FCOFF 0x60
#define RFCOMM_MX_FCOFF_LEN 0
#define RFCOMM_MX_MSC 0xE0
#define RFCOMM_MX_MSC_LEN_NO_BREAK 2
#define RFCOMM_MX_MSC_LEN_WITH_BREAK 3
#define RFCOMM_MX_NSC 0x10
#define RFCOMM_MX_NSC_LEN 1
#define RFCOMM_MX_RPN 0x90
#define RFCOMM_MX_RPN_REQ_LEN 1
#define RFCOMM_MX_RPN_LEN 8
#define RFCOMM_MX_RLS 0x50
#define RFCOMM_MX_RLS_LEN 2
#endif