Home | History | Annotate | Download | only in gap
      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 "bt_target.h"
     24 #include "gap_api.h"
     25 #include "btm_api.h"
     26 #include "gki.h"
     27 #include "gatt_api.h"
     28 #if AMP_INCLUDED == TRUE
     29     #include "amp_api.h"
     30 #endif
     31 
     32 #if defined BLE_INCLUDED && BLE_INCLUDED == TRUE
     33     #include "gatt_api.h"
     34 #endif
     35 
     36 #define GAP_MAX_BLOCKS 2        /* Concurrent GAP commands pending at a time*/
     37 /* There must be a different btm callback for*/
     38 /* each control block.*/
     39 
     40 
     41 /* Definitions of limits for inquiries */
     42 #define GAP_PER_INQ_MIN_MAX_PERIOD      BTM_PER_INQ_MIN_MAX_PERIOD
     43 #define GAP_PER_INQ_MAX_MAX_PERIOD      BTM_PER_INQ_MAX_MAX_PERIOD
     44 #define GAP_PER_INQ_MIN_MIN_PERIOD      BTM_PER_INQ_MIN_MIN_PERIOD
     45 #define GAP_PER_INQ_MAX_MIN_PERIOD      BTM_PER_INQ_MAX_MIN_PERIOD
     46 #define GAP_MAX_INQUIRY_LENGTH          BTM_MAX_INQUIRY_LENGTH
     47 #define GAP_MIN_INQUIRY_LEN             BTM_MIN_INQUIRY_LEN
     48 
     49 /* Define the Generic Access Profile control structure */
     50 typedef struct
     51 {
     52     void          *p_data;      /* Pointer to any data returned in callback */
     53     tGAP_CALLBACK *gap_cback;   /* Pointer to users callback function */
     54     tGAP_CALLBACK *gap_inq_rslt_cback; /* Used for inquiry results */
     55     UINT16         event;       /* Passed back in the callback */
     56     UINT8          index;       /* Index of this control block and callback */
     57     BOOLEAN        in_use;      /* True when structure is allocated */
     58 } tGAP_INFO;
     59 
     60 /* Define the control block for the FindAddrByName operation (Only 1 active at a time) */
     61 typedef struct
     62 {
     63     tGAP_CALLBACK           *p_cback;
     64     tBTM_INQ_INFO           *p_cur_inq; /* Pointer to the current inquiry database entry */
     65     tGAP_FINDADDR_RESULTS    results;
     66     BOOLEAN                  in_use;
     67 } tGAP_FINDADDR_CB;
     68 
     69 
     70 /* Define the GAP Connection Control Block.
     71 */
     72 typedef struct
     73 {
     74 #define GAP_CCB_STATE_IDLE              0
     75 #define GAP_CCB_STATE_LISTENING         1
     76 #define GAP_CCB_STATE_CONN_SETUP        2
     77 #define GAP_CCB_STATE_CFG_SETUP         3
     78 #define GAP_CCB_STATE_WAIT_SEC          4
     79 #define GAP_CCB_STATE_CONNECTED         5
     80     UINT8             con_state;
     81 
     82 #define GAP_CCB_FLAGS_IS_ORIG           0x01
     83 #define GAP_CCB_FLAGS_HIS_CFG_DONE      0x02
     84 #define GAP_CCB_FLAGS_MY_CFG_DONE       0x04
     85 #define GAP_CCB_FLAGS_SEC_DONE          0x08
     86 #define GAP_CCB_FLAGS_CONN_DONE         0x0E
     87     UINT8             con_flags;
     88 
     89     UINT8             service_id;           /* Used by BTM                          */
     90     UINT16            gap_handle;           /* GAP handle                           */
     91     UINT16            connection_id;        /* L2CAP CID                            */
     92     BOOLEAN           rem_addr_specified;
     93     UINT8             chan_mode_mask;       /* Supported channel modes (FCR)        */
     94     BD_ADDR           rem_dev_address;
     95     UINT16            psm;
     96     UINT16            rem_mtu_size;
     97 
     98     BOOLEAN           is_congested;
     99     BUFFER_Q          tx_queue;             /* Queue of buffers waiting to be sent  */
    100     BUFFER_Q          rx_queue;             /* Queue of buffers waiting to be read  */
    101 
    102     UINT32            rx_queue_size;        /* Total data count in rx_queue         */
    103 
    104     tGAP_CONN_CALLBACK *p_callback;         /* Users callback function              */
    105 
    106     tL2CAP_CFG_INFO   cfg;                  /* Configuration                        */
    107     tL2CAP_ERTM_INFO  ertm_info;            /* Pools and modes for ertm */
    108 } tGAP_CCB;
    109 
    110 typedef struct
    111 {
    112 #if AMP_INCLUDED == TRUE
    113     tAMP_APPL_INFO    reg_info;
    114 #else
    115     tL2CAP_APPL_INFO  reg_info;                     /* L2CAP Registration info */
    116 #endif
    117     tGAP_CCB    ccb_pool[GAP_MAX_CONNECTIONS];
    118 } tGAP_CONN;
    119 
    120 
    121 #if BLE_INCLUDED == TRUE
    122     #define GAP_MAX_CHAR_NUM          5
    123 
    124 typedef struct
    125 {
    126     UINT16                  handle;
    127     UINT16                  uuid;
    128     tGAP_BLE_ATTR_VALUE     attr_value;
    129 }tGAP_ATTR;
    130 #endif
    131 /**********************************************************************
    132 ** M A I N   C O N T R O L   B L O C K
    133 ***********************************************************************/
    134 
    135 #define GAP_MAX_CL GATT_CL_MAX_LCB
    136 
    137 typedef struct
    138 {
    139     union
    140     {
    141         BD_ADDR         reconn_addr;
    142         UINT8           privacy_flag;
    143     }                   pending_data;
    144     UINT8               op;
    145     void                *p_pending_cback;
    146 }tGAP_BLE_PENDING_OP;
    147 
    148 typedef struct
    149 {
    150     BD_ADDR                 bda;
    151     BD_ADDR                 reconn_addr;
    152     void                    * p_cback;
    153     UINT16                  conn_id;
    154     UINT16                  cl_op_uuid;
    155     UINT16                  disc_handle;
    156     BOOLEAN                 in_use;
    157     BOOLEAN                 connected;
    158     UINT8                   privacy_flag;
    159     BUFFER_Q                pending_op_q;
    160 }tGAP_CLCB;
    161 
    162 typedef struct
    163 {
    164     tGAP_INFO        blk[GAP_MAX_BLOCKS];
    165     tBTM_CMPL_CB    *btm_cback[GAP_MAX_BLOCKS];
    166     UINT8            trace_level;
    167     tGAP_FINDADDR_CB findaddr_cb;   /* Contains the control block for finding a device addr */
    168     tBTM_INQ_INFO   *cur_inqptr;
    169 
    170 #if GAP_CONN_INCLUDED == TRUE
    171     tGAP_CONN        conn;
    172 #endif
    173 
    174     /* LE GAP attribute database */
    175 #if BLE_INCLUDED == TRUE
    176     tGAP_ATTR               gatt_attr[GAP_MAX_CHAR_NUM];
    177     BD_ADDR                 reconn_bda;
    178     tGAP_CLCB               clcb[GAP_MAX_CL]; /* connection link*/
    179 
    180     tGATT_IF                gatt_if;
    181 #endif
    182 } tGAP_CB;
    183 
    184 
    185 #ifdef __cplusplus
    186 extern "C" {
    187 #endif
    188 
    189 #if GAP_DYNAMIC_MEMORY == FALSE
    190     GAP_API extern tGAP_CB  gap_cb;
    191 #else
    192     GAP_API extern tGAP_CB *gap_cb_ptr;
    193 #define gap_cb (*gap_cb_ptr)
    194 #endif
    195 
    196     extern tGAP_INFO        *gap_allocate_cb(void);
    197     extern void              gap_free_cb(tGAP_INFO *p_cb);
    198 
    199     /* GAP inquiry functions */
    200     extern void              gap_inq_results_cb(tGAP_INQ_RESULTS *p_results, UINT8 *p_eir);
    201     extern UINT16            gap_find_local_addr_by_name (const BD_NAME devname, BD_ADDR bd_addr);
    202     extern void              gap_find_addr_inq_cb (tBTM_INQUIRY_CMPL *p);
    203 
    204     extern BOOLEAN           gap_is_service_busy (UINT16 request);
    205     extern UINT16            gap_convert_btm_status (tBTM_STATUS btm_status);
    206 
    207     extern void gap_btm_cback0(void *p1);
    208 #if GAP_MAX_BLOCKS > 1
    209     extern void gap_btm_cback1(void *p1);
    210 #endif
    211 #if GAP_MAX_BLOCKS > 2
    212     extern void gap_btm_cback2(void *p1);
    213 #endif
    214 
    215 #if (GAP_CONN_INCLUDED == TRUE)
    216     extern void gap_conn_init(void);
    217 #if (GAP_CONN_POST_EVT_INCLUDED == TRUE)
    218     void gap_send_event (UINT16 gap_handle);
    219     void gap_proc_btu_event(BT_HDR *p_msg);
    220 #endif
    221 #endif
    222 
    223 #if (BLE_INCLUDED == TRUE)
    224     extern void gap_attr_db_init(void);
    225 #endif
    226 
    227 #ifdef __cplusplus
    228 }
    229 #endif
    230 
    231 #endif
    232