Merge branch 'feature/btdm_bt_spp' into 'master'

component/bt: Add bt spp profile

See merge request !1593
This commit is contained in:
Jiang Jiang Jian
2018-01-09 10:44:46 +08:00
45 changed files with 7214 additions and 46 deletions

View File

@@ -498,6 +498,34 @@ void btu_stop_timer(TIMER_LIST_ENT *p_tle)
osi_alarm_cancel(alarm);
}
/*******************************************************************************
**
** Function btu_free_timer
**
** Description Stop and free a timer.
**
** Returns void
**
*******************************************************************************/
void btu_free_timer(TIMER_LIST_ENT *p_tle)
{
assert(p_tle != NULL);
if (p_tle->in_use == FALSE) {
return;
}
p_tle->in_use = FALSE;
// Get the alarm for the timer list entry.
osi_alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
if (alarm == NULL) {
LOG_WARN("%s Unable to find expected alarm in hashmap", __func__);
return;
}
osi_alarm_cancel(alarm);
hash_map_erase(btu_general_alarm_hash_map, p_tle);
}
#if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
/*******************************************************************************
**

View File

@@ -234,6 +234,7 @@ extern const BD_ADDR BT_BD_ANY;
*/
void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
void btu_stop_timer (TIMER_LIST_ENT *p_tle);
void btu_free_timer (TIMER_LIST_ENT *p_tle);
void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle);

View File

