upload android base code part4

This commit is contained in:
August 2018-08-08 17:00:29 +08:00
parent b9e30e05b1
commit 78ea2404cd
23455 changed files with 5250148 additions and 0 deletions

View file

@ -0,0 +1,168 @@
/******************************************************************************
*
* Copyright (C) 2016 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Module Name:
* bt_list.h
*
* Abstract:
* To implement list data structure
*
* Major Change History:
* When Who What
* --------------------------------------------------------------
* 2010-06-04 W.Bi Created
*
* Notes:
*
******************************************************************************/
#ifndef BT_LIST_H
#define BT_LIST_H
/**
\file bt_list.h
\brief Implement bluetooth list data structure. Has referred to Linux list implementation
You could add your new list manipulation here.
*/
/**
List entry structure, could be header or node.
Prev<-----Header---->Next
Every List has an additional header, and list tail will be list header's previous node.
You can use list to form a queue or a stack data structure
queue:
ListAddToTail----->LIST_FOR_EACH iterate--->manipulate on the list entry
Stack:
ListAddToHead--- >LIST_FOR_EACH iterate--->manipulate on the list entry
*/
///RT list structure definition
typedef struct _RT_LIST_ENTRY {
struct _RT_LIST_ENTRY *Next; ///< Entry's next element
struct _RT_LIST_ENTRY *Prev; ///< Entry's previous element
} RT_LIST_ENTRY, *PRT_LIST_ENTRY;
///List head would be another name of list entry, and it points to the list header
typedef RT_LIST_ENTRY RT_LIST_HEAD, *PRT_LIST_HEAD;
/*----------------------------------------------------------------------------------
EXTERNAL FUNCTION
----------------------------------------------------------------------------------*/
///Initialize a list with its header
void ListInitializeHeader(PRT_LIST_HEAD ListHead);
/**
Add a new entry to the list.
Insert a new entry after the specified head. This is good for implementing stacks.
\param [IN] ListNew <RT_LIST_ENTRY> : new entry to be added
\param [IN OUT] ListHead <RT_LIST_ENTRY> : List header after which to add new entry
*/
void ListAddToHead(PRT_LIST_ENTRY ListNew, PRT_LIST_HEAD ListHead);
/**
Add a new entry to the list.
Insert a new entry before the specified head. This is good for implementing queues.
\param [IN] ListNew <RT_LIST_ENTRY> : new entry to be added
\param [IN OUT] ListHead <RT_LIST_ENTRY> : List header before which to add new entry
*/
void ListAddToTail(PRT_LIST_ENTRY ListNew, PRT_LIST_HEAD ListHead);
/**
Get entry in the head of the list
\param [IN ] ListHead <RT_LIST_ENTRY> : List header
\return entry in the head , otherwise NULL
*/
RT_LIST_ENTRY* ListGetTop(PRT_LIST_HEAD ListHead);
/**
Get entry in the tail of the list
\param [IN ] ListHead <RT_LIST_ENTRY> : List header
\return entry in the tail , otherwise NULL
*/
RT_LIST_ENTRY*
ListGetTail(
PRT_LIST_HEAD ListHead
);
/**
Delete entry from the list
Note: ListIsEmpty() on this list entry would not return true, since its state is undefined
\param [IN] ListToDelete <RT_LIST_ENTRY> : list entry to be deleted
*/
void ListDeleteNode(PRT_LIST_ENTRY ListToDelete);
/**
Tell whether the list is empty
\param [IN] ListHead <RT_LIST_ENTRY> : List header of which to be test
*/
unsigned char ListIsEmpty(PRT_LIST_HEAD ListHead);
//EXTERN void ListEmpty(PRT_LIST_HEAD ListHead);
void
ListAdd(
PRT_LIST_ENTRY New,
PRT_LIST_ENTRY Prev,
PRT_LIST_ENTRY Next
);
/*----------------------------------------------------------------------------------
MACRO
----------------------------------------------------------------------------------*/
/**
Macros to iterate over the list.
\param _Iter : struct PRT_LIST_ENTRY type iterator to use as a loop cursor
\param _ListHead : List head of which to be iterated
*/
#define LIST_FOR_EACH(_Iter, _ListHead) \
for ((_Iter) = (_ListHead)->Next; (_Iter) != (_ListHead); (_Iter) = (_Iter)->Next)
/**
Macros to iterate over the list safely against removal of list entry.
If you would delete any list entry from the list while iterating the list, should use this macro
\param _Iter : Struct PRT_LIST_ENTRY type iterator to use as a loop cursor
\param _Temp : Another Struct PRT_LIST_ENTRY type to use as a temporary storage
\param _ListHead : List head of which to be iterated
*/
#define LIST_FOR_EACH_SAFELY(_Iter, _Temp, _ListHead) \
for ((_Iter) = (_ListHead)->Next, (_Temp) = (_Iter)->Next; (_Iter) != (_ListHead); \
(_Iter) = (_Temp), (_Temp) = (_Iter)->Next)
/**
Macros to get the struct pointer of this list entry
You could make every RT_LIST_ENTRY at the first place of your structure to avoid the macro, which will be dangerouse.
Copy from winnt.h.
BUG:if offset of field in type larger than 32 bit interger, which is not likely to happen, it will error
\param _Ptr : Struct RT_LIST_ENTRY type pointer
\param _Type : The type of structure in which the RT_LIST_ENTRY embedded in
\param _Field : the name of the RT_LIST_ENTRY within the struct
*/
#define LIST_ENTRY(_Ptr, _Type, _Field) ((_Type *)((char *)(_Ptr)-(unsigned long)(&((_Type *)0)->_Field)))
#endif /*BT_LIST_H*/

