Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cec99a5 authored by Ganesh Ganapathi Batta's avatar Ganesh Ganapathi Batta Committed by Matthew Xie
Browse files

BT: JV rfcomm socket sniff support

Bug:8322094

Change-Id: Ib472f39488b685ac396289e65c1da21fdfd93c4c
parent 31618422
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "bta_sys.h"
#include "bta_api.h"
#include "bta_dm_int.h"
#include "bta_jv_api.h"

#ifndef BTA_DM_LINK_POLICY_SETTINGS
#define BTA_DM_LINK_POLICY_SETTINGS    (HCI_ENABLE_MASTER_SLAVE_SWITCH | HCI_ENABLE_HOLD_MODE | HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)
@@ -124,8 +125,8 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[] =
  {BTA_ID_OPC, BTA_ALL_APP_ID,      6},  /* reuse ftc spec table */
  {BTA_ID_OPS, BTA_ALL_APP_ID,      7},  /* reuse fts spec table */
  {BTA_ID_MSE, BTA_ALL_APP_ID,      7},  /* reuse fts spec table */
  {BTA_ID_JV1, BTA_ALL_APP_ID,      7},  /* reuse fts spec table */
  {BTA_ID_JV2, BTA_ALL_APP_ID,      7},  /* reuse fts spec table */
  {BTA_ID_JV,  BTA_JV_PM_ID_1,      6},  /* app BTA_JV_PM_ID_1, reuse ftc spec table */
  {BTA_ID_JV,  BTA_ALL_APP_ID,      7},  /* reuse fts spec table */
  {BTA_ID_HL,  BTA_ALL_APP_ID,      8}   /* reuse fts spec table */
};

+64 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#define BTA_JV_FAILURE             1            /* Generic failure. */
#define BTA_JV_BUSY                2            /* Temporarily can not handle this request. */
#define BTA_JV_NO_DATA             3            /* no data. */
#define BTA_JV_NO_RESOURCE         4            /* No more set pm control block */

typedef UINT8 tBTA_JV_STATUS;
#define BTA_JV_INTERNAL_ERR        (-1) /* internal error. */
@@ -103,7 +104,34 @@ typedef UINT32 tBTA_JV_ROLE;
#define BTA_JV_SERVICE_TELEPHONY        BTM_COD_SERVICE_TELEPHONY       /* 0x4000 */
#define BTA_JV_SERVICE_INFORMATION      BTM_COD_SERVICE_INFORMATION     /* 0x8000 */

/* JV ID type */
#define BTA_JV_PM_ID_1             1    /* PM example profile 1 */
#define BTA_JV_PM_ID_2             2    /* PM example profile 2 */
#define BTA_JV_PM_ID_CLEAR         0    /* Special JV ID used to clear PM profile */
#define BTA_JV_PM_ALL              0xFF /* Generic match all id, see bta_dm_cfg.c */
typedef UINT8 tBTA_JV_PM_ID;

#define BTA_JV_PM_HANDLE_CLEAR     0xFF /* Special JV ID used to clear PM profile  */

/* define maximum number of registered PM entities. should be in sync with bta pm! */
#ifndef BTA_JV_PM_MAX_NUM
#define BTA_JV_PM_MAX_NUM 5
#endif

/* JV pm connection states */
enum
{
    BTA_JV_CONN_OPEN = 0,   /* Connection opened state */
    BTA_JV_CONN_CLOSE,      /* Connection closed state */
    BTA_JV_APP_OPEN,        /* JV Application opened state */
    BTA_JV_APP_CLOSE,       /* JV Application closed state */
    BTA_JV_SCO_OPEN,        /* SCO connection opened state */
    BTA_JV_SCO_CLOSE,       /* SCO connection opened state */
    BTA_JV_CONN_IDLE,       /* Connection idle state */
    BTA_JV_CONN_BUSY,       /* Connection busy state */
    BTA_JV_MAX_CONN_STATE   /* Max number of connection state */
};
typedef UINT8 tBTA_JV_CONN_STATE;

