Home | History | Annotate | Download | only in int
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-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 NFA Connection Handover.
     22  *
     23  ******************************************************************************/
     24 #ifndef NFA_CHO_INT_H
     25 #define NFA_CHO_INT_H
     26 
     27 #if (defined (NFA_CHO_INCLUDED) && (NFA_CHO_INCLUDED==TRUE))
     28 #include "llcp_api.h"
     29 #include "llcp_defs.h"
     30 #include "nfa_cho_api.h"
     31 
     32 /*****************************************************************************
     33 **  Constants and data types
     34 *****************************************************************************/
     35 
     36 /* NFA Connection Handover state */
     37 enum
     38 {
     39     NFA_CHO_ST_DISABLED,        /* Application has not registered      */
     40     NFA_CHO_ST_IDLE,            /* No data link connection             */
     41     NFA_CHO_ST_W4_CC,           /* Waiting for connection confirm      */
     42     NFA_CHO_ST_CONNECTED,       /* Data link connected                 */
     43 
     44     NFA_CHO_ST_MAX
     45 };
     46 
     47 typedef UINT8 tNFA_CHO_STATE;
     48 
     49 /* NFA Connection Handover substate in NFA_CHO_ST_CONNECTED */
     50 enum
     51 {
     52     NFA_CHO_SUBSTATE_W4_LOCAL_HR,   /* Waiting for Hs record from local     */
     53     NFA_CHO_SUBSTATE_W4_LOCAL_HS,   /* Waiting for Hs record from local     */
     54     NFA_CHO_SUBSTATE_W4_REMOTE_HR,  /* Waiting for Hr record from remote    */
     55     NFA_CHO_SUBSTATE_W4_REMOTE_HS,  /* Waiting for Hs record from remote    */
     56 
     57     NFA_CHO_SUBSTATE_MAX
     58 };
     59 
     60 typedef UINT8 tNFA_CHO_SUBSTATE;
     61 
     62 /* Handover Message receiving status for SAR */
     63 #define NFA_CHO_RX_NDEF_COMPLETE    0   /* received complete NDEF message */
     64 #define NFA_CHO_RX_NDEF_TEMP_MEM    1   /* Cannot process due to temporary memory constraint */
     65 #define NFA_CHO_RX_NDEF_PERM_MEM    2   /* Cannot process due to permanent memory constraint */
     66 #define NFA_CHO_RX_NDEF_INCOMPLTE   3   /* Need more date       */
     67 #define NFA_CHO_RX_NDEF_INVALID     4   /* Invalid NDEF message */
     68 
     69 typedef UINT8 tNFA_CHO_RX_NDEF_STATUS;
     70 
     71 /* Handover Message Type */
     72 #define NFA_CHO_MSG_UNKNOWN         0   /* Unknown Message           */
     73 #define NFA_CHO_MSG_HR              1   /* Handover Request Message  */
     74 #define NFA_CHO_MSG_HS              2   /* Handover Select Message   */
     75 #define NFA_CHO_MSG_BT_OOB          3   /* Simplified BT OOB message */
     76 #define NFA_CHO_MSG_WIFI            4   /* Simplified WIFI message   */
     77 
     78 typedef UINT8 tNFA_CHO_MSG_TYPE;
     79 
     80 /* Timeout */
     81 #define NFA_CHO_TIMEOUT_FOR_HS          1000    /* ms, waiting for Hs record */
     82 #define NFA_CHO_TIMEOUT_FOR_RETRY       1000    /* ms, retry because of temp memory constrain */
     83 #define NFA_CHO_TIMEOUT_SEGMENTED_HR    500     /* ms, waiting for next segmented Hr */
     84 
     85 #define NFA_CHO_EXCLUDING_PAYLOAD_ID    0xFF    /* don't include payload ID string */
     86 
     87 /* NFA Connection Handover internal events */
     88 enum
     89 {
     90     NFA_CHO_API_REG_EVT     = NFA_SYS_EVT_START (NFA_ID_CHO), /* NFA_ChoRegister () */
     91     NFA_CHO_API_DEREG_EVT,            /* NFA_ChoDeregister ()       */
     92     NFA_CHO_API_CONNECT_EVT,          /* NFA_ChoConnect ()          */
     93     NFA_CHO_API_DISCONNECT_EVT,       /* NFA_ChoDisconnect ()       */
     94     NFA_CHO_API_SEND_HR_EVT,          /* NFA_ChoSendHr ()           */
     95     NFA_CHO_API_SEND_HS_EVT,          /* NFA_ChoSendHs ()           */
     96     NFA_CHO_API_SEL_ERR_EVT,          /* NFA_ChoSendSelectError ()  */
     97 
     98     NFA_CHO_RX_HANDOVER_MSG_EVT,      /* Received Handover Message  */
     99 
    100     NFA_CHO_LLCP_CONNECT_IND_EVT,     /* LLCP_SAP_EVT_CONNECT_IND       */
    101     NFA_CHO_LLCP_CONNECT_RESP_EVT,    /* LLCP_SAP_EVT_CONNECT_RESP      */
    102     NFA_CHO_LLCP_DISCONNECT_IND_EVT,  /* LLCP_SAP_EVT_DISCONNECT_IND    */
    103     NFA_CHO_LLCP_DISCONNECT_RESP_EVT, /* LLCP_SAP_EVT_DISCONNECT_RESP   */
    104     NFA_CHO_LLCP_CONGEST_EVT,         /* LLCP_SAP_EVT_CONGEST           */
    105     NFA_CHO_LLCP_LINK_STATUS_EVT,     /* LLCP_SAP_EVT_LINK_STATUS       */
    106 
    107     NFA_CHO_NDEF_TYPE_HANDLER_EVT,    /* Callback event from NDEF Type handler */
    108     NFA_CHO_TIMEOUT_EVT,              /* Timeout event              */
    109 
    110     NFA_CHO_LAST_EVT
    111 };
    112 
    113 typedef UINT16 tNFA_CHO_INT_EVT;
    114 
    115 /* data type for NFA_CHO_API_REG_EVT */
    116 typedef struct
    117 {
    118     BT_HDR              hdr;
    119     BOOLEAN             enable_server;
    120     tNFA_CHO_CBACK     *p_cback;
    121 } tNFA_CHO_API_REG;
    122 
    123 /* data type for NFA_CHO_API_DEREG_EVT */
    124 typedef BT_HDR tNFA_CHO_API_DEREG;
    125 
    126 /* data type for NFA_CHO_API_CONNECT_EVT */
    127 typedef BT_HDR tNFA_CHO_API_CONNECT;
    128 
    129 /* data type for NFA_CHO_API_DISCONNECT_EVT */
    130 typedef BT_HDR tNFA_CHO_API_DISCONNECT;
    131 
    132 /* data type for NFA_CHO_API_SEND_HR_EVT */
    133 typedef struct
    134 {
    135     BT_HDR              hdr;
    136     UINT8               num_ac_info;
    137     tNFA_CHO_AC_INFO   *p_ac_info;
    138     UINT8              *p_ndef;
    139     UINT32              max_ndef_size;
    140     UINT32              cur_ndef_size;
    141 } tNFA_CHO_API_SEND_HR;
    142 
    143 /* data type for NFA_CHO_API_SEND_HS_EVT */
    144 typedef struct
    145 {
    146     BT_HDR              hdr;
    147     UINT8               num_ac_info;
    148     tNFA_CHO_AC_INFO   *p_ac_info;
    149     UINT8              *p_ndef;
    150     UINT32              max_ndef_size;
    151     UINT32              cur_ndef_size;
    152 } tNFA_CHO_API_SEND_HS;
    153 
    154 /* data type for NFA_CHO_API_STOP_EVT */
    155 typedef BT_HDR tNFA_CHO_API_STOP;
    156 
    157 /* data type for NFA_CHO_API_SEL_ERR_EVT */
    158 typedef struct
    159 {
    160     BT_HDR              hdr;
    161     UINT8               error_reason;
    162     UINT32              error_data;
    163 } tNFA_CHO_API_SEL_ERR;
    164 
    165 /* data type for NFA_CHO_NDEF_TYPE_HANDLER_EVT */
    166 typedef struct
    167 {
    168     BT_HDR              hdr;
    169     tNFA_NDEF_EVT       event;
    170     tNFA_NDEF_EVT_DATA  data;
    171 } tNFA_CHO_NDEF_TYPE_HDLR_EVT;
    172 
    173 /* union of all event data types */
    174 typedef union
    175 {
    176     BT_HDR                      hdr;                /* NFA_CHO_TIMEOUT_EVT        */
    177     tNFA_CHO_API_REG            api_reg;            /* NFA_CHO_API_REG_EVT        */
    178     tNFA_CHO_API_DEREG          api_dereg;          /* NFA_CHO_API_DEREG_EVT      */
    179     tNFA_CHO_API_CONNECT        api_connect;        /* NFA_CHO_API_CONNECT_EVT    */
    180     tNFA_CHO_API_DISCONNECT     api_disconnect;     /* NFA_CHO_API_DISCONNECT_EVT */
    181     tNFA_CHO_API_SEND_HR        api_send_hr;        /* NFA_CHO_API_SEND_HR_EVT    */
    182     tNFA_CHO_API_SEND_HS        api_send_hs;        /* NFA_CHO_API_SEND_HS_EVT    */
    183     tNFA_CHO_API_SEL_ERR        api_sel_err;        /* NFA_CHO_API_SEL_ERR_EVT    */
    184     tNFA_CHO_NDEF_TYPE_HDLR_EVT ndef_type_hdlr;     /* NFA_CHO_NDEF_TYPE_HANDLER_EVT */
    185     tLLCP_SAP_CBACK_DATA        llcp_cback_data;    /* LLCP callback data         */
    186 } tNFA_CHO_INT_EVENT_DATA;
    187 
    188 /*****************************************************************************
    189 **  control block
    190 *****************************************************************************/
    191 
    192 #define NFA_CHO_FLAGS_LLCP_ACTIVATED    0x01
    193 #define NFA_CHO_FLAGS_CLIENT_ONLY       0x02    /* Handover server is not enabled       */
    194 #define NFA_CHO_FLAGS_CONN_COLLISION    0x04    /* collision when creating data link    */
    195 
    196 /* NFA Connection Handover control block */
    197 typedef struct
    198 {
    199     tNFA_CHO_STATE      state;                  /* main state                           */
    200     tNFA_CHO_SUBSTATE   substate;               /* substate in connected state          */
    201     TIMER_LIST_ENT      timer;                  /* timer for rx handover message        */
    202 
    203     UINT8               server_sap;             /* SAP for local handover server        */
    204     UINT8               client_sap;             /* SAP for connection to remote handover server */
    205     UINT8               local_sap;              /* SSAP for connection, either server_sap or client_sap */
    206     UINT8               remote_sap;             /* DSAP for connection                  */
    207 
    208     UINT8               flags;                  /* internal flags                       */
    209     tNFA_CHO_DISC_REASON disc_reason;           /* disconnection reason                 */
    210 
    211     tNFA_HANDLE         hs_ndef_type_handle;    /* handle for HS NDEF Type handler      */
    212     tNFA_HANDLE         bt_ndef_type_handle;    /* handle for BT OOB NDEF Type handler  */
    213     tNFA_HANDLE         wifi_ndef_type_handle;  /* handle for WiFi NDEF Type handler    */
    214 
    215     UINT16              local_link_miu;         /* MIU of local LLCP                    */
    216     UINT16              remote_miu;             /* peer's MIU of data link connection   */
    217     BOOLEAN             congested;              /* TRUE if data link is congested       */
    218 
    219     UINT8               collision_local_sap;    /* SSAP for collision connection        */
    220     UINT8               collision_remote_sap;   /* DSAP for collision connection        */
    221     UINT16              collision_remote_miu;   /* peer's MIU of collision  connection  */
    222     BOOLEAN             collision_congested;    /* TRUE if collision connection is congested */
    223 
    224     UINT16              tx_random_number;       /* it has been sent in Hr for collision */
    225 
    226     UINT8              *p_tx_ndef_msg;          /* allocate buffer for tx NDEF msg      */
    227     UINT32              tx_ndef_cur_size;       /* current size of NDEF message         */
    228     UINT32              tx_ndef_sent_size;      /* transmitted size of NDEF message     */
    229 
    230     UINT8              *p_rx_ndef_msg;          /* allocate buffer for rx NDEF msg      */
    231     UINT32              rx_ndef_buf_size;       /* allocate buffer size for rx NDEF msg */
    232     UINT32              rx_ndef_cur_size;       /* current rx size of NDEF message      */
    233 
    234     tNFA_CHO_CBACK     *p_cback;                /* callback registered by application   */
    235 
    236     UINT8               trace_level;
    237 
    238 #if (defined (NFA_CHO_TEST_INCLUDED) && (NFA_CHO_TEST_INCLUDED == TRUE))
    239     UINT8               test_enabled;
    240     UINT8               test_version;
    241     UINT16              test_random_number;
    242 #endif
    243 } tNFA_CHO_CB;
    244 
    245 /*****************************************************************************
    246 **  External variables
    247 *****************************************************************************/
    248 
    249 /* NFA Connection Handover control block */
    250 #if NFA_DYNAMIC_MEMORY == FALSE
    251 extern tNFA_CHO_CB nfa_cho_cb;
    252 #else
    253 extern tNFA_CHO_CB *nfa_cho_cb_ptr;
    254 #define nfa_cho_cb (*nfa_cho_cb_ptr)
    255 #endif
    256 
    257 /*****************************************************************************
    258 **  External functions
    259 *****************************************************************************/
    260 /* nfa_cho_main.c */
    261 void nfa_cho_init (void);
    262 
    263 /* nfa_cho_sm.c */
    264 void nfa_cho_sm_llcp_cback (tLLCP_SAP_CBACK_DATA *p_data);
    265 void nfa_cho_sm_execute (tNFA_CHO_INT_EVT event, tNFA_CHO_INT_EVENT_DATA *p_evt_data);
    266 
    267 /* nfa_cho_util.c */
    268 void nfa_cho_proc_ndef_type_handler_evt (tNFA_CHO_INT_EVENT_DATA *p_evt_data);
    269 tNFA_STATUS nfa_cho_proc_api_reg (tNFA_CHO_INT_EVENT_DATA *p_evt_data);
    270 void        nfa_cho_proc_api_dereg (void);
    271 tNFA_STATUS nfa_cho_create_connection (void);
    272 void nfa_cho_process_disconnection (tNFA_CHO_DISC_REASON disc_reason);
    273 void nfa_cho_notify_tx_fail_evt (tNFA_STATUS status);
    274 
    275 tNFA_STATUS nfa_cho_send_handover_msg (void);
    276 tNFA_CHO_RX_NDEF_STATUS nfa_cho_read_ndef_msg (UINT8 local_sap, UINT8 remote_sap);
    277 tNFA_CHO_RX_NDEF_STATUS nfa_cho_reassemble_ho_msg (UINT8 local_sap, UINT8 remote_sap);
    278 
    279 tNFA_STATUS nfa_cho_send_hr (tNFA_CHO_API_SEND_HR *p_api_send_hr);
    280 tNFA_STATUS nfa_cho_send_hs (tNFA_CHO_API_SEND_HS *p_api_select);
    281 tNFA_STATUS nfa_cho_send_hs_error (UINT8 error_reason, UINT32 error_data);
    282 
    283 void nfa_cho_proc_hr (UINT32 length, UINT8 *p_ndef_msg);
    284 void nfa_cho_proc_hs (UINT32 length, UINT8 *p_ndef_msg);
    285 void nfa_cho_proc_simplified_format (UINT32 length, UINT8 *p_ndef_msg);
    286 
    287 tNFA_CHO_MSG_TYPE  nfa_cho_get_msg_type (UINT32 length, UINT8 *p_ndef_msg);
    288 tNFA_CHO_ROLE_TYPE nfa_cho_get_local_device_role (UINT32 length, UINT8 *p_ndef_msg);
    289 tNFA_STATUS nfa_cho_update_random_number (UINT8 *p_ndef_msg);
    290 #else
    291 
    292 #define nfa_cho_init ()
    293 
    294 #endif /* (defined (NFA_CHO_INCLUDED) && (NFA_CHO_INCLUDED==TRUE)) */
    295 #endif /* NFA_CHO_INT_H */
    296