Home | History | Annotate | Download | only in pan
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2004-2012 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  *
     21  *  This is the private interface file for the BTA data gateway.
     22  *
     23  ******************************************************************************/
     24 #ifndef BTA_PAN_INT_H
     25 #define BTA_PAN_INT_H
     26 
     27 #include "osi/include/fixed_queue.h"
     28 #include "bta_sys.h"
     29 #include "bta_pan_api.h"
     30 
     31 /*****************************************************************************
     32 **  Constants
     33 *****************************************************************************/
     34 
     35 
     36 
     37 
     38 /* PAN events */
     39 enum
     40 {
     41     /* these events are handled by the state machine */
     42     BTA_PAN_API_CLOSE_EVT = BTA_SYS_EVT_START(BTA_ID_PAN),
     43     BTA_PAN_CI_TX_READY_EVT,
     44     BTA_PAN_CI_RX_READY_EVT,
     45     BTA_PAN_CI_TX_FLOW_EVT,
     46     BTA_PAN_CI_RX_WRITE_EVT,
     47     BTA_PAN_CI_RX_WRITEBUF_EVT,
     48     BTA_PAN_CONN_OPEN_EVT,
     49     BTA_PAN_CONN_CLOSE_EVT,
     50     BTA_PAN_BNEP_FLOW_ENABLE_EVT,
     51     BTA_PAN_RX_FROM_BNEP_READY_EVT,
     52 
     53     /* these events are handled outside of the state machine */
     54     BTA_PAN_API_ENABLE_EVT,
     55     BTA_PAN_API_DISABLE_EVT,
     56     BTA_PAN_API_SET_ROLE_EVT,
     57     BTA_PAN_API_OPEN_EVT
     58 };
     59 
     60 /* state machine states */
     61 enum
     62 {
     63     BTA_PAN_IDLE_ST,
     64     BTA_PAN_OPEN_ST,
     65     BTA_PAN_CLOSING_ST
     66 };
     67 
     68 
     69 
     70 
     71 /*****************************************************************************
     72 **  Data types
     73 *****************************************************************************/
     74 
     75 /* data type for BTA_PAN_API_ENABLE_EVT */
     76 typedef struct
     77 {
     78     BT_HDR              hdr;                        /* Event header */
     79     tBTA_PAN_CBACK     *p_cback;                    /* PAN callback function */
     80 } tBTA_PAN_API_ENABLE;
     81 
     82 /* data type for BTA_PAN_API_REG_ROLE_EVT */
     83 typedef struct
     84 {
     85     BT_HDR              hdr;                             /* Event header */
     86     char                user_name[BTA_SERVICE_NAME_LEN+1];   /* Service name */
     87     char                gn_name[BTA_SERVICE_NAME_LEN+1];     /* Service name */
     88     char                nap_name[BTA_SERVICE_NAME_LEN+1];    /* Service name */
     89     tBTA_PAN_ROLE       role;
     90     UINT8               user_app_id;
     91     UINT8               gn_app_id;
     92     UINT8               nap_app_id;
     93     tBTA_SEC            user_sec_mask;                   /* Security mask */
     94     tBTA_SEC            gn_sec_mask;                     /* Security mask */
     95     tBTA_SEC            nap_sec_mask;                    /* Security mask */
     96 
     97 
     98 } tBTA_PAN_API_SET_ROLE;
     99 
    100 /* data type for BTA_PAN_API_OPEN_EVT */
    101 typedef struct
    102 {
    103     BT_HDR              hdr;                        /* Event header */
    104     tBTA_PAN_ROLE        local_role;                 /* local role */
    105     tBTA_PAN_ROLE        peer_role;                  /* peer role */
    106     BD_ADDR             bd_addr;                    /* peer bdaddr */
    107 } tBTA_PAN_API_OPEN;
    108 
    109 /* data type for BTA_PAN_CI_TX_FLOW_EVT */
    110 typedef struct
    111 {
    112     BT_HDR          hdr;                    /* Event header */
    113     BOOLEAN         enable;                 /* Flow control setting */
    114 } tBTA_PAN_CI_TX_FLOW;
    115 
    116 /* data type for BTA_PAN_CONN_OPEN_EVT */
    117 typedef struct
    118 {
    119     BT_HDR          hdr;        /* Event header */
    120     tPAN_RESULT     result;
    121 
    122 } tBTA_PAN_CONN;
    123 
    124 
    125 
    126 
    127 /* union of all data types */
    128 typedef union
    129 {
    130     BT_HDR                   hdr;
    131     tBTA_PAN_API_ENABLE      api_enable;
    132     tBTA_PAN_API_SET_ROLE    api_set_role;
    133     tBTA_PAN_API_OPEN        api_open;
    134     tBTA_PAN_CI_TX_FLOW      ci_tx_flow;
    135     tBTA_PAN_CONN            conn;
    136 } tBTA_PAN_DATA;
    137 
    138 /* state machine control block */
    139 typedef struct
    140 {
    141     BD_ADDR                 bd_addr;        /* peer bdaddr */
    142     fixed_queue_t           *data_queue;    /* Queue of buffers waiting to be passed to application */
    143     UINT16                  handle;         /* BTA PAN/BNEP handle */
    144     BOOLEAN                 in_use;         /* scb in use */
    145     tBTA_SEC                sec_mask;       /* Security mask */
    146     BOOLEAN                 pan_flow_enable;/* BNEP flow control state */
    147     BOOLEAN                 app_flow_enable;/* Application flow control state */
    148     UINT8                   state;          /* State machine state */
    149     tBTA_PAN_ROLE            local_role;     /* local role */
    150     tBTA_PAN_ROLE            peer_role;      /* peer role */
    151     UINT8                    app_id;         /* application id for the connection */
    152 
    153 } tBTA_PAN_SCB;
    154 
    155 
    156 
    157 /* main control block */
    158 typedef struct
    159 {
    160     tBTA_PAN_SCB    scb[BTA_PAN_NUM_CONN];          /* state machine control blocks */
    161     tBTA_PAN_CBACK *p_cback;                        /* PAN callback function */
    162     UINT8            app_id[3];                      /* application id for PAN roles */
    163     UINT8           flow_mask;                      /* Data flow mask */
    164     UINT8           q_level;                        /* queue level set by application for TX data */
    165 
    166 } tBTA_PAN_CB;
    167 
    168 
    169 /* pan data param */
    170 typedef struct
    171 {
    172     BT_HDR  hdr;
    173     BD_ADDR src;
    174     BD_ADDR dst;
    175     UINT16  protocol;
    176     BOOLEAN ext;
    177     BOOLEAN forward;
    178 
    179 } tBTA_PAN_DATA_PARAMS;
    180 
    181 
    182 /*****************************************************************************
    183 **  Global data
    184 *****************************************************************************/
    185 
    186 /* PAN control block */
    187 
    188 #if BTA_DYNAMIC_MEMORY == FALSE
    189 extern tBTA_PAN_CB  bta_pan_cb;
    190 #else
    191 extern tBTA_PAN_CB *bta_pan_cb_ptr;
    192 #define bta_pan_cb (*bta_pan_cb_ptr)
    193 #endif
    194 
    195 /*****************************************************************************
    196 **  Function prototypes
    197 *****************************************************************************/
    198 extern tBTA_PAN_SCB *bta_pan_scb_alloc(void);
    199 extern void bta_pan_scb_dealloc(tBTA_PAN_SCB *p_scb);
    200 extern UINT8 bta_pan_scb_to_idx(tBTA_PAN_SCB *p_scb);
    201 extern tBTA_PAN_SCB *bta_pan_scb_by_handle(UINT16 handle);
    202 extern BOOLEAN bta_pan_hdl_event(BT_HDR *p_msg);
    203 
    204 /* action functions */
    205 extern void bta_pan_enable(tBTA_PAN_DATA *p_data);
    206 extern void bta_pan_disable(void);
    207 extern void bta_pan_set_role(tBTA_PAN_DATA *p_data);
    208 extern void bta_pan_open(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    209 extern void bta_pan_api_close(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    210 extern void bta_pan_set_shutdown(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    211 extern void bta_pan_rx_path(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    212 extern void bta_pan_tx_path(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    213 extern void bta_pan_tx_flow(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    214 extern void bta_pan_conn_open(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    215 extern void bta_pan_conn_close(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    216 extern void bta_pan_writebuf(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    217 extern void bta_pan_write_buf(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    218 extern void bta_pan_free_buf(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data);
    219 
    220 
    221 #endif /* BTA_PAN_INT_H */
    222