/* Java I/F callback events */
/* events received by tBTA_JV_DM_CBACK */
@@ -364,6 +392,21 @@ typedef struct
    BOOLEAN         cong;       /* congestion status */
} tBTA_JV_RFCOMM_WRITE;

/* data associated with BTA_JV_API_SET_PM_PROFILE_EVT */
typedef struct
{
    tBTA_JV_STATUS  status;     /* Status of the operation */
    UINT32          handle;     /* Connection handle */
    tBTA_JV_PM_ID   app_id;      /* JV app ID */
} tBTA_JV_SET_PM_PROFILE;

/* data associated with BTA_JV_API_NOTIFY_PM_STATE_CHANGE_EVT */
typedef struct
{
    UINT32          handle;     /* Connection handle */
    tBTA_JV_CONN_STATE  state;  /* JV connection stata */
} tBTA_JV_NOTIFY_PM_STATE_CHANGE;


/* union of data associated with JV callback */
typedef union
@@ -1101,6 +1144,27 @@ BTA_API extern tBTA_JV_STATUS BTA_JvRfcommReady(UINT32 handle, UINT32 *p_data_si
*******************************************************************************/
BTA_API extern tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id);

/*******************************************************************************
 **
 ** Function    BTA_JVSetPmProfile
 **
 ** Description This function set or free power mode profile for different JV application
 **
 ** Parameters:  handle,  JV handle from RFCOMM or L2CAP
 **              app_id:  app specific pm ID, can be BTA_JV_PM_ALL, see bta_dm_cfg.c for details
 **              BTA_JV_PM_ID_CLEAR: removes pm management on the handle. init_st is ignored and
 **              BTA_JV_CONN_CLOSE is called implicitely
 **              init_st:  state after calling this API. typically it should be BTA_JV_CONN_OPEN
 **
 ** Returns      BTA_JV_SUCCESS, if the request is being processed.
 **              BTA_JV_FAILURE, otherwise.
 **
 ** NOTE:        BTA_JV_PM_ID_CLEAR: In general no need to be called as jv pm calls automatically
 **              BTA_JV_CONN_CLOSE to remove in case of connection close!
 **
 *******************************************************************************/
BTA_API extern tBTA_JV_STATUS BTA_JvSetPmProfile(UINT32 handle, tBTA_JV_PM_ID app_id,
                                                 tBTA_JV_CONN_STATE init_st);

/*******************************************************************************
**
+508 −92

File changed.

Preview size limit exceeded, changes collapsed.

+55 −7
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
 *  Technology (JABWT) as specified by the JSR82 specificiation
 *
 ******************************************************************************/

#include "bta_api.h"
#include "bd.h"
#include "bta_sys.h"
@@ -61,11 +60,17 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK *p_cback)
{
    tBTA_JV_STATUS status = BTA_JV_FAILURE;
    tBTA_JV_API_ENABLE  *p_buf;
    int i;

    APPL_TRACE_API0( "BTA_JvEnable");
    if(p_cback && FALSE == bta_sys_is_register(BTA_ID_JV))
    {
        memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB));
        /* set handle to invalid value by default */
        for (i=0; i<BTA_JV_PM_MAX_NUM; i++)
        {
            bta_jv_cb.pm_cb[i].handle = BTA_JV_PM_HANDLE_CLEAR;
        }

        /* register with BTA system manager */
        GKI_sched_lock();
@@ -80,6 +85,10 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK *p_cback)
            status = BTA_JV_SUCCESS;
        }
    }
    else
      {
         APPL_TRACE_ERROR0("JVenable fails");
      }
    return(status);
}