View file

@ -0,0 +1,362 @@
/******************************************************************************
*
* Copyright (C) 2016 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Module Name:
* bt_skbuff.h
*
* Abstract:
* Data buffer managerment through whole bluetooth stack.
*
* Major Change History:
* When Who What
* --------------------------------------------------------------
* 2010-06-11 W.Bi Created.
*
* Notes:
* To reduce memory copy when pass data buffer to other layers,
* RTK_BUFFER is designed referring to linux socket buffer.
* But I still wonder its effect, since RTK_BUFFER is much bigger
* than original data buffer.RTK_BUFFER will reduce its member if
* it would not reach what i had expected.
*
******************************************************************************/
#ifndef BT_SKBUFF_H
#define BT_SKBUFF_H
#include "bt_list.h"
#include <stdbool.h>
#ifndef EXTERN
#define EXTERN
#endif
#ifndef IN
#define IN
#endif
#ifndef OUT
#define OUT
#endif
/*----------------------------------------------------------------------------------
CONSTANT DEFINITION
----------------------------------------------------------------------------------*/
#define RTK_CONTEXT_SIZE 12
#define RTB_QUEUE_ID_LENGTH 64
/*----------------------------------------------------------------------------------
STRUCTURE DEFINITION
----------------------------------------------------------------------------------*/
/**
Rtk buffer definition
Head -->|<---Data--->|<-----Length------>| <---End
_________________________________
|_____________|___________________|
|<-headroom->|<--RealDataBuffer-->|
Compared to socket buffer, there exists no tail and end pointer and tailroom as tail is rarely used in bluetooth stack
\param List : List structure used to list same type rtk buffer and manipulate rtk buffer like list.
\param Head : Pointer to truely allocated data buffer. It point to the headroom
\param Data : Pointer to real data buffer.
\param Length : currently data length
\param HeadRoom : Record initialize headroom size.
\param RefCount : Reference count. zero means able to be freed, otherwise somebody is handling it.
\param Priv : Reserved for multi-device support. Record Hci pointer which will handles this packet
\param Contest : Control buffer, put private variables here.
*/
typedef struct _RTK_BUFFER
{
RT_LIST_ENTRY List;
uint8_t *Head;
uint8_t *Data;
uint8_t *Tail;
uint8_t *End;
uint32_t Length;
uint32_t HeadRoom;
// RT_U16 TailRoom;
signed char RefCount;
void* Priv;
uint8_t Context[RTK_CONTEXT_SIZE];
}RTK_BUFFER, *PRTK_BUFFER;
/**
RTK_BUFFER Control Buffer Context
\param PacketType : HCI data types, Command/Acl/...
\param LastFrag : Is Current Acl buffer the last fragment.(0 for no, 1 for yes)
\param TxSeq : Current packet tx sequence
\param Retries : Current packet retransmission times
\param Sar : L2cap control field segmentation and reassembly bits
*/
struct BT_RTB_CONTEXT{
uint8_t PacketType;
uint16_t Handle;
};
///definition to get rtk_buffer's control buffer context pointer
#define BT_CONTEXT(_Rtb) ((struct BT_RTB_CONTEXT *)((_Rtb)->Context))
/**
Since RTBs are always used into/from list, so abstract this struct and provide APIs to easy process on RTBs
*/
typedef struct _RTB_QUEUE_HEAD RTB_QUEUE_HEAD;
/*----------------------------------------------------------------------------------
EXTERNAL FUNCTION
----------------------------------------------------------------------------------*/
/**
Allocate a RTK_BUFFER with specified data length and reserved headroom.
If caller does not know actual headroom to reserve for further usage, specify it to zero to use default value.
\param [IN] Length <uint32_t> : current data buffer length to allcated
\param [IN] HeadRoom <uint32_t> : if caller knows reserved head space, set it; otherwise set 0 to use default value
\return pointer to RTK_BUFFER if succeed, null otherwise
*/
RTK_BUFFER*
RtbAllocate(
IN uint32_t Length,
IN uint32_t HeadRoom
);
/**
Free specified Rtk_buffer
\param [IN] RtkBuffer <RTK_BUFFER*> : buffer to free
*/
void
RtbFree(
IN RTK_BUFFER* RtkBuffer
);
/**
increament reference count
*/
void
RtbIncreaseRefCount(
IN RTK_BUFFER* RtkBuffer
);
/**
Recycle a rtk_buffer after its usage if specified rtb could
if rtb total length is not smaller than specified rtbsize to be recycled for, it will succeeded recycling
\param [IN OUT] RtkBuffer <RTK_BUFFER*> : buffer to recycle
\param [IN] RtbSize <uint32_t> : size of buffer to be recycled for
*/
/*
BOOLEAN
RtbCheckRecycle(
IN OUT RTK_BUFFER* RtkBuffer,
IN uint32_t RtbSize
);
*/
/**
Add a specified length protocal header to the start of data buffer hold by specified rtk_buffer.
This function extends used data area of the buffer at the buffer start.
\param [IN OUT] RtkBuffer <RTK_BUFFER*> : data buffer to add
\param [IN] Length <uint32_t> : header length
\return Pointer to the first byte of the extra data is returned
*/
uint8_t*
RtbAddHead(
IN OUT RTK_BUFFER* RtkBuffer,
IN uint32_t Length
);
/**
Remove a specified length data from the start of data buffer hold by specified rtk_buffer.
This function returns the memory to the headroom.
\param [IN OUT] RtkBuffer <RTK_BUFFER*> : data buffer to remove
\param [IN] Length <uint32_t> : header length
\return Pointer to the next data in the buffer is returned, usually useless
*/
unsigned char
RtbRemoveHead(
IN OUT RTK_BUFFER* RtkBuffer,
IN uint32_t Length
);
/**
Add a specified length protocal header to the end of data buffer hold by specified rtk_buffer.
This function extends used data area of the buffer at the buffer end.
\param [IN OUT] RtkBuffer <RTK_BUFFER*> : data buffer to add
\param [IN] Length <uint32_t> : header length
\return Pointer to the first byte of the extra data is returned
*/
EXTERN uint8_t*
RtbAddTail(
IN OUT RTK_BUFFER* RtkBuffer,
IN uint32_t Length
);
/**
Remove a specified length data from the end of data buffer hold by specified rtk_buffer.
*/
EXTERN unsigned char
RtbRemoveTail(
IN OUT RTK_BUFFER * RtkBuffer,
IN uint32_t Length
);
/**
Initialize a rtb queue.
\return Initilized rtb queue if succeed, otherwise NULL
*/
EXTERN RTB_QUEUE_HEAD*
RtbQueueInit(
);
/**
Free a rtb queue.
\param [IN] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
*/
EXTERN void
RtbQueueFree(
RTB_QUEUE_HEAD* RtkQueueHead
);
/**
Queue specified RtkBuffer into a RtkQueue at list tail.
\param [IN OUT] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
\param [IN] RtkBuffer <RTK_BUFFER*> : Rtk buffer to add
*/
EXTERN void
RtbQueueTail(
IN OUT RTB_QUEUE_HEAD* RtkQueueHead,
IN RTK_BUFFER* RtkBuffer
);
/**
Queue specified RtkBuffer into a RtkQueue at list Head.
\param [IN OUT] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
\param [IN] RtkBuffer <RTK_BUFFER*> : Rtk buffer to add
*/
EXTERN void
RtbQueueHead(
IN OUT RTB_QUEUE_HEAD* RtkQueueHead,
IN RTK_BUFFER* RtkBuffer
);
/**
Remove a RtkBuffer from specified rtkqueue at list tail.
\param [IN OUT] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
\return removed rtkbuffer if succeed, otherwise NULL
*/
EXTERN RTK_BUFFER*
RtbDequeueTail(
IN OUT RTB_QUEUE_HEAD* RtkQueueHead
);
/**
Remove a RtkBuffer from specified rtkqueue at list head.
\param [IN OUT] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
\return removed rtkbuffer if succeed, otherwise NULL
*/
EXTERN RTK_BUFFER*
RtbDequeueHead(
IN OUT RTB_QUEUE_HEAD* RtkQueueHead
);
/**
Get current rtb queue's length.
\param [IN] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
\return current queue's length
*/
EXTERN signed long
RtbGetQueueLen(
IN RTB_QUEUE_HEAD* RtkQueueHead
);
/**
Empty the rtkqueue.
\param [IN OUT] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
*/
EXTERN void
RtbEmptyQueue(
IN OUT RTB_QUEUE_HEAD* RtkQueueHead
);
/**
Get the RtkBuffer which is the head of a RtkQueue
\param [IN OUT] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
\return head of the RtkQueue , otherwise NULL
*/
EXTERN RTK_BUFFER*
RtbTopQueue(
IN RTB_QUEUE_HEAD* RtkQueueHead
);
/**
Insert new Rtkbuffer in the old buffer
\param [IN OUT] RtkQueueHead <RTB_QUEUE_HEAD*> : Rtk Queue
\param [IN] OldRtkBuffer <RTK_BUFFER*> : old rtk buffer
\param [IN] NewRtkBuffer <RTK_BUFFER*> : Rtk buffer to add
*/
EXTERN void
RtbInsertBefore(
IN OUT RTB_QUEUE_HEAD* RtkQueueHead,
IN RTK_BUFFER* pOldRtkBuffer,
IN RTK_BUFFER* pNewRtkBuffer
);
/**
check whether the buffer is the last node in the queue
*/
EXTERN unsigned char
RtbNodeIsLast(
IN RTB_QUEUE_HEAD* RtkQueueHead,
IN RTK_BUFFER* pRtkBuffer
);
/**
get the next buffer node after the specified buffer in the queue
if the specified buffer is the last node in the queue , return NULL
\param [IN] RtkBuffer <RTK_BUFFER*> : Rtk Queue
\param [IN] RtkBuffer <RTK_BUFFER*> : Rtk buffer
\return node after the specified buffer
*/
EXTERN RTK_BUFFER*
RtbQueueNextNode(
IN RTB_QUEUE_HEAD* RtkQueueHead,
IN RTK_BUFFER* pRtkBuffer
);
/**
check whether queue is empty
*/
EXTERN bool
RtbQueueIsEmpty(
IN RTB_QUEUE_HEAD* RtkQueueHead
);
//annie_tmp
EXTERN unsigned char
RtbCheckQueueLen(
IN RTB_QUEUE_HEAD* RtkQueueHead,
IN uint8_t Len
);
EXTERN void
RtbRemoveNode(
IN OUT RTB_QUEUE_HEAD* RtkQueueHead,
IN RTK_BUFFER* RtkBuffer
);
EXTERN RTK_BUFFER*
RtbCloneBuffer(
IN RTK_BUFFER* pDataBuffer
);
#endif /*BT_SKBUFF_H*/

