Home | History | Annotate | Download | only in int
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-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 /******************************************************************************
     21  *
     22  *  This file contains LLCP internal definitions
     23  *
     24  ******************************************************************************/
     25 #ifndef LLCP_INT_H
     26 #define LLCP_INT_H
     27 
     28 #include "llcp_api.h"
     29 #include "nfc_api.h"
     30 
     31 /*
     32 ** LLCP link states
     33 */
     34 enum
     35 {
     36     LLCP_LINK_STATE_DEACTIVATED,                /* llcp link is deactivated     */
     37     LLCP_LINK_STATE_ACTIVATED,                  /* llcp link has been activated */
     38     LLCP_LINK_STATE_DEACTIVATING                /* llcp link is deactivating    */
     39 };
     40 typedef UINT8 tLLCP_LINK_STATE;
     41 
     42 /*
     43 ** LLCP Symmetric state
     44 */
     45 
     46 #define LLCP_LINK_SYMM_LOCAL_XMIT_NEXT   0
     47 #define LLCP_LINK_SYMM_REMOTE_XMIT_NEXT  1
     48 
     49 /*
     50 ** LLCP internal flags
     51 */
     52 #define LLCP_LINK_FLAGS_RX_ANY_LLC_PDU      0x01    /* Received any LLC PDU in activated state */
     53 
     54 /*
     55 ** LLCP link control block
     56 */
     57 typedef struct
     58 {
     59     tLLCP_LINK_STATE    link_state;             /* llcp link state                              */
     60     tLLCP_LINK_CBACK   *p_link_cback;           /* callback function to report llcp link status */
     61     UINT16              wks;                    /* well-known service bit-map                   */
     62 
     63     BOOLEAN             is_initiator;           /* TRUE if initiator role                       */
     64     BOOLEAN             is_sending_data;        /* TRUE if llcp_link_check_send_data() is excuting    */
     65     UINT8               flags;                  /* LLCP internal flags                          */
     66     BOOLEAN             received_first_packet;  /* TRUE if a packet has been received from remote */
     67     UINT8               agreed_major_version;   /* llcp major version used in activated state   */
     68     UINT8               agreed_minor_version;   /* llcp minor version used in activated state   */
     69 
     70     UINT8               peer_version;           /* llcp version of peer device                  */
     71     UINT16              peer_miu;               /* link MIU of peer device                      */
     72     UINT16              peer_wks;               /* WKS of peer device                           */
     73     UINT16              peer_lto;               /* link timeout of peer device in ms            */
     74     UINT8               peer_opt;               /* Option field of peer device                  */
     75     UINT16              effective_miu;          /* MIU to send PDU in activated state           */
     76     TIMER_LIST_ENT      timer;                  /* link timer for LTO and SYMM response         */
     77     UINT8               symm_state;             /* state of symmectric procedure                */
     78     BOOLEAN             ll_served;              /* TRUE if last transmisstion was for UI        */
     79     UINT8               ll_idx;                 /* for scheduler of logical link connection     */
     80     UINT8               dl_idx;                 /* for scheduler of data link connection        */
     81 
     82     TIMER_LIST_ENT      inact_timer;            /* inactivity timer                             */
     83     UINT16              inact_timeout;          /* inactivity timeout in ms                     */
     84 
     85     UINT8               link_deact_reason;      /* reason of LLCP link deactivated              */
     86 
     87     BUFFER_Q            sig_xmit_q;             /* tx signaling PDU queue                       */
     88 
     89     /* runtime configuration parameters */
     90     UINT16              local_link_miu;         /* Maximum Information Unit                     */
     91     UINT8               local_opt;              /* Option parameter                             */
     92     UINT8               local_wt;               /* Response Waiting Time Index                  */
     93     UINT16              local_lto;              /* Local Link Timeout                           */
     94     UINT16              inact_timeout_init;     /* Inactivity Timeout as initiator role         */
     95     UINT16              inact_timeout_target;   /* Inactivity Timeout as target role            */
     96     UINT16              symm_delay;             /* Delay SYMM response                          */
     97     UINT16              data_link_timeout;      /* data link conneciton timeout                 */
     98     UINT16              delay_first_pdu_timeout;/* delay timeout to send first PDU as initiator */
     99 
    100 } tLLCP_LCB;
    101 
    102 /*
    103 ** LLCP Application's registration control block on service access point (SAP)
    104 */
    105 
    106 typedef struct
    107 {
    108     UINT8               link_type;              /* logical link and/or data link                */
    109     UINT8               *p_service_name;        /* GKI buffer containing service name           */
    110     tLLCP_APP_CBACK     *p_app_cback;           /* application's callback pointer               */
    111 
    112     BUFFER_Q            ui_xmit_q;              /* UI PDU queue for transmitting                */
    113     BUFFER_Q            ui_rx_q;                /* UI PDU queue for receiving                   */
    114     BOOLEAN             is_ui_tx_congested;     /* TRUE if transmitting UI PDU is congested     */
    115 
    116 } tLLCP_APP_CB;
    117 
    118 /*
    119 ** LLCP data link connection states
    120 */
    121 enum
    122 {
    123     LLCP_DLC_STATE_IDLE,            /* initial state                                    */
    124     LLCP_DLC_STATE_W4_REMOTE_RESP,  /* waiting for connection confirm from peer         */
    125     LLCP_DLC_STATE_W4_LOCAL_RESP,   /* waiting for connection confirm from upper layer  */
    126     LLCP_DLC_STATE_CONNECTED,       /* data link connection has been established        */
    127     LLCP_DLC_STATE_W4_REMOTE_DM,    /* waiting for disconnection confirm from peer      */
    128     LLCP_DLC_STATE_MAX
    129 };
    130 typedef UINT8 tLLCP_DLC_STATE;
    131 
    132 /*
    133 ** LLCP data link connection events
    134 */
    135 enum
    136 {
    137     LLCP_DLC_EVENT_API_CONNECT_REQ,      /* connection request from upper layer  */
    138     LLCP_DLC_EVENT_API_CONNECT_CFM,      /* connection confirm from upper layer  */
    139     LLCP_DLC_EVENT_API_CONNECT_REJECT,   /* connection reject from upper layer   */
    140     LLCP_DLC_EVENT_PEER_CONNECT_IND,     /* connection request from peer         */
    141     LLCP_DLC_EVENT_PEER_CONNECT_CFM,     /* connection confirm from peer         */
    142 
    143     LLCP_DLC_EVENT_API_DATA_REQ,         /* data packet from upper layer         */
    144     LLCP_DLC_EVENT_PEER_DATA_IND,        /* data packet from peer                */
    145 
    146     LLCP_DLC_EVENT_API_DISCONNECT_REQ,   /* disconnect request from upper layer  */
    147     LLCP_DLC_EVENT_PEER_DISCONNECT_IND,  /* disconnect request from peer         */
    148     LLCP_DLC_EVENT_PEER_DISCONNECT_RESP, /* disconnect response from peer        */
    149 
    150     LLCP_DLC_EVENT_FRAME_ERROR,          /* received erroneous frame from peer   */
    151     LLCP_DLC_EVENT_LINK_ERROR,           /* llcp link has been deactivated       */
    152 
    153     LLCP_DLC_EVENT_TIMEOUT               /* timeout event                        */
    154 };
    155 typedef UINT8 tLLCP_DLC_EVENT;
    156 
    157 /*
    158 ** LLCP data link connection control block
    159 */
    160 
    161 #define LLCP_DATA_LINK_FLAG_PENDING_DISC     0x01 /* send DISC when tx queue is empty       */
    162 #define LLCP_DATA_LINK_FLAG_PENDING_RR_RNR   0x02 /* send RR/RNR with valid sequence        */
    163 #define LLCP_DATA_LINK_FLAG_NOTIFY_TX_DONE   0x04 /* notify upper later when tx complete    */
    164 
    165 
    166 typedef struct
    167 {
    168     tLLCP_DLC_STATE         state;              /* data link connection state               */
    169     UINT8                   flags;              /* specific action flags                    */
    170     tLLCP_APP_CB            *p_app_cb;          /* pointer of application registration      */
    171     TIMER_LIST_ENT          timer;              /* timer for connection complete            */
    172 
    173     UINT8                   local_sap;          /* SAP of local end point                   */
    174     UINT16                  local_miu;          /* MIU of local SAP                         */
    175     UINT8                   local_rw;           /* RW of local SAP                          */
    176     BOOLEAN                 local_busy;         /* TRUE if local SAP is busy                */
    177 
    178     UINT8                   remote_sap;         /* SAP of remote end point                  */
    179     UINT16                  remote_miu;         /* MIU of remote SAP                        */
    180     UINT8                   remote_rw;          /* RW of remote SAP                         */
    181     BOOLEAN                 remote_busy;        /* TRUE if remote SAP is busy               */
    182 
    183     UINT8                   next_tx_seq;        /* V(S), send state variable                */
    184     UINT8                   rcvd_ack_seq;       /* V(SA), send ack state variable           */
    185     UINT8                   next_rx_seq;        /* V(R), receive state variable             */
    186     UINT8                   sent_ack_seq;       /* V(RA), receive ack state variable        */
    187 
    188     BUFFER_Q                i_xmit_q;           /* tx queue of I PDU                        */
    189     BOOLEAN                 is_tx_congested;    /* TRUE if tx I PDU is congested            */
    190 
    191     BUFFER_Q                i_rx_q;             /* rx queue of I PDU                        */
    192     BOOLEAN                 is_rx_congested;    /* TRUE if rx I PDU is congested            */
    193     UINT8                   num_rx_i_pdu;       /* number of I PDU in rx queue              */
    194     UINT8                   rx_congest_threshold; /* dynamic congest threshold for rx I PDU */
    195 
    196 } tLLCP_DLCB;
    197 
    198 /*
    199 ** LLCP service discovery control block
    200 */
    201 
    202 typedef struct
    203 {
    204     UINT8           tid;        /* transaction ID                           */
    205     tLLCP_SDP_CBACK *p_cback;   /* callback function for service discovery  */
    206 } tLLCP_SDP_TRANSAC;
    207 
    208 typedef struct
    209 {
    210     UINT8               next_tid;                       /* next TID to use         */
    211     tLLCP_SDP_TRANSAC   transac[LLCP_MAX_SDP_TRANSAC];  /* active SDP transactions */
    212     BT_HDR              *p_snl;                         /* buffer for SNL PDU      */
    213 } tLLCP_SDP_CB;
    214 
    215 
    216 /*
    217 ** LLCP control block
    218 */
    219 
    220 typedef struct
    221 {
    222     UINT8           trace_level;                    /* LLCP trace level                             */
    223 
    224     tLLCP_SDP_CB    sdp_cb;                         /* SDP control block                            */
    225     tLLCP_LCB       lcb;                            /* LLCP link control block                      */
    226     tLLCP_APP_CB    wks_cb[LLCP_MAX_WKS];           /* Application's registration for well-known services */
    227     tLLCP_APP_CB    server_cb[LLCP_MAX_SERVER];     /* Application's registration for SDP services  */
    228     tLLCP_APP_CB    client_cb[LLCP_MAX_CLIENT];     /* Application's registration for client        */
    229     tLLCP_DLCB      dlcb[LLCP_MAX_DATA_LINK];       /* Data link connection control block           */
    230 
    231     UINT8           max_num_ll_tx_buff;             /* max number of tx UI PDU in queue             */
    232     UINT8           max_num_tx_buff;                /* max number of tx UI/I PDU in queue           */
    233 
    234     UINT8           num_logical_data_link;          /* number of logical data link                  */
    235     UINT8           num_data_link_connection;       /* number of established data link connection   */
    236 
    237     /* these two thresholds (number of tx UI PDU) are dynamically adjusted based on number of logical links */
    238     UINT8           ll_tx_congest_start;            /* congest start threshold for each logical link*/
    239     UINT8           ll_tx_congest_end;              /* congest end threshold for each logical link  */
    240 
    241     UINT8           total_tx_ui_pdu;                /* total number of tx UI PDU in all of ui_xmit_q*/
    242     UINT8           total_tx_i_pdu;                 /* total number of tx I PDU in all of i_xmit_q  */
    243     BOOLEAN         overall_tx_congested;           /* TRUE if tx link is congested                 */
    244 
    245     /* start point of uncongested status notification is in round robin */
    246     UINT8           ll_tx_uncongest_ntf_start_sap;  /* next start of logical data link              */
    247     UINT8           dl_tx_uncongest_ntf_start_idx;  /* next start of data link connection           */
    248 
    249     /*
    250     ** when overall rx link congestion starts, RNR is sent to remote end point of data link connection
    251     ** while rx link is congested, UI PDU is discarded.
    252     */
    253     UINT8           num_rx_buff;                    /* reserved number of rx UI/I PDU in queue      */
    254     UINT8           overall_rx_congest_start;       /* threshold of overall rx congestion start     */
    255     UINT8           overall_rx_congest_end;         /* threshold of overall rx congestion end       */
    256     UINT8           max_num_ll_rx_buff;             /* max number of rx UI PDU in queue             */
    257 
    258     /*
    259     ** threshold (number of rx UI PDU) is dynamically adjusted based on number of logical links
    260     ** when number of rx UI PDU is more than ll_rx_congest_start, the oldest UI PDU is discarded
    261     */
    262     UINT8           ll_rx_congest_start;            /* rx congest start threshold for each logical link */
    263 
    264     UINT8           total_rx_ui_pdu;                /* total number of rx UI PDU in all of ui_rx_q  */
    265     UINT8           total_rx_i_pdu;                 /* total number of rx I PDU in all of i_rx_q    */
    266     BOOLEAN         overall_rx_congested;           /* TRUE if overall rx link is congested         */
    267 
    268     tLLCP_DTA_CBACK *p_dta_cback;                   /* callback to notify DTA when respoding SNL    */
    269     BOOLEAN         dta_snl_resp;                   /* TRUE if need to notify DTA when respoding SNL*/
    270 } tLLCP_CB;
    271 
    272 #if (LLCP_TEST_INCLUDED == TRUE) /* this is for LLCP testing */
    273 
    274 typedef struct {
    275     UINT8  version;
    276     UINT16 wks;
    277 } tLLCP_TEST_PARAMS;
    278 
    279 #endif
    280 
    281 #ifdef __cplusplus
    282 extern "C" {
    283 #endif
    284 
    285 
    286 /*
    287 ** LLCP global data
    288 */
    289 
    290 #if (!defined LLCP_DYNAMIC_MEMORY) || (LLCP_DYNAMIC_MEMORY == FALSE)
    291 LLCP_API extern tLLCP_CB  llcp_cb;
    292 #else
    293 LLCP_API extern tLLCP_CB *llcp_cb_ptr;
    294 #define llcp_cb (*llcp_cb_ptr)
    295 #endif
    296 
    297 /*
    298 ** Functions provided by llcp_main.c
    299 */
    300 void llcp_init (void);
    301 void llcp_cleanup (void);
    302 void llcp_process_timeout (TIMER_LIST_ENT *p_tle);
    303 
    304 /*
    305 ** Functions provided by llcp_link.c
    306 */
    307 tLLCP_STATUS llcp_link_activate (tLLCP_ACTIVATE_CONFIG *p_config);
    308 void llcp_link_process_link_timeout (void);
    309 void llcp_link_deactivate (UINT8 reason);
    310 
    311 void llcp_link_check_send_data (void);
    312 void llcp_link_connection_cback (UINT8 conn_id, tNFC_CONN_EVT event, tNFC_CONN *p_data);
    313 
    314 /*
    315 **  Functions provided by llcp_util.c
    316 */
    317 void         llcp_util_adjust_ll_congestion (void);
    318 void         llcp_util_adjust_dl_rx_congestion (void);
    319 void         llcp_util_check_rx_congested_status (void);
    320 BOOLEAN      llcp_util_parse_link_params (UINT16 length, UINT8 *p_bytes);
    321 tLLCP_STATUS llcp_util_send_ui (UINT8 ssap, UINT8 dsap, tLLCP_APP_CB *p_app_cb, BT_HDR *p_msg);
    322 void         llcp_util_send_disc (UINT8 dsap, UINT8 ssap);
    323 tLLCP_DLCB  *llcp_util_allocate_data_link (UINT8 reg_sap, UINT8 remote_sap);
    324 void         llcp_util_deallocate_data_link (tLLCP_DLCB *p_dlcb);
    325 tLLCP_STATUS llcp_util_send_connect (tLLCP_DLCB *p_dlcb, tLLCP_CONNECTION_PARAMS *p_params);
    326 tLLCP_STATUS llcp_util_parse_connect (UINT8 *p_bytes, UINT16 length, tLLCP_CONNECTION_PARAMS *p_params);
    327 tLLCP_STATUS llcp_util_send_cc (tLLCP_DLCB *p_dlcb, tLLCP_CONNECTION_PARAMS *p_params);
    328 tLLCP_STATUS llcp_util_parse_cc (UINT8 *p_bytes, UINT16 length, UINT16 *p_miu, UINT8 *p_rw);
    329 void         llcp_util_send_dm (UINT8 dsap, UINT8 ssap, UINT8 reason);
    330 void         llcp_util_build_info_pdu (tLLCP_DLCB *p_dlcb, BT_HDR *p_msg);
    331 tLLCP_STATUS llcp_util_send_frmr (tLLCP_DLCB *p_dlcb, UINT8 flags, UINT8 ptype, UINT8 sequence);
    332 void         llcp_util_send_rr_rnr (tLLCP_DLCB *p_dlcb);
    333 tLLCP_APP_CB *llcp_util_get_app_cb (UINT8 sap);
    334 /*
    335 ** Functions provided by llcp_dlc.c
    336 */
    337 tLLCP_STATUS llcp_dlsm_execute (tLLCP_DLCB *p_dlcb, tLLCP_DLC_EVENT event, void *p_data);
    338 tLLCP_DLCB  *llcp_dlc_find_dlcb_by_sap (UINT8 local_sap, UINT8 remote_sap);
    339 void         llcp_dlc_flush_q (tLLCP_DLCB *p_dlcb);
    340 void         llcp_dlc_proc_i_pdu (UINT8 dsap, UINT8 ssap, UINT16 i_pdu_length, UINT8 *p_i_pdu, BT_HDR *p_msg);
    341 void         llcp_dlc_proc_rx_pdu (UINT8 dsap, UINT8 ptype, UINT8 ssap, UINT16 length, UINT8 *p_data);
    342 void         llcp_dlc_check_to_send_rr_rnr (void);
    343 BOOLEAN      llcp_dlc_is_rw_open (tLLCP_DLCB *p_dlcb);
    344 BT_HDR      *llcp_dlc_get_next_pdu (tLLCP_DLCB *p_dlcb);
    345 UINT16       llcp_dlc_get_next_pdu_length (tLLCP_DLCB *p_dlcb);
    346 
    347 /*
    348 ** Functions provided by llcp_sdp.c
    349 */
    350 void         llcp_sdp_proc_data (tLLCP_SAP_CBACK_DATA *p_data);
    351 tLLCP_STATUS llcp_sdp_send_sdreq (UINT8 tid, char *p_name);
    352 UINT8        llcp_sdp_get_sap_by_name (char *p_name, UINT8 length);
    353 tLLCP_STATUS llcp_sdp_proc_snl (UINT16 sdu_length, UINT8 *p);
    354 void         llcp_sdp_check_send_snl (void);
    355 void         llcp_sdp_proc_deactivation (void);
    356 #ifdef __cplusplus
    357 }
    358 #endif
    359 
    360 #endif
    361