@@ -1362,7 +1371,7 @@ tBTA_JV_STATUS BTA_JvRfcommClose(UINT32 handle, void *user_data)
{
    tBTA_JV_STATUS status = BTA_JV_FAILURE;
    tBTA_JV_API_RFCOMM_CLOSE *p_msg;
    UINT32  hi = (handle & BTA_JV_RFC_HDL_MASK) - 1;
    UINT32  hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
    UINT32  si = BTA_JV_RFC_HDL_TO_SIDX(handle);

    APPL_TRACE_API0( "BTA_JvRfcommClose");
@@ -1448,7 +1457,7 @@ tBTA_JV_STATUS BTA_JvRfcommStopServer(UINT32 handle, void * user_data)
    if ((p_msg = (tBTA_JV_API_RFCOMM_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_SERVER))) != NULL)
    {
        p_msg->hdr.event = BTA_JV_API_RFCOMM_STOP_SERVER_EVT;
        p_msg->rfc_handle = handle;
        p_msg->handle = handle;
        p_msg->user_data = user_data; //caller's private data
        bta_sys_sendmsg(p_msg);
        status = BTA_JV_SUCCESS;
@@ -1472,7 +1481,7 @@ tBTA_JV_STATUS BTA_JvRfcommRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UIN
{
    tBTA_JV_STATUS status = BTA_JV_FAILURE;
    tBTA_JV_API_RFCOMM_READ *p_msg;
    UINT32  hi = (handle & BTA_JV_RFC_HDL_MASK) - 1;
    UINT32  hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
    UINT32  si = BTA_JV_RFC_HDL_TO_SIDX(handle);

    APPL_TRACE_API0( "BTA_JvRfcommRead");
@@ -1506,7 +1515,7 @@ tBTA_JV_STATUS BTA_JvRfcommRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UIN
*******************************************************************************/
UINT16 BTA_JvRfcommGetPortHdl(UINT32 handle)
{
    UINT32  hi = (handle & BTA_JV_RFC_HDL_MASK) - 1;
    UINT32  hi = ((handle & BTA_JV_RFC_HDL_MASK) & BTA_JV_RFCOMM_MASK) - 1;
    UINT32  si = BTA_JV_RFC_HDL_TO_SIDX(handle);

    if (hi < BTA_JV_MAX_RFC_CONN &&
@@ -1532,7 +1541,7 @@ tBTA_JV_STATUS BTA_JvRfcommReady(UINT32 handle, UINT32 *p_data_size)
{
    tBTA_JV_STATUS status = BTA_JV_FAILURE;
    UINT16          size = 0;
    UINT32  hi = (handle & BTA_JV_RFC_HDL_MASK) - 1;
    UINT32  hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
    UINT32  si = BTA_JV_RFC_HDL_TO_SIDX(handle);

    APPL_TRACE_API0( "BTA_JvRfcommReady");
@@ -1562,7 +1571,7 @@ tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id)
{
    tBTA_JV_STATUS status = BTA_JV_FAILURE;
    tBTA_JV_API_RFCOMM_WRITE *p_msg;
    UINT32  hi = (handle & BTA_JV_RFC_HDL_MASK) - 1;
    UINT32  hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
    UINT32  si = BTA_JV_RFC_HDL_TO_SIDX(handle);

    APPL_TRACE_API0( "BTA_JvRfcommWrite");
@@ -1584,3 +1593,42 @@ tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id)
    return(status);
}


/*******************************************************************************
 **
 ** Function    BTA_JVSetPmProfile
 **
 ** Description This function set or free power mode profile for different JV application
 **
 ** Parameters:  handle,  JV handle from RFCOMM or L2CAP
 **              app_id:  app specific pm ID, can be BTA_JV_PM_ALL, see bta_dm_cfg.c for details
 **              BTA_JV_PM_ID_CLEAR: removes pm management on the handle. init_st is ignored and
 **              BTA_JV_CONN_CLOSE is called implicitely
 **              init_st:  state after calling this API. typically it should be BTA_JV_CONN_OPEN
 **
 ** Returns      BTA_JV_SUCCESS, if the request is being processed.
 **              BTA_JV_FAILURE, otherwise.
 **
 ** NOTE:        BTA_JV_PM_ID_CLEAR: In general no need to be called as jv pm calls automatically
 **              BTA_JV_CONN_CLOSE to remove in case of connection close!
 **
 *******************************************************************************/
tBTA_JV_STATUS BTA_JvSetPmProfile(UINT32 handle, tBTA_JV_PM_ID app_id, tBTA_JV_CONN_STATE init_st)
{
    tBTA_JV_STATUS status = BTA_JV_FAILURE;
    tBTA_JV_API_SET_PM_PROFILE *p_msg;

    APPL_TRACE_API2("BTA_JVSetPmProfile handle:0x%x, app_id:%d", handle, app_id);
    if ((p_msg = (tBTA_JV_API_SET_PM_PROFILE *)GKI_getbuf(sizeof(tBTA_JV_API_SET_PM_PROFILE)))
        != NULL)
    {
        p_msg->hdr.event = BTA_JV_API_SET_PM_PROFILE_EVT;
        p_msg->handle = handle;
        p_msg->app_id = app_id;
        p_msg->init_st = init_st;
        bta_sys_sendmsg(p_msg);
        status = BTA_JV_SUCCESS;
    }

    return (status);
}
+58 −9
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "bta_api.h"
#include "bta_jv_api.h"
#include "rfcdefs.h"
#include "port_api.h"

/*****************************************************************************
**  Constants
@@ -67,9 +68,15 @@ enum
    BTA_JV_API_RFCOMM_STOP_SERVER_EVT,
    BTA_JV_API_RFCOMM_READ_EVT,
    BTA_JV_API_RFCOMM_WRITE_EVT,
    BTA_JV_API_SET_PM_PROFILE_EVT,
    BTA_JV_API_PM_STATE_CHANGE_EVT,
    BTA_JV_MAX_INT_EVT
};

#ifndef BTA_JV_RFC_EV_MASK
#define BTA_JV_RFC_EV_MASK (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | PORT_EV_FC | PORT_EV_FCS)
#endif

/* data type for BTA_JV_API_ENABLE_EVT */
typedef struct
{
@@ -148,6 +155,22 @@ typedef struct
    UINT16        uuid;
} tBTA_JV_API_SERVICE_SELECT;

enum
{
    BTA_JV_PM_FREE_ST = 0, /* empty PM slot */
    BTA_JV_PM_IDLE_ST,
    BTA_JV_PM_BUSY_ST
};

/* BTA JV PM control block */
typedef struct
{
    UINT32          handle;     /* The connection handle */
    UINT8           state;      /* state: see above enum */
    tBTA_JV_PM_ID   app_id;     /* JV app specific id indicating power table to use */
    BD_ADDR         peer_bd_addr;    /* Peer BD address */
} tBTA_JV_PM_CB;

enum
{
    BTA_JV_ST_NONE = 0,
@@ -168,11 +191,14 @@ typedef struct
    UINT16              psm;        /* the psm used for this server connection */
    tBTA_JV_STATE       state;      /* the state of this control block */
    tBTA_SERVICE_ID     sec_id;     /* service id */
    UINT16              handle;     /* the handle reported to java app (same as gap handle) */
    UINT32              handle;     /* the handle reported to java app (same as gap handle) */
    BOOLEAN             cong;       /* TRUE, if congested */
    tBTA_JV_PM_CB      *p_pm_cb;    /* ptr to pm control block, NULL: unused */
} tBTA_JV_L2C_CB;

#define BTA_JV_RFC_HDL_MASK         0xFF
#define BTA_JV_RFCOMM_MASK          0x80
#define BTA_JV_ALL_APP_ID           0xFF
#define BTA_JV_RFC_HDL_TO_SIDX(r)   (((r)&0xFF00) >> 8)
#define BTA_JV_RFC_H_S_TO_HDL(h, s) ((h)|(s<<8))

@@ -185,6 +211,7 @@ typedef struct
    UINT8               max_sess;   /* max sessions */
    void                *user_data; /* piggyback caller's private data*/
    BOOLEAN             cong;       /* TRUE, if congested */
    tBTA_JV_PM_CB      *p_pm_cb;    /* ptr to pm control block, NULL: unused */
} tBTA_JV_PCB;

/* JV RFCOMM control block */
@@ -226,7 +253,7 @@ typedef struct
typedef struct
{
    BT_HDR          hdr;
    UINT16          handle;
    UINT32          handle;
    tBTA_JV_L2C_CB  *p_cb;
} tBTA_JV_API_L2CAP_CLOSE;

@@ -234,7 +261,7 @@ typedef struct
typedef struct
{
    BT_HDR              hdr;
    UINT16              handle;
    UINT32              handle;
    UINT32              req_id;
    tBTA_JV_L2CAP_CBACK *p_cback;
    UINT8*              p_data;
@@ -245,7 +272,7 @@ typedef struct
typedef struct
{
    BT_HDR              hdr;
    UINT16              handle;
    UINT32              handle;
    UINT32              req_id;
    tBTA_JV_L2C_CB      *p_cb;
    UINT8               *p_data;
@@ -272,7 +299,7 @@ typedef struct
    tBTA_JV_ROLE    role;
    UINT8           local_scn;
    UINT8           max_session;
    int             rfc_handle;
    UINT32          handle;
    tBTA_JV_RFCOMM_CBACK *p_cback;
    void            *user_data;
} tBTA_JV_API_RFCOMM_SERVER;
@@ -281,7 +308,7 @@ typedef struct
typedef struct
{
    BT_HDR          hdr;
    UINT16          handle;
    UINT32          handle;
    UINT32          req_id;
    UINT8           *p_data;
    UINT16          len;
@@ -289,11 +316,28 @@ typedef struct
    tBTA_JV_PCB     *p_pcb;
} tBTA_JV_API_RFCOMM_READ;

/* data type for BTA_JV_API_SET_PM_PROFILE_EVT */
typedef struct
{
    BT_HDR              hdr;
    UINT32              handle;
    tBTA_JV_PM_ID       app_id;
    tBTA_JV_CONN_STATE  init_st;
} tBTA_JV_API_SET_PM_PROFILE;

/* data type for BTA_JV_API_PM_STATE_CHANGE_EVT */
typedef struct
{
    BT_HDR              hdr;
    tBTA_JV_PM_CB       *p_cb;
    tBTA_JV_CONN_STATE  state;
} tBTA_JV_API_PM_STATE_CHANGE;

/* data type for BTA_JV_API_RFCOMM_WRITE_EVT */
typedef struct
{
    BT_HDR          hdr;
    UINT16          handle;
    UINT32          handle;
    UINT32          req_id;
    UINT8           *p_data;
    int          len;
@@ -305,7 +349,7 @@ typedef struct
typedef struct
{
    BT_HDR          hdr;
    UINT16          handle;
    UINT32          handle;
    tBTA_JV_RFC_CB  *p_cb;
    tBTA_JV_PCB     *p_pcb;
    void        *user_data;
@@ -372,6 +416,8 @@ typedef union
    tBTA_JV_API_RFCOMM_CONNECT      rfcomm_connect;
    tBTA_JV_API_RFCOMM_READ         rfcomm_read;
    tBTA_JV_API_RFCOMM_WRITE        rfcomm_write;
    tBTA_JV_API_SET_PM_PROFILE      set_pm;
    tBTA_JV_API_PM_STATE_CHANGE     change_pm_state;
    tBTA_JV_API_RFCOMM_CLOSE        rfcomm_close;
    tBTA_JV_API_RFCOMM_SERVER       rfcomm_server;
} tBTA_JV_MSG;
@@ -402,6 +448,7 @@ typedef struct
    UINT8                   sdp_active;                     /* see BTA_JV_SDP_ACT_* */
    tSDP_UUID               uuid;                           /* current uuid of sdp discovery*/
    void                    *user_data;                     /* piggyback user data*/
    tBTA_JV_PM_CB           pm_cb[BTA_JV_PM_MAX_NUM];       /* PM on a per JV handle bases */
} tBTA_JV_CB;

enum
@@ -459,5 +506,7 @@ extern void bta_jv_rfcomm_start_server (tBTA_JV_MSG *p_data);
extern void bta_jv_rfcomm_stop_server (tBTA_JV_MSG *p_data);
extern void bta_jv_rfcomm_read (tBTA_JV_MSG *p_data);
extern void bta_jv_rfcomm_write (tBTA_JV_MSG *p_data);
extern void bta_jv_set_pm_profile (tBTA_JV_MSG *p_data);
extern void bta_jv_change_pm_state(tBTA_JV_MSG *p_data);

#endif /* BTA_JV_INT_H */
Loading