View file

@ -0,0 +1,245 @@
/******************************************************************************
*
* Copyright (C) 2009-2012 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Filename: bt_vendor_rtk.h
*
* Description: A wrapper header file of bt_vendor_lib.h
*
* Contains definitions specific for interfacing with Realtek
* Bluetooth chipsets
*
******************************************************************************/
#ifndef BT_VENDOR_RTK_H
#define BT_VENDOR_RTK_H
#include "bt_vendor_lib.h"
#include "vnd_buildcfg.h"
#include "rtk_btsnoop_net.h"
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include <ctype.h>
#include <cutils/properties.h>
/******************************************************************************
** Constants & Macros
******************************************************************************/
#define RTKBT_TRANS_H4 0x20
#define RTKBT_TRANS_H5 0x10
#define RTKBT_TRANS_UART 0x01
#define RTKBT_TRANS_USB 0x20
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
#ifndef BTVND_DBG
#define BTVND_DBG TRUE
#endif
#if (BTVND_DBG == TRUE)
#define BTVNDDBG(param, ...) {ALOGD(param, ## __VA_ARGS__);}
#else
#define BTVNDDBG(param, ...) {}
#endif
#define DOWN_FW_CFG _IOW('H', 201, int)
#define SET_ISO_CFG _IOW('H', 202, int)
/* Device port name where Bluetooth controller attached */
#ifndef BLUETOOTH_UART_DEVICE_PORT
#define BLUETOOTH_UART_DEVICE_PORT "/dev/ttyO1" /* maguro */
#endif
/* Location of firmware patch files */
#ifndef FW_PATCHFILE_LOCATION
#define FW_PATCHFILE_LOCATION "/vendor/firmware/" /* maguro */
#endif
#ifndef UART_TARGET_BAUD_RATE
#define UART_TARGET_BAUD_RATE 3000000
#endif
/* The Bluetooth Device Aaddress source switch:
*
* -FALSE- (default value)
* Get the factory BDADDR from device's file system. Normally the BDADDR is
* stored in the location pointed by the PROPERTY_BT_BDADDR_PATH (defined in
* btif_common.h file) property.
*
* -TRUE-
* If the Bluetooth Controller has equipped with a non-volatile memory (such
* as BCM4330's OTP memory), the factory BDADDR can be stored in there and
* retrieved by the stack while enabling BT.
* !!! WARNING !!! Make sure that the OTP feature has been enabled in the
* firmware patchram (.hcd) file.
*/
#ifndef USE_CONTROLLER_BDADDR
#define USE_CONTROLLER_BDADDR TRUE //FALSE
#endif
/* sleep mode
0: disable
1: UART with Host wake/BT wake out of band signals
*/
#ifndef LPM_SLEEP_MODE
#define LPM_SLEEP_MODE 1
#endif
/* Host Stack Idle Threshold in 300ms or 25ms
In sleep mode 1, this is the number of firmware loops executed with no
activity before the Host wake line is deasserted. Activity includes HCI
traffic excluding certain sleep mode commands and the presence of SCO
connections if the "Allow Host Sleep During SCO" flag is not set to 1.
Each count of this parameter is roughly equivalent to 300ms or 25ms.
*/
#ifndef LPM_IDLE_THRESHOLD
#define LPM_IDLE_THRESHOLD 1
#endif
/* Host Controller Idle Threshold in 300ms or 25ms
This is the number of firmware loops executed with no activity before the
HC is considered idle. Depending on the mode, HC may then attempt to sleep.
Activity includes HCI traffic excluding certain sleep mode commands and
the presence of ACL/SCO connections.
*/
#ifndef LPM_HC_IDLE_THRESHOLD
#define LPM_HC_IDLE_THRESHOLD 1
#endif
/* BT_WAKE Polarity - 0=Active Low, 1= Active High */
#ifndef LPM_BT_WAKE_POLARITY
#define LPM_BT_WAKE_POLARITY 1 /* maguro */
#endif
/* HOST_WAKE Polarity - 0=Active Low, 1= Active High */
#ifndef LPM_HOST_WAKE_POLARITY
#define LPM_HOST_WAKE_POLARITY 1 /* maguro */
#endif
/* LPM_ALLOW_HOST_SLEEP_DURING_SCO
When this flag is set to 0, the host is not allowed to sleep while
an SCO is active. In sleep mode 1, the device will keep the host
wake line asserted while an SCO is active.
When this flag is set to 1, the host can sleep while an SCO is active.
This flag should only be set to 1 if SCO traffic is directed to the PCM
interface.
*/
#ifndef LPM_ALLOW_HOST_SLEEP_DURING_SCO
#define LPM_ALLOW_HOST_SLEEP_DURING_SCO 1
#endif
/* LPM_COMBINE_SLEEP_MODE_AND_LPM
In Mode 0, always set byte 7 to 0. In sleep mode 1, device always
requires permission to sleep between scans / periodic inquiries regardless
of the setting of this byte. In sleep mode 1, if byte is set, device must
have "permission" to sleep during the low power modes of sniff, hold, and
park. If byte is not set, device can sleep without permission during these
modes. Permission to sleep in Mode 1 is obtained if the BT_WAKE signal is
not asserted.
*/
#ifndef LPM_COMBINE_SLEEP_MODE_AND_LPM
#define LPM_COMBINE_SLEEP_MODE_AND_LPM 1
#endif
/* LPM_ENABLE_UART_TXD_TRI_STATE
When set to 0, the device will not tristate its UART TX line before going
to sleep.
When set to 1, the device will tristate its UART TX line before going to
sleep.
*/
#ifndef LPM_ENABLE_UART_TXD_TRI_STATE
#define LPM_ENABLE_UART_TXD_TRI_STATE 0
#endif
/* LPM_PULSED_HOST_WAKE
*/
#ifndef LPM_PULSED_HOST_WAKE
#define LPM_PULSED_HOST_WAKE 0
#endif
/* LPM_IDLE_TIMEOUT_MULTIPLE
The multiple factor of host stack idle threshold in 300ms/25ms
*/
#ifndef LPM_IDLE_TIMEOUT_MULTIPLE
#define LPM_IDLE_TIMEOUT_MULTIPLE 10
#endif
/* BT_WAKE_VIA_USERIAL_IOCTL
Use userial ioctl function to control BT_WAKE signal
*/
#ifndef BT_WAKE_VIA_USERIAL_IOCTL
#define BT_WAKE_VIA_USERIAL_IOCTL FALSE
#endif
/* BT_WAKE_VIA_PROC
LPM & BT_WAKE control through PROC nodes
*/
#ifndef BT_WAKE_VIA_PROC
#define BT_WAKE_VIA_PROC FALSE
#endif
/* HW_END_WITH_HCI_RESET
Sample code implementation of sending a HCI_RESET command during the epilog
process. It calls back to the callers after command complete of HCI_RESET
is received.
*/
#ifndef HW_END_WITH_HCI_RESET
#define HW_END_WITH_HCI_RESET FALSE
#endif
/******************************************************************************
** Extern variables and functions
******************************************************************************/
extern bt_vendor_callbacks_t *bt_vendor_cbacks;
#endif /* BT_VENDOR_RTK_H */

