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 SNEP.
22 *
23 ******************************************************************************/
24#ifndef NFA_SNEP_INT_H
25#define NFA_SNEP_INT_H
26
27#if (NFA_SNEP_INCLUDED == TRUE)
28#include "llcp_api.h"
29#include "nfa_snep_api.h"
30
31/*****************************************************************************
32**  Constants and data types
33*****************************************************************************/
34#define NFA_SNEP_DEFAULT_SERVER_SAP 0x04 /* SNEP default server SAP   */
35#define NFA_SNEP_HEADER_SIZE 6           /* SNEP header size          */
36/* SNEP Acceptable Length size */
37#define NFA_SNEP_ACCEPT_LEN_SIZE 4
38#define NFA_SNEP_CLIENT_TIMEOUT 1000 /* ms, waiting for response  */
39
40/* NFA SNEP events */
41enum {
42  NFA_SNEP_API_START_DEFAULT_SERVER_EVT = NFA_SYS_EVT_START(NFA_ID_SNEP),
43  NFA_SNEP_API_STOP_DEFAULT_SERVER_EVT,
44  NFA_SNEP_API_REG_SERVER_EVT,
45  NFA_SNEP_API_REG_CLIENT_EVT,
46  NFA_SNEP_API_DEREG_EVT,
47  NFA_SNEP_API_CONNECT_EVT,
48  NFA_SNEP_API_GET_REQ_EVT,
49  NFA_SNEP_API_PUT_REQ_EVT,
50  NFA_SNEP_API_GET_RESP_EVT,
51  NFA_SNEP_API_PUT_RESP_EVT,
52  NFA_SNEP_API_DISCONNECT_EVT,
53
54  NFA_SNEP_LAST_EVT
55};
56
57/* data type for NFA_SNEP_API_START_DEFAULT_SERVER_EVT */
58typedef struct {
59  NFC_HDR hdr;
60  tNFA_SNEP_CBACK* p_cback;
61} tNFA_SNEP_API_START_DEFAULT_SERVER;
62
63/* data type for NFA_SNEP_API_STOP_DEFAULT_SERVER_EVT */
64typedef struct {
65  NFC_HDR hdr;
66  tNFA_SNEP_CBACK* p_cback;
67} tNFA_SNEP_API_STOP_DEFAULT_SERVER;
68
69/* data type for NFA_SNEP_API_REG_SERVER_EVT */
70typedef struct {
71  NFC_HDR hdr;
72  uint8_t server_sap;
73  char service_name[LLCP_MAX_SN_LEN + 1];
74  tNFA_SNEP_CBACK* p_cback;
75} tNFA_SNEP_API_REG_SERVER;
76
77/* data type for NFA_SNEP_API_REG_CLIENT_EVT */
78typedef struct {
79  NFC_HDR hdr;
80  tNFA_SNEP_CBACK* p_cback;
81} tNFA_SNEP_API_REG_CLIENT;
82
83/* data type for NFA_SNEP_API_DEREG_EVT */
84typedef struct {
85  NFC_HDR hdr;
86  tNFA_HANDLE reg_handle; /* handle for registered server/client */
87} tNFA_SNEP_API_DEREG;
88
89/* data type for NFA_SNEP_API_CONNECT_EVT */
90typedef struct {
91  NFC_HDR hdr;
92  tNFA_HANDLE client_handle; /* handle for client                   */
93  char service_name[LLCP_MAX_SN_LEN + 1];
94} tNFA_SNEP_API_CONNECT;
95
96/* data type for NFA_SNEP_API_GET_REQ_EVT */
97typedef struct {
98  NFC_HDR hdr;
99  tNFA_HANDLE conn_handle; /* handle for data link connection      */
100  uint32_t buff_length;    /* length of buffer; acceptable length  */
101  uint32_t ndef_length;    /* length of current NDEF message       */
102  uint8_t* p_ndef_buff;    /* buffer for NDEF message              */
103} tNFA_SNEP_API_GET_REQ;
104
105/* data type for NFA_SNEP_API_PUT_REQ_EVT */
106typedef struct {
107  NFC_HDR hdr;
108  tNFA_HANDLE conn_handle; /* handle for data link connection */
109  uint32_t ndef_length;    /* length of NDEF message          */
110  uint8_t* p_ndef_buff;    /* buffer for NDEF message         */
111} tNFA_SNEP_API_PUT_REQ;
112
113/* data type for NFA_SNEP_API_GET_RESP_EVT */
114typedef struct {
115  NFC_HDR hdr;
116  tNFA_HANDLE conn_handle;       /* handle for data link connection */
117  tNFA_SNEP_RESP_CODE resp_code; /* response code                   */
118  uint32_t ndef_length;          /* length of NDEF message          */
119  uint8_t* p_ndef_buff;          /* buffer for NDEF message         */
120} tNFA_SNEP_API_GET_RESP;
121
122/* data type for NFA_SNEP_API_PUT_RESP_EVT */
123typedef struct {
124  NFC_HDR hdr;
125  tNFA_HANDLE conn_handle;       /* handle for data link connection */
126  tNFA_SNEP_RESP_CODE resp_code; /* response code                   */
127} tNFA_SNEP_API_PUT_RESP;
128
129/* data type for NFA_SNEP_API_DISCONNECT_EVT */
130typedef struct {
131  NFC_HDR hdr;
132  tNFA_HANDLE conn_handle; /* response code                   */
133  bool flush;              /* TRUE if discard pending data    */
134} tNFA_SNEP_API_DISCONNECT;
135
136/* union of all event data types */
137typedef union {
138  NFC_HDR hdr;
139  tNFA_SNEP_API_START_DEFAULT_SERVER
140      api_start_default_server; /* NFA_SNEP_API_START_DEFAULT_SERVER_EVT */
141  tNFA_SNEP_API_STOP_DEFAULT_SERVER
142      api_stop_default_server; /* NFA_SNEP_API_STOP_DEFAULT_SERVER_EVT  */
143  tNFA_SNEP_API_REG_SERVER api_reg_server; /* NFA_SNEP_API_REG_SERVER_EVT   */
144  tNFA_SNEP_API_REG_CLIENT api_reg_client; /* NFA_SNEP_API_REG_CLIENT_EVT   */
145  tNFA_SNEP_API_DEREG api_dereg;           /* NFA_SNEP_API_DEREG_EVT        */
146  tNFA_SNEP_API_CONNECT api_connect;       /* NFA_SNEP_API_CONNECT_EVT      */
147  tNFA_SNEP_API_GET_REQ api_get_req;       /* NFA_SNEP_API_GET_REQ_EVT      */
148  tNFA_SNEP_API_PUT_REQ api_put_req;       /* NFA_SNEP_API_PUT_REQ_EVT      */
149  tNFA_SNEP_API_GET_RESP api_get_resp;     /* NFA_SNEP_API_GET_RESP_EVT     */
150  tNFA_SNEP_API_PUT_RESP api_put_resp;     /* NFA_SNEP_API_PUT_RESP_EVT     */
151  tNFA_SNEP_API_DISCONNECT api_disc;       /* NFA_SNEP_API_DISCONNECT_EVT   */
152} tNFA_SNEP_MSG;
153
154/*****************************************************************************
155**  control block
156*****************************************************************************/
157
158/* NFA SNEP service control block */
159/* ignore flags while searching   */
160#define NFA_SNEP_FLAG_ANY 0x00
161#define NFA_SNEP_FLAG_SERVER 0x01 /* server */
162#define NFA_SNEP_FLAG_CLIENT 0x02 /* client */
163/* waiting for connection confirm */
164#define NFA_SNEP_FLAG_CONNECTING 0x04
165/* data link connected            */
166#define NFA_SNEP_FLAG_CONNECTED 0x08
167/* Waiting for continue response  */
168#define NFA_SNEP_FLAG_W4_RESP_CONTINUE 0x10
169/* Waiting for continue request   */
170#define NFA_SNEP_FLAG_W4_REQ_CONTINUE 0x20
171
172typedef struct {
173  uint8_t local_sap;        /* local SAP of service */
174  uint8_t remote_sap;       /* local SAP of service */
175  uint8_t flags;            /* internal flags       */
176  tNFA_SNEP_CBACK* p_cback; /* callback for event   */
177  TIMER_LIST_ENT timer;     /* timer for client     */
178
179  uint16_t tx_miu;   /* adjusted MIU for throughput              */
180  bool congest;      /* TRUE if data link connection is congested */
181  bool rx_fragments; /* TRUE if waiting more fragments            */
182
183  uint8_t tx_code; /* transmitted code in request/response */
184  uint8_t rx_code; /* received code in request/response    */
185
186  uint32_t acceptable_length;
187  uint32_t buff_length; /* size of buffer for NDEF message   */
188  uint32_t ndef_length; /* length of NDEF message            */
189  uint32_t cur_length;  /* currently sent or received length */
190  uint8_t* p_ndef_buff; /* NDEF message buffer               */
191} tNFA_SNEP_CONN;
192
193/*
194** NFA SNEP control block
195*/
196typedef struct {
197  tNFA_SNEP_CONN conn[NFA_SNEP_MAX_CONN];
198  bool listen_enabled;
199  bool is_dta_mode;
200  uint8_t trace_level;
201} tNFA_SNEP_CB;
202
203/*
204** NFA SNEP default server control block
205*/
206
207/* multiple data link connections for default server */
208typedef struct {
209  tNFA_HANDLE conn_handle; /* connection handle for default server   */
210  uint8_t* p_rx_ndef;      /* buffer to receive NDEF                 */
211} tNFA_SNEP_DEFAULT_CONN;
212
213#define NFA_SNEP_DEFAULT_MAX_CONN 3
214
215typedef struct {
216  tNFA_HANDLE server_handle; /* registered handle for default server   */
217  tNFA_SNEP_DEFAULT_CONN
218      conn[NFA_SNEP_DEFAULT_MAX_CONN]; /* connections for default server */
219
220} tNFA_SNEP_DEFAULT_CB;
221
222/*****************************************************************************
223**  External variables
224*****************************************************************************/
225
226/* NFA SNEP control block */
227extern tNFA_SNEP_CB nfa_snep_cb;
228
229/* NFA SNEP default server control block */
230extern tNFA_SNEP_DEFAULT_CB nfa_snep_default_cb;
231
232/*****************************************************************************
233**  External functions
234*****************************************************************************/
235/*
236**  nfa_snep_main.c
237*/
238void nfa_snep_init(bool is_dta_mode);
239/*
240**  nfa_snep_default.c
241*/
242void nfa_snep_default_init(void);
243bool nfa_snep_start_default_server(tNFA_SNEP_MSG* p_msg);
244bool nfa_snep_stop_default_server(tNFA_SNEP_MSG* p_msg);
245/*
246**  nfa_snep_srv.c
247*/
248uint8_t nfa_snep_allocate_cb(void);
249void nfa_snep_deallocate_cb(uint8_t xx);
250void nfa_snep_send_msg(uint8_t opcode, uint8_t dlink);
251
252void nfa_snep_llcp_cback(tLLCP_SAP_CBACK_DATA* p_data);
253void nfa_snep_proc_llcp_data_ind(tLLCP_SAP_CBACK_DATA* p_data);
254void nfa_snep_proc_llcp_connect_ind(tLLCP_SAP_CBACK_DATA* p_data);
255void nfa_snep_proc_llcp_connect_resp(tLLCP_SAP_CBACK_DATA* p_data);
256void nfa_snep_proc_llcp_disconnect_ind(tLLCP_SAP_CBACK_DATA* p_data);
257void nfa_snep_proc_llcp_disconnect_resp(tLLCP_SAP_CBACK_DATA* p_data);
258void nfa_snep_proc_llcp_congest(tLLCP_SAP_CBACK_DATA* p_data);
259void nfa_snep_proc_llcp_link_status(tLLCP_SAP_CBACK_DATA* p_data);
260void nfa_snep_proc_llcp_tx_complete(tLLCP_SAP_CBACK_DATA* p_data);
261
262bool nfa_snep_reg_server(tNFA_SNEP_MSG* p_msg);
263bool nfa_snep_reg_client(tNFA_SNEP_MSG* p_msg);
264bool nfa_snep_dereg(tNFA_SNEP_MSG* p_msg);
265bool nfa_snep_connect(tNFA_SNEP_MSG* p_msg);
266bool nfa_snep_put_resp(tNFA_SNEP_MSG* p_msg);
267bool nfa_snep_get_resp(tNFA_SNEP_MSG* p_msg);
268bool nfa_snep_put_req(tNFA_SNEP_MSG* p_msg);
269bool nfa_snep_get_req(tNFA_SNEP_MSG* p_msg);
270bool nfa_snep_disconnect(tNFA_SNEP_MSG* p_msg);
271
272#endif /* (NFA_SNEP_INCLUDED == TRUE) */
273#endif /* NFA_SNEP_INT_H */
274