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