View file

@ -0,0 +1,82 @@
/******************************************************************************
*
* Copyright (C) 2014 Google, Inc.
*
* 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 RTK_HCI_H5_INT_H
#define RTK_HCI_H5_INT_H
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "bt_hci_bdroid.h"
#include "bt_vendor_lib.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "rtk_hcidefs.h"
//HCI Command opcodes
#define HCI_LE_READ_BUFFER_SIZE 0x2002
#define DATA_TYPE_H5 0x05
//HCI VENDOR Command opcode
#define HCI_VSC_H5_INIT 0xFCEE
#define HCI_VSC_UPDATE_BAUDRATE 0xFC17
#define HCI_VSC_DOWNLOAD_FW_PATCH 0xFC20
#define HCI_VSC_READ_ROM_VERSION 0xFC6D
#define HCI_VSC_READ_CHIP_TYPE 0xFC61
#define HCI_VSC_SET_WAKE_UP_DEVICE 0xFC7B
#define HCI_VSC_BT_OFF 0xFC28
#define HCI_READ_LMP_VERSION 0x1001
#define STREAM_TO_UINT16(u16, p) {u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); (p) += 2;}
#define UINT16_TO_STREAM(p, u16) {*(p)++ = (uint8_t)(u16); *(p)++ = (uint8_t)((u16) >> 8);}
#define UINT32_TO_STREAM(p, u32) {*(p)++ = (uint8_t)(u32); *(p)++ = (uint8_t)((u32) >> 8); *(p)++ = (uint8_t)((u32) >> 16); *(p)++ = (uint8_t)((u32) >> 24);}
#define STREAM_TO_UINT32(u32, p) {u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24)); (p) += 4;}
#define UINT8_TO_STREAM(p, u8) {*(p)++ = (uint8_t)(u8);}
void ms_delay (uint32_t timeout);
typedef enum {
DATA_TYPE_COMMAND = 1,
DATA_TYPE_ACL = 2,
DATA_TYPE_SCO = 3,
DATA_TYPE_EVENT = 4
} serial_data_type_t;
typedef struct hci_h5_callbacks_t{
uint16_t (*h5_int_transmit_data_cb)(serial_data_type_t type, uint8_t *data, uint16_t length);
void (*h5_data_ready_cb)(serial_data_type_t type, unsigned int total_length);
} hci_h5_callbacks_t;
typedef struct hci_h5_t {
void (*h5_int_init)(hci_h5_callbacks_t *h5_callbacks);
void (*h5_int_cleanup)(void);
uint16_t (*h5_send_cmd)(serial_data_type_t type, uint8_t *data, uint16_t length);
uint8_t (*h5_send_sync_cmd)(uint16_t opcode, uint8_t *data, uint16_t length);
uint16_t (*h5_send_acl_data)(serial_data_type_t type, uint8_t *data, uint16_t length);
uint16_t (*h5_send_sco_data)(serial_data_type_t type, uint8_t *data, uint16_t length);
bool (*h5_recv_msg)(uint8_t *byte, uint16_t length);
size_t (*h5_int_read_data)(uint8_t *data_buffer, size_t max_size);
} hci_h5_t;
const hci_h5_t *hci_get_h5_int_interface(void);
#endif

View file

@ -0,0 +1,58 @@
/******************************************************************************
*
* Copyright (C) 2009-2012 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Filename: rtk_btsnoop_net.h
*
* Description: A wrapper header file of bt_vendor_lib.h
*
* Contains definitions specific for interfacing with Realtek
* Bluetooth chipsets
*
******************************************************************************/
#ifndef RTK_BTSNOOP_NET_H
#define RTK_BTSNOOP_NET_H
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdbool.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <time.h>
#include "hci_h5_int.h"
#include <utils/Log.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
void rtk_btsnoop_open(void);
void rtk_btsnoop_close(void);
void rtk_btsnoop_capture(const HC_BT_HDR *p_buf, bool is_rcvd);
void rtk_btsnoop_net_open();
void rtk_btsnoop_net_close();
void rtk_btsnoop_net_write(serial_data_type_t type, uint8_t *data, bool is_received);
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,152 @@
/******************************************************************************
*
* Copyright (C) 2016 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Module Name:
* rtk_parse.h
*
* Abstract:
* Contains wifi-bt coex functions implemented by bluedroid stack
*
* Major Change History:
* When Who What
* ---------------------------------------------------------------
* 2015-12-15 lamparten modified
* 2014-10-23 kyle_xu modified
*
* Notes:
* This is designed for wifi-bt Coex in Android 6.0.
*
******************************************************************************/
#ifndef RTK_PARSE_H
#define RTK_PARSE_H
#pragma once
#include <stdlib.h>
#include <strings.h>
#include "bt_vendor_rtk.h"
#include "userial_vendor.h"
/******************************************************************************
** Constants & Macros
******************************************************************************/
#define HOST_PROFILE_INFO
/******************************************************************************
** Type definitions
******************************************************************************/
typedef unsigned char UINT8;
#define BD_ADDR_LEN 6 /* Device address length */
typedef UINT8 BD_ADDR[BD_ADDR_LEN]; /* Device address */
typedef void* TRANSAC;
/******************************************************************************
** Extern variables and functions
******************************************************************************/
extern uint8_t coex_log_enable;
/******************************************************************************
** Functions
******************************************************************************/
typedef struct rtk_parse_manager_t {
void (*rtk_parse_internal_event_intercept)(uint8_t *p);
void (*rtk_parse_l2cap_data)(uint8_t *p, uint8_t direction);
void (*rtk_parse_init)(void);
void (*rtk_parse_cleanup)(void);
void (*rtk_parse_command)(uint8_t *p);
void (*rtk_add_le_profile)(BD_ADDR bdaddr, uint16_t handle, uint8_t profile_map);
void (*rtk_delete_le_profile)(BD_ADDR bdaddr, uint16_t handle, uint8_t profile_map);
void (*rtk_add_le_data_count)(uint8_t data_type);
}rtk_parse_manager_t;
const rtk_parse_manager_t *rtk_parse_manager_get_interface();
#ifdef __LITTLE_ENDIAN
struct sbc_frame_hdr {
uint8_t syncword:8; /* Sync word */
uint8_t subbands:1; /* Subbands */
uint8_t allocation_method:1; /* Allocation method */
uint8_t channel_mode:2; /* Channel mode */
uint8_t blocks:2; /* Blocks */
uint8_t sampling_frequency:2; /* Sampling frequency */
uint8_t bitpool:8; /* Bitpool */
uint8_t crc_check:8; /* CRC check */
} __attribute__ ((packed));
/* NOTE: The code is copied from pa.
* only the bit field in 8-bit is affected by endian, not the 16-bit or 32-bit.
* why?
*/
struct rtp_header {
unsigned cc:4;
unsigned x:1;
unsigned p:1;
unsigned v:2;
unsigned pt:7;
unsigned m:1;
uint16_t sequence_number;
uint32_t timestamp;
uint32_t ssrc;
uint32_t csrc[0];
} __attribute__ ((packed));
#else
/* big endian */
struct sbc_frame_hdr {
uint8_t syncword:8; /* Sync word */
uint8_t sampling_frequency:2; /* Sampling frequency */
uint8_t blocks:2; /* Blocks */
uint8_t channel_mode:2; /* Channel mode */
uint8_t allocation_method:1; /* Allocation method */
uint8_t subbands:1; /* Subbands */
uint8_t bitpool:8; /* Bitpool */
uint8_t crc_check:8; /* CRC check */
} __attribute__ ((packed));
struct rtp_header {
unsigned v:2;
unsigned p:1;
unsigned x:1;
unsigned cc:4;
unsigned m:1;
unsigned pt:7;
uint16_t sequence_number;
uint32_t timestamp;
uint32_t ssrc;
uint32_t csrc[0];
} __attribute__ ((packed));
#endif /* __LITTLE_ENDIAN */
#endif /*RTK_PARSE_H*/

