1ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/******************************************************************************
2ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *
3ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  Copyright (C) 2009-2013 Broadcom Corporation
4ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *
5ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  Licensed under the Apache License, Version 2.0 (the "License");
6ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  you may not use this file except in compliance with the License.
7ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  You may obtain a copy of the License at:
8ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *
9ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  http://www.apache.org/licenses/LICENSE-2.0
10ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *
11ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  Unless required by applicable law or agreed to in writing, software
12ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  distributed under the License is distributed on an "AS IS" BASIS,
13ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  See the License for the specific language governing permissions and
15ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *  limitations under the License.
16ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *
17ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta ******************************************************************************/
18ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
19ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
20ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#ifndef GAP_INT_H
21ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#define GAP_INT_H
22ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
23ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bt_target.h"
24bba583cd520b99d954f3585c38f59ef138d2fe40Pavlin Radoslavov#include "osi/include/fixed_queue.h"
25ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "gap_api.h"
26a11035b5ecbc6cbd9da5bd707683504c47e2744ePavlin Radoslavov#include "bt_common.h"
27ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "gatt_api.h"
288372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_MAX_BLOCKS 2        /* Concurrent GAP commands pending at a time*/
298372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz/* Define the Generic Access Profile control structure */
308372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulztypedef struct
318372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz{
328372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    void          *p_data;      /* Pointer to any data returned in callback */
338372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_CALLBACK *gap_cback;   /* Pointer to users callback function */
348372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_CALLBACK *gap_inq_rslt_cback; /* Used for inquiry results */
358372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT16         event;       /* Passed back in the callback */
368372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT8          index;       /* Index of this control block and callback */
378372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    BOOLEAN        in_use;      /* True when structure is allocated */
388372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz} tGAP_INFO;
398372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
408372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz/* Define the control block for the FindAddrByName operation (Only 1 active at a time) */
418372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulztypedef struct
428372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz{
438372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_CALLBACK           *p_cback;
448372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tBTM_INQ_INFO           *p_cur_inq; /* Pointer to the current inquiry database entry */
458372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_FINDADDR_RESULTS    results;
468372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    BOOLEAN                  in_use;
478372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz} tGAP_FINDADDR_CB;
488372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
498372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz/* Define the GAP Connection Control Block.
508372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz*/
518372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulztypedef struct
528372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz{
538372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_STATE_IDLE              0
548372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_STATE_LISTENING         1
558372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_STATE_CONN_SETUP        2
568372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_STATE_CFG_SETUP         3
578372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_STATE_WAIT_SEC          4
588372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_STATE_CONNECTED         5
598372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT8             con_state;
608372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
618372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_FLAGS_IS_ORIG           0x01
628372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_FLAGS_HIS_CFG_DONE      0x02
638372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_FLAGS_MY_CFG_DONE       0x04
648372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_FLAGS_SEC_DONE          0x08
658372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#define GAP_CCB_FLAGS_CONN_DONE         0x0E
668372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT8             con_flags;
678372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
688372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT8             service_id;           /* Used by BTM                          */
698372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT16            gap_handle;           /* GAP handle                           */
708372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT16            connection_id;        /* L2CAP CID                            */
718372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    BOOLEAN           rem_addr_specified;
728372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT8             chan_mode_mask;       /* Supported channel modes (FCR)        */
738372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    BD_ADDR           rem_dev_address;
748372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT16            psm;
758372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT16            rem_mtu_size;
768372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
778372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    BOOLEAN           is_congested;
78bba583cd520b99d954f3585c38f59ef138d2fe40Pavlin Radoslavov    fixed_queue_t     *tx_queue;            /* Queue of buffers waiting to be sent  */
79bba583cd520b99d954f3585c38f59ef138d2fe40Pavlin Radoslavov    fixed_queue_t     *rx_queue;            /* Queue of buffers waiting to be read  */
808372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
818372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    UINT32            rx_queue_size;        /* Total data count in rx_queue         */
828372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
838372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_CONN_CALLBACK *p_callback;         /* Users callback function              */
848372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
858372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tL2CAP_CFG_INFO   cfg;                  /* Configuration                        */
868372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tL2CAP_ERTM_INFO  ertm_info;            /* Pools and modes for ertm */
87ab99638f9a05ae7ed04ab0a75d48cbd1d78b36e8Navin Kochar    tBT_TRANSPORT     transport;            /* Transport channel BR/EDR or BLE */
88ab99638f9a05ae7ed04ab0a75d48cbd1d78b36e8Navin Kochar    tL2CAP_LE_CFG_INFO local_coc_cfg;       /* local configuration for LE Coc */
89ab99638f9a05ae7ed04ab0a75d48cbd1d78b36e8Navin Kochar    tL2CAP_LE_CFG_INFO peer_coc_cfg;        /* local configuration for LE Coc */
908372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz} tGAP_CCB;
918372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
928372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulztypedef struct
938372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz{
948372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#if AMP_INCLUDED == TRUE
958372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tAMP_APPL_INFO    reg_info;
968372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#else
978372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tL2CAP_APPL_INFO  reg_info;                     /* L2CAP Registration info */
988372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#endif
998372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_CCB    ccb_pool[GAP_MAX_CONNECTIONS];
1008372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz} tGAP_CONN;
1018372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
102ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
103ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#if BLE_INCLUDED == TRUE
104444a8da807abaf5f9e813ce70c56a79160495fb3Satya Calloji#define GAP_MAX_CHAR_NUM          4
105ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
106ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct
107ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
108ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT16                  handle;
109ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT16                  uuid;
110ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tGAP_BLE_ATTR_VALUE     attr_value;
111ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}tGAP_ATTR;
112ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#endif
113ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/**********************************************************************
114ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** M A I N   C O N T R O L   B L O C K
115ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta***********************************************************************/
116ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
117ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#define GAP_MAX_CL GATT_CL_MAX_LCB
118ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
119ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct
120ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
121444a8da807abaf5f9e813ce70c56a79160495fb3Satya Calloji    UINT16 uuid;
122444a8da807abaf5f9e813ce70c56a79160495fb3Satya Calloji    tGAP_BLE_CMPL_CBACK *p_cback;
123444a8da807abaf5f9e813ce70c56a79160495fb3Satya Calloji} tGAP_BLE_REQ;
124ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
125ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct
126ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
127ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    BD_ADDR                 bda;
128444a8da807abaf5f9e813ce70c56a79160495fb3Satya Calloji    tGAP_BLE_CMPL_CBACK     *p_cback;
129ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT16                  conn_id;
130ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT16                  cl_op_uuid;
131ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    BOOLEAN                 in_use;
132ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    BOOLEAN                 connected;
133bba583cd520b99d954f3585c38f59ef138d2fe40Pavlin Radoslavov    fixed_queue_t           *pending_req_q;
134444a8da807abaf5f9e813ce70c56a79160495fb3Satya Calloji
135ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}tGAP_CLCB;
136ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
137ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct
138ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
1398372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_INFO        blk[GAP_MAX_BLOCKS];
1408372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tBTM_CMPL_CB    *btm_cback[GAP_MAX_BLOCKS];
141ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT8            trace_level;
1428372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_FINDADDR_CB findaddr_cb;   /* Contains the control block for finding a device addr */
1438372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tBTM_INQ_INFO   *cur_inqptr;
1448372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz
1458372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#if GAP_CONN_INCLUDED == TRUE
1468372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz    tGAP_CONN        conn;
1478372aa5fa535ee4f09c09981b6125b54ace31fe2Kim Schulz#endif
148ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
149ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    /* LE GAP attribute database */
150ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#if BLE_INCLUDED == TRUE
151ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tGAP_ATTR               gatt_attr[GAP_MAX_CHAR_NUM];
152ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tGAP_CLCB               clcb[GAP_MAX_CL]; /* connection link*/
153ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tGATT_IF                gatt_if;
154ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#endif
155ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} tGAP_CB;
156ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
157ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
15865645888da537ff8b3480c36ffe2dfc58844aea6Zach Johnsonextern tGAP_CB  gap_cb;
159d232721ae5e5b6949a5249f0d116408b8a3c5f1dCasper Bonde#if (GAP_CONN_INCLUDED == TRUE)
160d232721ae5e5b6949a5249f0d116408b8a3c5f1dCasper Bonde    extern void gap_conn_init(void);
161d232721ae5e5b6949a5249f0d116408b8a3c5f1dCasper Bonde#endif
162ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#if (BLE_INCLUDED == TRUE)
163ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    extern void gap_attr_db_init(void);
164ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#endif
165ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
166ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#endif
167