@@ -598,7 +598,7 @@ extern int PORT_WriteData (UINT16 handle, char *p_data, UINT16 max_len,
** Parameters: handle - Handle returned in the RFCOMM_CreateConnection
**
*******************************************************************************/
extern int PORT_WriteDataCO (UINT16 handle, int *p_len);
extern int PORT_WriteDataCO (UINT16 handle, int *p_len, int len, UINT8 *p_data);
/*******************************************************************************
**

View File

@@ -28,6 +28,8 @@
#include "bt_target.h"
#include "rfcdefs.h"
#include "port_api.h"
#include "fixed_queue.h"
#include "bt_defs.h"
/* Local events passed when application event is sent from the api to PORT */
/* ???*/

View File

@@ -32,7 +32,10 @@
#include "rfc_int.h"
#include "l2c_api.h"
#include "sdp_api.h"
#include "allocator.h"
#include "mutex.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
/* duration of break in 200ms units */
#define PORT_BREAK_DURATION 1
@@ -366,7 +369,7 @@ int PORT_SetDataCallback (UINT16 port_handle, tPORT_DATA_CALLBACK *p_port_cb)
{
tPORT *p_port;
RFCOMM_TRACE_API ("PORT_SetDataCallback() handle:%d cb 0x%x", port_handle, p_port_cb);
// RFCOMM_TRACE_API ("PORT_SetDataCallback() handle:%d cb 0x%x", port_handle, p_port_cb);
/* Check if handle is valid to avoid crashing */
if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) {
@@ -400,7 +403,7 @@ int PORT_SetDataCOCallback (UINT16 port_handle, tPORT_DATA_CO_CALLBACK *p_port_c
{
tPORT *p_port;
RFCOMM_TRACE_API ("PORT_SetDataCOCallback() handle:%d cb 0x%x", port_handle, p_port_cb);
// RFCOMM_TRACE_API ("PORT_SetDataCOCallback() handle:%d cb 0x%x", port_handle, p_port_cb);
/* Check if handle is valid to avoid crashing */
if ((port_handle == 0) || (port_handle > MAX_RFC_PORTS)) {
@@ -1173,8 +1176,7 @@ int PORT_ReadData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
return (PORT_LINE_ERR);
}
if (fixed_queue_is_empty(p_port->rx.queue))
if (!p_buf) {
if (fixed_queue_is_empty(p_port->rx.queue)){
return (PORT_SUCCESS);
}
@@ -1317,7 +1319,7 @@ static int port_write (tPORT *p_port, BT_HDR *p_buf)
|| ((p_port->port_ctrl & (PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED)) !=
(PORT_CTRL_REQ_SENT | PORT_CTRL_IND_RECEIVED))) {
if ((p_port->tx.queue_size > PORT_TX_CRITICAL_WM)
|| (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_CRITICAL_WM))
|| (fixed_queue_length(p_port->tx.queue) > PORT_TX_BUF_CRITICAL_WM)){
RFCOMM_TRACE_WARNING ("PORT_Write: Queue size: %d",
p_port->tx.queue_size);
@@ -1421,7 +1423,7 @@ int PORT_Write (UINT16 handle, BT_HDR *p_buf)
** p_len - Byte count returned
**
*******************************************************************************/
int PORT_WriteDataCO (UINT16 handle, int *p_len)
int PORT_WriteDataCO (UINT16 handle, int *p_len, int len, UINT8 *p_data)
{
tPORT *p_port;
@@ -1449,12 +1451,7 @@ int PORT_WriteDataCO (UINT16 handle, int *p_len)
return (PORT_UNKNOWN_ERROR);
}
int available = 0;
//if(ioctl(fd, FIONREAD, &available) < 0)
if (p_port->p_data_co_callback(handle, (UINT8 *)&available, sizeof(available),
DATA_CO_CALLBACK_TYPE_OUTGOING_SIZE) == FALSE) {
RFCOMM_TRACE_ERROR("p_data_co_callback DATA_CO_CALLBACK_TYPE_INCOMING_SIZE failed, available:%d", available);
return (PORT_UNKNOWN_ERROR);
}
available = len;
if (available == 0) {
return PORT_SUCCESS;
}
@@ -1469,16 +1466,7 @@ int PORT_WriteDataCO (UINT16 handle, int *p_len)
if (((p_buf = (BT_HDR *)fixed_queue_try_peek_last(p_port->tx.queue)) != NULL)
&& (((int)p_buf->len + available) <= (int)p_port->peer_mtu)
&& (((int)p_buf->len + available) <= (int)length)) {
//if(recv(fd, (UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len, available, 0) != available)
if (p_port->p_data_co_callback(handle, (UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len,
available, DATA_CO_CALLBACK_TYPE_OUTGOING) == FALSE)
{
RFCOMM_TRACE_ERROR("p_data_co_callback DATA_CO_CALLBACK_TYPE_OUTGOING failed, available:%d", available);
osi_mutex_global_unlock();
return (PORT_UNKNOWN_ERROR);
}
//memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len);
memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, available);
p_port->tx.queue_size += (UINT16)available;
*p_len = available;
@@ -1524,14 +1512,7 @@ int PORT_WriteDataCO (UINT16 handle, int *p_len)
p_buf->len = length;
p_buf->event = BT_EVT_TO_BTU_SP_DATA;
//memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset, p_data, length);
//if(recv(fd, (UINT8 *)(p_buf + 1) + p_buf->offset, (int)length, 0) != (int)length)
if (p_port->p_data_co_callback(handle, (UINT8 *)(p_buf + 1) + p_buf->offset, length,
DATA_CO_CALLBACK_TYPE_OUTGOING) == FALSE) {
RFCOMM_TRACE_ERROR("p_data_co_callback DATA_CO_CALLBACK_TYPE_OUTGOING failed, length:%d", length);
return (PORT_UNKNOWN_ERROR);
}
memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset, p_data, length);
RFCOMM_TRACE_EVENT ("PORT_WriteData %d bytes", length);
@@ -1610,14 +1591,14 @@ int PORT_WriteData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
}
/* Length for each buffer is the smaller of GKI buffer, peer MTU, or max_len */
length = RFCOMM_DATA_POOL_BUF_SIZE -
length = RFCOMM_DATA_BUF_SIZE -
(UINT16)(sizeof(BT_HDR) + L2CAP_MIN_OFFSET + RFCOMM_DATA_OVERHEAD);
/* If there are buffers scheduled for transmission check if requested */
/* data fits into the end of the queue */
osi_mutex_global_lock();
if (((p_buf = (BT_HDR *)fixed_queue_try_peek_last(p_port->tx.queue)) != NULL) {
if (((p_buf = (BT_HDR *)fixed_queue_try_peek_last(p_port->tx.queue)) != NULL)
&& ((p_buf->len + max_len) <= p_port->peer_mtu)
&& ((p_buf->len + max_len) <= length)) {
memcpy ((UINT8 *)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len);
@@ -1800,3 +1781,5 @@ const char *PORT_GetResultString (const uint8_t result_code)
return result_code_strings[result_code];
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -32,7 +32,9 @@
#include "port_int.h"
#include "rfc_int.h"
#include "bt_defs.h"
#include "mutex.h"
#include "allocator.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
/*
** Local function definitions
*/
@@ -1090,3 +1092,6 @@ void port_get_credits (tPORT *p_port, UINT8 k)
p_port->tx.peer_fc = TRUE;
}
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -31,6 +31,9 @@
#include "l2cdefs.h"
#include "btm_int.h"
#include "btu.h"
#include "mutex.h"
#include "allocator.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
static const tPORT_STATE default_port_pars = {
PORT_BAUD_RATE_9600,
@@ -564,3 +567,5 @@ void port_flow_control_peer(tPORT *p_port, BOOLEAN enable, UINT16 count)
}
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -32,8 +32,10 @@
#include "l2cdefs.h"
#include "rfc_int.h"
#include "bt_defs.h"
#include "allocator.h"
#include "mutex.h"
#include "alarm.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
/*
** Define Callback functions to be called by L2CAP
*/
@@ -413,3 +415,5 @@ void rfc_save_lcid_mcb (tRFC_MCB *p_mcb, UINT16 lcid)
{
rfc_cb.rfc.p_rfc_lcid_mcb[lcid - L2CAP_BASE_APPL_CID] = p_mcb;
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -31,6 +31,10 @@
#include "l2c_api.h"
#include "rfc_int.h"
#include "bt_defs.h"
#include "allocator.h"
#include "mutex.h"
#include "bt_target.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
#define L2CAP_SUCCESS 0
#define L2CAP_ERROR 1
@@ -572,7 +576,7 @@ static void rfc_mx_send_config_req (tRFC_MCB *p_mcb)
*******************************************************************************/
static void rfc_mx_conf_cnf (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg)
{
RFCOMM_TRACE_EVENT ("rfc_mx_conf_cnf p_cfg:%08x res:%d ", p_cfg, (p_cfg) ? p_cfg->result : 0);
// RFCOMM_TRACE_EVENT ("rfc_mx_conf_cnf p_cfg:%08x res:%d ", p_cfg, (p_cfg) ? p_cfg->result : 0);
if (p_cfg->result != L2CAP_CFG_OK) {
if (p_mcb->is_initiator) {
@@ -639,3 +643,5 @@ static void rfc_mx_conf_ind (tRFC_MCB *p_mcb, tL2CAP_CFG_INFO *p_cfg)
}
}
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -31,6 +31,9 @@
#include "port_int.h"
#include "rfc_int.h"
#include "bt_defs.h"
#include "allocator.h"
#include "mutex.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
/********************************************************************************/
/* L O C A L F U N C T I O N P R O T O T Y P E S */
@@ -895,3 +898,4 @@ void rfc_set_port_state(tPORT_STATE *port_pars, MX_FRAME *p_frame)
}
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -32,6 +32,8 @@
#include "rfc_int.h"
#include "bt_defs.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
#if RFC_DYNAMIC_MEMORY == FALSE
tRFC_CB rfc_cb;
#endif
@@ -372,3 +374,4 @@ void RFCOMM_DataReq (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf)
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -29,6 +29,9 @@
#include "l2c_api.h"
#include "port_int.h"
#include "rfc_int.h"
#include "mutex.h"
#include "allocator.h"
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
/*******************************************************************************
**
@@ -895,3 +898,4 @@ void rfc_process_mx_message (tRFC_MCB *p_mcb, BT_HDR *p_buf)
}
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)

View File

@@ -34,8 +34,12 @@
#include "btu.h"
#include "bt_defs.h"
#include "allocator.h"
#include "mutex.h"
#include <string.h>
#if (defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)
/*******************************************************************************
**
** Function rfc_calc_fcs
@@ -183,7 +187,9 @@ tRFC_MCB *rfc_alloc_multiplexer_channel (BD_ADDR bd_addr, BOOLEAN is_initiator)
return (NULL);
}
void osi_free_fun(void *p){
osi_free(p);
}
/*******************************************************************************
**
** Function rfc_release_multiplexer_channel
@@ -197,8 +203,7 @@ void rfc_release_multiplexer_channel (tRFC_MCB *p_mcb)
rfc_timer_stop (p_mcb);
fixed_queue_free(p_mcb->cmd_q, osi_free);
fixed_queue_free(p_mcb->cmd_q, osi_free_fun);
memset (p_mcb, 0, sizeof (tRFC_MCB));
p_mcb->state = RFC_MX_STATE_IDLE;
@@ -269,7 +274,7 @@ void rfc_port_timer_stop (tPORT *p_port)
{
RFCOMM_TRACE_EVENT ("rfc_port_timer_stop");
btu_stop_timer (&p_port->rfc.tle);
btu_free_timer (&p_port->rfc.tle);
}
@@ -475,3 +480,4 @@ void rfc_check_send_cmd(tRFC_MCB *p_mcb, BT_HDR *p_buf)
}
#endif ///(defined RFCOMM_INCLUDED && RFCOMM_INCLUDED == TRUE)