View file

@ -0,0 +1,73 @@
/******************************************************************************
*
* Copyright (C) 2009-2012 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Filename: userial_vendor.h
*
* Description: Contains vendor-specific definitions used in serial port
* controls
*
******************************************************************************/
#ifndef RTK_SOCKET_H
#define RTK_SOCKET_H
#include "bt_vendor_rtk.h"
#include "userial.h"
#include <sys/poll.h>
#include <assert.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <sys/prctl.h>
#include <sys/un.h>
#ifdef CONFIG_SCO_OVER_HCI
#define SCO_CTRL_PATH "/data/misc/bluedroid/.sco_ctrl"
#define SCO_DATA_PATH "/data/misc/bluedroid/.sco_data"
typedef enum {
SCO_CTRL_CMD_NONE,
SCO_CTRL_CMD_CHECK_READY,
SCO_CTRL_CMD_OUT_START,
SCO_CTRL_CMD_IN_START,
SCO_CTRL_CMD_OUT_STOP,
SCO_CTRL_CMD_IN_STOP,
SCO_CTRL_CMD_SUSPEND,
SCO_CTRL_GET_AUDIO_CONFIG,
SCO_CTRL_CMD_OFFLOAD_START,
} tSCO_CTRL_CMD;
#define SCO_SAMPLE_RATE_8K 1
#define SCO_SAMPLE_RATE_16K 2
#endif
#define MAX(a,b) ((a)>(b)?(a):(b))
/******************************************************************************
** Constants & Macros
******************************************************************************/
uint32_t Skt_Read(int fd, uint8_t *p_buf, uint32_t len);
int Skt_Read_noblock(int fd, uint8_t *p_buf, uint32_t len);
bool Skt_Send(int fd, uint8_t *p_buf, uint16_t msglen);
int Skt_Send_noblock(int fd, uint8_t *p_buf, uint16_t msglen);
#endif

