1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2013 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 
20 #ifndef GAP_INT_H
21 #define GAP_INT_H
22 
23 #include "common/bt_target.h"
24 #include "osi/fixed_queue.h"
25 #include "stack/gap_api.h"
26 #include "stack/gatt_api.h"
27 #define GAP_MAX_BLOCKS 2        /* Concurrent GAP commands pending at a time*/
28 /* Define the Generic Access Profile control structure */
29 typedef struct {
30     void          *p_data;      /* Pointer to any data returned in callback */
31     tGAP_CALLBACK *gap_cback;   /* Pointer to users callback function */
32     tGAP_CALLBACK *gap_inq_rslt_cback; /* Used for inquiry results */
33     UINT16         event;       /* Passed back in the callback */
34     UINT8          index;       /* Index of this control block and callback */
35     BOOLEAN        in_use;      /* True when structure is allocated */
36 } tGAP_INFO;
37 
38 /* Define the control block for the FindAddrByName operation (Only 1 active at a time) */
39 typedef struct {
40     tGAP_CALLBACK           *p_cback;
41     tBTM_INQ_INFO           *p_cur_inq; /* Pointer to the current inquiry database entry */
42     tGAP_FINDADDR_RESULTS    results;
43     BOOLEAN                  in_use;
44 } tGAP_FINDADDR_CB;
45 
46 /* Define the GAP Connection Control Block.
47 */
48 typedef struct {
49 #define GAP_CCB_STATE_IDLE              0
50 #define GAP_CCB_STATE_LISTENING         1
51 #define GAP_CCB_STATE_CONN_SETUP        2
52 #define GAP_CCB_STATE_CFG_SETUP         3
53 #define GAP_CCB_STATE_WAIT_SEC          4
54 #define GAP_CCB_STATE_CONNECTED         5
55     UINT8             con_state;
56 
57 #define GAP_CCB_FLAGS_IS_ORIG           0x01
58 #define GAP_CCB_FLAGS_HIS_CFG_DONE      0x02
59 #define GAP_CCB_FLAGS_MY_CFG_DONE       0x04
60 #define GAP_CCB_FLAGS_SEC_DONE          0x08
61 #define GAP_CCB_FLAGS_CONN_DONE         0x0E
62     UINT8             con_flags;
63 
64     UINT8             service_id;           /* Used by BTM                          */
65     UINT16            gap_handle;           /* GAP handle                           */
66     UINT16            connection_id;        /* L2CAP CID                            */
67     BOOLEAN           rem_addr_specified;
68     UINT8             chan_mode_mask;       /* Supported channel modes (FCR)        */
69     BD_ADDR           rem_dev_address;
70     UINT16            psm;
71     UINT16            rem_mtu_size;
72 
73     BOOLEAN           is_congested;
74     fixed_queue_t     *tx_queue;             /* Queue of buffers waiting to be sent  */
75     fixed_queue_t     *rx_queue;             /* Queue of buffers waiting to be read  */
76 
77     UINT32            rx_queue_size;        /* Total data count in rx_queue         */
78 
79     tGAP_CONN_CALLBACK *p_callback;         /* Users callback function              */
80 
81     tL2CAP_CFG_INFO   cfg;                  /* Configuration                        */
82     tL2CAP_ERTM_INFO  ertm_info;            /* Pools and modes for ertm */
83 } tGAP_CCB;
84 
85 typedef struct {
86 #if ((defined AMP_INCLUDED) && (AMP_INCLUDED == TRUE))
87     tAMP_APPL_INFO    reg_info;
88 #else
89     tL2CAP_APPL_INFO  reg_info;                     /* L2CAP Registration info */
90 #endif
91     tGAP_CCB    ccb_pool[GAP_MAX_CONNECTIONS];
92 } tGAP_CONN;
93 
94 
95 #if BLE_INCLUDED == TRUE
96 #define GAP_MAX_CHAR_NUM          4
97 
98 typedef struct {
99     UINT16                  handle;
100     UINT16                  uuid;
101     tGAP_BLE_ATTR_VALUE     attr_value;
102 } tGAP_ATTR;
103 #endif
104 /**********************************************************************
105 ** M A I N   C O N T R O L   B L O C K
106 ***********************************************************************/
107 
108 #define GAP_MAX_CL GATT_CL_MAX_LCB
109 
110 typedef struct {
111     UINT16 uuid;
112     tGAP_BLE_CMPL_CBACK *p_cback;
113 } tGAP_BLE_REQ;
114 
115 typedef struct {
116     BD_ADDR                 bda;
117     tGAP_BLE_CMPL_CBACK     *p_cback;
118     UINT16                  conn_id;
119     UINT16                  cl_op_uuid;
120     BOOLEAN                 in_use;
121     BOOLEAN                 connected;
122     fixed_queue_t           *pending_req_q;
123 
124 } tGAP_CLCB;
125 
126 typedef struct {
127     tGAP_INFO        blk[GAP_MAX_BLOCKS];
128     tBTM_CMPL_CB    *btm_cback[GAP_MAX_BLOCKS];
129     UINT8            trace_level;
130     //tGAP_FINDADDR_CB findaddr_cb;   /* Contains the control block for finding a device addr */
131     //tBTM_INQ_INFO   *cur_inqptr;
132 
133 #if GAP_CONN_INCLUDED == TRUE
134     tGAP_CONN        conn;
135 #endif
136 
137     /* LE GAP attribute database */
138 #if BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE
139     tGAP_ATTR               gap_attr[GAP_MAX_CHAR_NUM];
140     tGAP_CLCB               clcb[GAP_MAX_CL]; /* connection link*/
141     tGATT_IF                gatt_if;
142 #endif
143 } tGAP_CB;
144 
145 #if GAP_DYNAMIC_MEMORY == FALSE
146 extern tGAP_CB  gap_cb;
147 #else
148 extern tGAP_CB  *gap_cb_ptr;
149 #define gap_cb (*gap_cb_ptr)
150 #endif
151 
152 #if (GAP_CONN_INCLUDED == TRUE)
153 extern void gap_conn_init(void);
154 #endif
155 #if (BLE_INCLUDED == TRUE && GATTS_INCLUDED == TRUE)
156 extern void gap_attr_db_init(void);
157 #endif
158 
159 #endif
160