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