View file

@ -0,0 +1,118 @@
/******************************************************************************
*
* Copyright (C) 2009-2012 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Filename: upio.h
*
* Description: Contains definitions used for I/O controls
*
******************************************************************************/
#ifndef UPIO_H
#define UPIO_H
/******************************************************************************
** Constants & Macros
******************************************************************************/
#define UPIO_BT_POWER_OFF 0
#define UPIO_BT_POWER_ON 1
/* UPIO signals */
enum {
UPIO_BT_WAKE = 0,
UPIO_HOST_WAKE,
UPIO_LPM_MODE,
UPIO_MAX_COUNT
};
/* UPIO assertion/deassertion */
enum {
UPIO_UNKNOWN = 0,
UPIO_DEASSERT,
UPIO_ASSERT
};
/******************************************************************************
** Extern variables and functions
******************************************************************************/
/******************************************************************************
** Functions
******************************************************************************/
/*******************************************************************************
**
** Function upio_init
**
** Description Initialization
**
** Returns None
**
*******************************************************************************/
void upio_init(void);
/*******************************************************************************
**
** Function upio_cleanup
**
** Description Clean up
**
** Returns None
**
*******************************************************************************/
void upio_cleanup(void);
/*******************************************************************************
**
** Function upio_set_bluetooth_power
**
** Description Interact with low layer driver to set Bluetooth power
** on/off.
**
** Returns 0 : SUCCESS or Not-Applicable
** <0 : ERROR
**
*******************************************************************************/
int upio_set_bluetooth_power(int on);
/*******************************************************************************
**
** Function upio_set
**
** Description Set i/o based on polarity
**
** Returns None
**
*******************************************************************************/
void upio_set(uint8_t pio, uint8_t action, uint8_t polarity);
/*******************************************************************************
**
** Function bt_wake_up_host_mode_set
**
** Description To enable/disable bt_wake_up_host mode.
**
** Returns 0 : SUCCESS or Not-Applicable
** <0 : ERROR
**
*******************************************************************************/
int bt_wake_up_host_mode_set(uint8_t mode);
#endif /* UPIO_H */

