1 /****************************************************************************** 2 * 3 * Copyright (C) 2010-2014 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 P2P. 22 * 23 ******************************************************************************/ 24 #ifndef NFA_P2P_INT_H 25 #define NFA_P2P_INT_H 26 27 #if (NFA_P2P_INCLUDED == TRUE) 28 #include "nfa_dm_int.h" 29 #include "nfa_p2p_api.h" 30 31 /***************************************************************************** 32 ** Constants and data types 33 *****************************************************************************/ 34 #define NFA_P2P_DEBUG BT_TRACE_VERBOSE 35 36 /* NFA P2P LLCP link state */ 37 enum { 38 NFA_P2P_LLCP_STATE_IDLE, 39 NFA_P2P_LLCP_STATE_LISTENING, 40 NFA_P2P_LLCP_STATE_ACTIVATED, 41 42 NFA_P2P_LLCP_STATE_MAX 43 }; 44 45 typedef uint8_t tNFA_P2P_LLCP_STATE; 46 47 /* NFA P2P events */ 48 enum { 49 NFA_P2P_API_REG_SERVER_EVT = NFA_SYS_EVT_START(NFA_ID_P2P), 50 NFA_P2P_API_REG_CLIENT_EVT, 51 NFA_P2P_API_DEREG_EVT, 52 NFA_P2P_API_ACCEPT_CONN_EVT, 53 NFA_P2P_API_REJECT_CONN_EVT, 54 NFA_P2P_API_DISCONNECT_EVT, 55 NFA_P2P_API_CONNECT_EVT, 56 NFA_P2P_API_SEND_UI_EVT, 57 NFA_P2P_API_SEND_DATA_EVT, 58 NFA_P2P_API_SET_LOCAL_BUSY_EVT, 59 NFA_P2P_API_GET_LINK_INFO_EVT, 60 NFA_P2P_API_GET_REMOTE_SAP_EVT, 61 NFA_P2P_API_SET_LLCP_CFG_EVT, 62 NFA_P2P_INT_RESTART_RF_DISC_EVT, 63 64 NFA_P2P_LAST_EVT 65 }; 66 67 /* data type for NFA_P2P_API_REG_SERVER_EVT */ 68 typedef struct { 69 NFC_HDR hdr; 70 uint8_t server_sap; 71 tNFA_P2P_LINK_TYPE link_type; 72 char service_name[LLCP_MAX_SN_LEN + 1]; 73 tNFA_P2P_CBACK* p_cback; 74 } tNFA_P2P_API_REG_SERVER; 75 76 /* data type for NFA_P2P_API_REG_CLIENT_EVT */ 77 typedef struct { 78 NFC_HDR hdr; 79 tNFA_P2P_LINK_TYPE link_type; 80 tNFA_P2P_CBACK* p_cback; 81 } tNFA_P2P_API_REG_CLIENT; 82 83 /* data type for NFA_P2P_API_DEREG_EVT */ 84 typedef struct { 85 NFC_HDR hdr; 86 tNFA_HANDLE handle; 87 } tNFA_P2P_API_DEREG; 88 89 /* data type for NFA_P2P_API_ACCEPT_CONN_EVT */ 90 typedef struct { 91 NFC_HDR hdr; 92 tNFA_HANDLE conn_handle; 93 uint16_t miu; 94 uint8_t rw; 95 } tNFA_P2P_API_ACCEPT_CONN; 96 97 /* data type for NFA_P2P_API_REJECT_CONN_EVT */ 98 typedef struct { 99 NFC_HDR hdr; 100 tNFA_HANDLE conn_handle; 101 } tNFA_P2P_API_REJECT_CONN; 102 103 /* data type for NFA_P2P_API_DISCONNECT_EVT */ 104 typedef struct { 105 NFC_HDR hdr; 106 tNFA_HANDLE conn_handle; 107 bool flush; 108 } tNFA_P2P_API_DISCONNECT; 109 110 /* data type for NFA_P2P_API_CONNECT_EVT */ 111 typedef struct { 112 NFC_HDR hdr; 113 tNFA_HANDLE client_handle; 114 char service_name[LLCP_MAX_SN_LEN + 1]; 115 uint8_t dsap; 116 uint16_t miu; 117 uint8_t rw; 118 } tNFA_P2P_API_CONNECT; 119 120 /* data type for NFA_P2P_API_SEND_UI_EVT */ 121 typedef struct { 122 NFC_HDR hdr; 123 tNFA_HANDLE handle; 124 uint8_t dsap; 125 NFC_HDR* p_msg; 126 } tNFA_P2P_API_SEND_UI; 127 128 /* data type for NFA_P2P_API_SEND_DATA_EVT */ 129 typedef struct { 130 NFC_HDR hdr; 131 tNFA_HANDLE conn_handle; 132 NFC_HDR* p_msg; 133 } tNFA_P2P_API_SEND_DATA; 134 135 /* data type for NFA_P2P_API_SET_LOCAL_BUSY_EVT */ 136 typedef struct { 137 NFC_HDR hdr; 138 tNFA_HANDLE conn_handle; 139 bool is_busy; 140 } tNFA_P2P_API_SET_LOCAL_BUSY; 141 142 /* data type for NFA_P2P_API_GET_LINK_INFO_EVT */ 143 typedef struct { 144 NFC_HDR hdr; 145 tNFA_HANDLE handle; 146 } tNFA_P2P_API_GET_LINK_INFO; 147 148 /* data type for NFA_P2P_API_GET_REMOTE_SAP_EVT */ 149 typedef struct { 150 NFC_HDR hdr; 151 tNFA_HANDLE handle; 152 char service_name[LLCP_MAX_SN_LEN + 1]; 153 } tNFA_P2P_API_GET_REMOTE_SAP; 154 155 /* data type for NFA_P2P_API_SET_LLCP_CFG_EVT */ 156 typedef struct { 157 NFC_HDR hdr; 158 uint16_t link_miu; 159 uint8_t opt; 160 uint8_t wt; 161 uint16_t link_timeout; 162 uint16_t inact_timeout_init; 163 uint16_t inact_timeout_target; 164 uint16_t symm_delay; 165 uint16_t data_link_timeout; 166 uint16_t delay_first_pdu_timeout; 167 } tNFA_P2P_API_SET_LLCP_CFG; 168 169 /* union of all event data types */ 170 typedef union { 171 NFC_HDR hdr; 172 tNFA_P2P_API_REG_SERVER api_reg_server; 173 tNFA_P2P_API_REG_CLIENT api_reg_client; 174 tNFA_P2P_API_DEREG api_dereg; 175 tNFA_P2P_API_ACCEPT_CONN api_accept; 176 tNFA_P2P_API_REJECT_CONN api_reject; 177 tNFA_P2P_API_DISCONNECT api_disconnect; 178 tNFA_P2P_API_CONNECT api_connect; 179 tNFA_P2P_API_SEND_UI api_send_ui; 180 tNFA_P2P_API_SEND_DATA api_send_data; 181 tNFA_P2P_API_SET_LOCAL_BUSY api_local_busy; 182 tNFA_P2P_API_GET_LINK_INFO api_link_info; 183 tNFA_P2P_API_GET_REMOTE_SAP api_remote_sap; 184 tNFA_P2P_API_SET_LLCP_CFG api_set_llcp_cfg; 185 } tNFA_P2P_MSG; 186 187 /***************************************************************************** 188 ** control block 189 *****************************************************************************/ 190 /* Bit flag for connection handle */ 191 #define NFA_P2P_HANDLE_FLAG_CONN 0x80 192 193 /* NFA P2P Connection block */ 194 /* Connection control block is used */ 195 #define NFA_P2P_CONN_FLAG_IN_USE 0x01 196 /* Remote set RW to 0 (flow off) */ 197 #define NFA_P2P_CONN_FLAG_REMOTE_RW_ZERO 0x02 198 /* data link connection is congested */ 199 #define NFA_P2P_CONN_FLAG_CONGESTED 0x04 200 201 typedef struct { 202 uint8_t flags; /* internal flags for data link connection */ 203 uint8_t local_sap; /* local SAP of data link connection */ 204 uint8_t remote_sap; /* remote SAP of data link connection */ 205 uint16_t remote_miu; /* MIU of remote end point */ 206 uint8_t num_pending_i_pdu; /* number of tx I PDU not processed by NFA */ 207 } tNFA_P2P_CONN_CB; 208 209 /* NFA P2P SAP control block */ 210 /* registered server */ 211 #define NFA_P2P_SAP_FLAG_SERVER 0x01 212 /* registered client */ 213 #define NFA_P2P_SAP_FLAG_CLIENT 0x02 214 /* logical link connection is congested */ 215 #define NFA_P2P_SAP_FLAG_LLINK_CONGESTED 0x04 216 217 typedef struct { 218 uint8_t flags; /* internal flags for local SAP */ 219 tNFA_P2P_CBACK* p_cback; /* callback function for local SAP */ 220 uint8_t num_pending_ui_pdu; /* number of tx UI PDU not processed by NFA */ 221 } tNFA_P2P_SAP_CB; 222 223 /* NFA P2P SDP control block */ 224 typedef struct { 225 uint8_t tid; /* transaction ID */ 226 uint8_t local_sap; 227 } tNFA_P2P_SDP_CB; 228 229 #define NFA_P2P_NUM_SAP 64 230 231 /* NFA P2P control block */ 232 typedef struct { 233 tNFA_HANDLE dm_disc_handle; 234 235 tNFA_DM_RF_DISC_STATE rf_disc_state; 236 tNFA_P2P_LLCP_STATE llcp_state; 237 bool is_initiator; 238 bool is_active_mode; 239 uint16_t local_link_miu; 240 uint16_t remote_link_miu; 241 242 tNFA_TECHNOLOGY_MASK listen_tech_mask; /* for P2P listening */ 243 tNFA_TECHNOLOGY_MASK 244 listen_tech_mask_to_restore; /* to retry without active listen mode */ 245 TIMER_LIST_ENT 246 active_listen_restore_timer; /* timer to restore active listen mode */ 247 bool is_p2p_listening; 248 bool is_snep_listening; 249 250 tNFA_P2P_SAP_CB sap_cb[NFA_P2P_NUM_SAP]; 251 tNFA_P2P_CONN_CB conn_cb[LLCP_MAX_DATA_LINK]; 252 tNFA_P2P_SDP_CB sdp_cb[LLCP_MAX_SDP_TRANSAC]; 253 254 uint8_t 255 total_pending_ui_pdu; /* total number of tx UI PDU not processed by NFA */ 256 uint8_t 257 total_pending_i_pdu; /* total number of tx I PDU not processed by NFA */ 258 259 uint8_t trace_level; 260 } tNFA_P2P_CB; 261 262 /***************************************************************************** 263 ** External variables 264 *****************************************************************************/ 265 266 /* NFA P2P control block */ 267 extern tNFA_P2P_CB nfa_p2p_cb; 268 269 /***************************************************************************** 270 ** External functions 271 *****************************************************************************/ 272 /* 273 ** nfa_p2p_main.c 274 */ 275 void nfa_p2p_init(void); 276 void nfa_p2p_update_listen_tech(tNFA_TECHNOLOGY_MASK tech_mask); 277 void nfa_p2p_enable_listening(tNFA_SYS_ID sys_id, bool update_wks); 278 void nfa_p2p_disable_listening(tNFA_SYS_ID sys_id, bool update_wks); 279 void nfa_p2p_activate_llcp(tNFC_DISCOVER* p_data); 280 void nfa_p2p_deactivate_llcp(void); 281 void nfa_p2p_set_config(tNFA_DM_DISC_TECH_PROTO_MASK disc_mask); 282 283 /* 284 ** nfa_p2p_act.c 285 */ 286 void nfa_p2p_proc_llcp_data_ind(tLLCP_SAP_CBACK_DATA* p_data); 287 void nfa_p2p_proc_llcp_connect_ind(tLLCP_SAP_CBACK_DATA* p_data); 288 void nfa_p2p_proc_llcp_connect_resp(tLLCP_SAP_CBACK_DATA* p_data); 289 void nfa_p2p_proc_llcp_disconnect_ind(tLLCP_SAP_CBACK_DATA* p_data); 290 void nfa_p2p_proc_llcp_disconnect_resp(tLLCP_SAP_CBACK_DATA* p_data); 291 void nfa_p2p_proc_llcp_congestion(tLLCP_SAP_CBACK_DATA* p_data); 292 void nfa_p2p_proc_llcp_link_status(tLLCP_SAP_CBACK_DATA* p_data); 293 294 bool nfa_p2p_start_sdp(char* p_service_name, uint8_t local_sap); 295 296 bool nfa_p2p_reg_server(tNFA_P2P_MSG* p_msg); 297 bool nfa_p2p_reg_client(tNFA_P2P_MSG* p_msg); 298 bool nfa_p2p_dereg(tNFA_P2P_MSG* p_msg); 299 bool nfa_p2p_accept_connection(tNFA_P2P_MSG* p_msg); 300 bool nfa_p2p_reject_connection(tNFA_P2P_MSG* p_msg); 301 bool nfa_p2p_disconnect(tNFA_P2P_MSG* p_msg); 302 bool nfa_p2p_create_data_link_connection(tNFA_P2P_MSG* p_msg); 303 bool nfa_p2p_send_ui(tNFA_P2P_MSG* p_msg); 304 bool nfa_p2p_send_data(tNFA_P2P_MSG* p_msg); 305 bool nfa_p2p_set_local_busy(tNFA_P2P_MSG* p_msg); 306 bool nfa_p2p_get_link_info(tNFA_P2P_MSG* p_msg); 307 bool nfa_p2p_get_remote_sap(tNFA_P2P_MSG* p_msg); 308 bool nfa_p2p_set_llcp_cfg(tNFA_P2P_MSG* p_msg); 309 bool nfa_p2p_restart_rf_discovery(tNFA_P2P_MSG* p_msg); 310 311 #if (BT_TRACE_VERBOSE == TRUE) 312 char* nfa_p2p_evt_code(uint16_t evt_code); 313 #endif 314 315 #else 316 317 #define nfa_p2p_init () 318 #define nfa_p2p_activate_llcp (a){}; 319 #define nfa_p2p_deactivate_llcp () 320 #define nfa_p2p_set_config () 321 322 #endif /* (NFA_P2P_INCLUDED == TRUE) */ 323 #endif /* NFA_P2P_INT_H */ 324