View file

@ -0,0 +1,221 @@
/******************************************************************************
*
* Copyright (C) 2009-2012 Realtek 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.
*
******************************************************************************/
/******************************************************************************
*
* Filename: userial_vendor.h
*
* Description: Contains vendor-specific definitions used in serial port
* controls
*
******************************************************************************/
#ifndef USERIAL_VENDOR_H
#define USERIAL_VENDOR_H
#include "bt_vendor_rtk.h"
#include "userial.h"
#include "hci_h5_int.h"
#include <sys/poll.h>
#include <assert.h>
#include "rtk_parse.h"
#include "bt_skbuff.h"
/******************************************************************************
** Constants & Macros
******************************************************************************/
#define RTK_NO_INTR(fn) do {} while ((fn) == -1 && errno == EINTR)
#define RTK_GET_BOUNDARY_FLAG(handle) (((handle) >> 12) & 0x0003)
#define RTK_START_PACKET_BOUNDARY 2
/**** baud rates ****/
#define USERIAL_BAUD_300 0
#define USERIAL_BAUD_600 1
#define USERIAL_BAUD_1200 2
#define USERIAL_BAUD_2400 3
#define USERIAL_BAUD_9600 4
#define USERIAL_BAUD_19200 5
#define USERIAL_BAUD_57600 6
#define USERIAL_BAUD_115200 7
#define USERIAL_BAUD_230400 8
#define USERIAL_BAUD_460800 9
#define USERIAL_BAUD_921600 10
#define USERIAL_BAUD_1M 11
#define USERIAL_BAUD_1_5M 12
#define USERIAL_BAUD_2M 13
#define USERIAL_BAUD_3M 14
#define USERIAL_BAUD_4M 15
#define USERIAL_BAUD_AUTO 16
/**** Data Format ****/
/* Stop Bits */
#define USERIAL_STOPBITS_1 1
#define USERIAL_STOPBITS_1_5 (1<<1)
#define USERIAL_STOPBITS_2 (1<<2)
/* Parity Bits */
#define USERIAL_PARITY_NONE (1<<3)
#define USERIAL_PARITY_EVEN (1<<4)
#define USERIAL_PARITY_ODD (1<<5)
/* Data Bits */
#define USERIAL_DATABITS_5 (1<<6)
#define USERIAL_DATABITS_6 (1<<7)
#define USERIAL_DATABITS_7 (1<<8)
#define USERIAL_DATABITS_8 (1<<9)
#define USERIAL_HW_FLOW_CTRL_OFF 0
#define USERIAL_HW_FLOW_CTRL_ON 1
#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
/* These are the ioctl values used for bt_wake ioctl via UART driver. you may
* need to redefine them on you platform!
* Logically they need to be unique and not colide with existing uart ioctl's.
*/
#ifndef USERIAL_IOCTL_BT_WAKE_ASSERT
#define USERIAL_IOCTL_BT_WAKE_ASSERT 0x8003
#endif
#ifndef USERIAL_IOCTL_BT_WAKE_DEASSERT
#define USERIAL_IOCTL_BT_WAKE_DEASSERT 0x8004
#endif
#ifndef USERIAL_IOCTL_BT_WAKE_GET_ST
#define USERIAL_IOCTL_BT_WAKE_GET_ST 0x8005
#endif
#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
/******************************************************************************
** Type definitions
******************************************************************************/
// 2 bytes for opcode, 1 byte for parameter length (Volume 2, Part E, 5.4.1)
#define COMMAND_PREAMBLE_SIZE 3
// 2 bytes for handle, 2 bytes for data length (Volume 2, Part E, 5.4.2)
#define ACL_PREAMBLE_SIZE 4
// 2 bytes for handle, 1 byte for data length (Volume 2, Part E, 5.4.3)
#define SCO_PREAMBLE_SIZE 3
// 1 byte for event code, 1 byte for parameter length (Volume 2, Part E, 5.4.4)
#define EVENT_PREAMBLE_SIZE 2
#define HCI_PACKET_TYPE_TO_INDEX(type) ((type) - 1)
#define COMMON_DATA_LENGTH_INDEX 3
#define EVENT_DATA_LENGTH_INDEX 2
/* Structure used to configure serial port during open */
typedef struct
{
uint16_t fmt; /* Data format */
uint8_t baud; /* Baud rate */
uint8_t hw_fctrl; /*hardware flowcontrol*/
} tUSERIAL_CFG;
typedef enum {
#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
USERIAL_OP_ASSERT_BT_WAKE,
USERIAL_OP_DEASSERT_BT_WAKE,
USERIAL_OP_GET_BT_WAKE_STATE,
#endif
USERIAL_OP_NOP,
} userial_vendor_ioctl_op_t;
enum {
RTKBT_PACKET_IDLE,
RTKBT_PACKET_TYPE,
RTKBT_PACKET_HEADER,
RTKBT_PACKET_CONTENT,
RTKBT_PACKET_END
};
/******************************************************************************
** Extern variables and functions
******************************************************************************/
/******************************************************************************
** Functions
******************************************************************************/
/*******************************************************************************
**
** Function userial_vendor_init
**
** Description Initialize userial vendor-specific control block
**
** Returns None
**
*******************************************************************************/
void userial_vendor_init(char *bt_device_node);
/*******************************************************************************
**
** Function userial_vendor_open
**
** Description Open the serial port with the given configuration
**
** Returns device fd
**
*******************************************************************************/
int userial_vendor_open(tUSERIAL_CFG *p_cfg);
/*******************************************************************************
**
** Function userial_vendor_close
**
** Description Conduct vendor-specific close work
**
** Returns None
**
*******************************************************************************/
void userial_vendor_close(void);
/*******************************************************************************
**
** Function userial_vendor_set_baud
**
** Description Set new baud rate
**
** Returns None
**
*******************************************************************************/
void userial_vendor_set_baud(uint8_t userial_baud);
/*******************************************************************************
**
** Function userial_vendor_ioctl
**
** Description ioctl inteface
**
** Returns None
**
*******************************************************************************/
void userial_vendor_ioctl(userial_vendor_ioctl_op_t op, void *p_data);
void userial_vendor_set_hw_fctrl(uint8_t hw_fctrl);
int userial_socket_open(void);
int userial_vendor_usb_ioctl(int operation, void* param);
int userial_vendor_usb_open(void);
#define RTK_HANDLE_EVENT
#define RTK_HANDLE_CMD
//#define CONFIG_SCO_OVER_HCI
#endif /* USERIAL_VENDOR_H */

View file

@ -0,0 +1,11 @@
#ifndef _VND_BUILDCFG_H
#define _VND_BUILDCFG_H
#define BLUETOOTH_UART_DEVICE_PORT "/dev/ttyS1"
#define FW_PATCHFILE_LOCATION "/etc/firmware/"
#define LPM_IDLE_TIMEOUT_MULTIPLE 5
#define SCO_USE_I2S_INTERFACE TRUE
#define BTVND_DBG TRUE
#define BTHW_DBG TRUE
#define VNDUSERIAL_DBG TRUE
#define UPIO_DBG TRUE
#endif