summaryrefslogtreecommitdiff
path: root/src/nfa/int/nfa_p2p_int.h
blob: 09647473e8bd66ac12a9d30a38cd81b83c813e31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/******************************************************************************
 *
 *  Copyright (C) 2010-2014 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/


/******************************************************************************
 *
 *  This is the private interface file for the NFA P2P.
 *
 ******************************************************************************/
#ifndef NFA_P2P_INT_H
#define NFA_P2P_INT_H

#if (defined (NFA_P2P_INCLUDED) && (NFA_P2P_INCLUDED==TRUE))
#include "nfa_p2p_api.h"
#include "nfa_dm_int.h"

/*****************************************************************************
**  Constants and data types
*****************************************************************************/
#define NFA_P2P_DEBUG   BT_TRACE_VERBOSE

/* NFA P2P LLCP link state */
enum
{
    NFA_P2P_LLCP_STATE_IDLE,
    NFA_P2P_LLCP_STATE_LISTENING,
    NFA_P2P_LLCP_STATE_ACTIVATED,

    NFA_P2P_LLCP_STATE_MAX
};

typedef UINT8 tNFA_P2P_LLCP_STATE;

/* NFA P2P events */
enum
{
    NFA_P2P_API_REG_SERVER_EVT  = NFA_SYS_EVT_START (NFA_ID_P2P),
    NFA_P2P_API_REG_CLIENT_EVT,
    NFA_P2P_API_DEREG_EVT,
    NFA_P2P_API_ACCEPT_CONN_EVT,
    NFA_P2P_API_REJECT_CONN_EVT,
    NFA_P2P_API_DISCONNECT_EVT,
    NFA_P2P_API_CONNECT_EVT,
    NFA_P2P_API_SEND_UI_EVT,
    NFA_P2P_API_SEND_DATA_EVT,
    NFA_P2P_API_SET_LOCAL_BUSY_EVT,
    NFA_P2P_API_GET_LINK_INFO_EVT,
    NFA_P2P_API_GET_REMOTE_SAP_EVT,
    NFA_P2P_API_SET_LLCP_CFG_EVT,
    NFA_P2P_INT_RESTART_RF_DISC_EVT,

    NFA_P2P_LAST_EVT
};

/* data type for NFA_P2P_API_REG_SERVER_EVT */
typedef struct
{
    BT_HDR              hdr;
    UINT8               server_sap;
    tNFA_P2P_LINK_TYPE  link_type;
    char                service_name[LLCP_MAX_SN_LEN + 1];
    tNFA_P2P_CBACK     *p_cback;
} tNFA_P2P_API_REG_SERVER;

/* data type for NFA_P2P_API_REG_CLIENT_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_P2P_LINK_TYPE  link_type;
    tNFA_P2P_CBACK     *p_cback;
} tNFA_P2P_API_REG_CLIENT;

/* data type for NFA_P2P_API_DEREG_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         handle;
} tNFA_P2P_API_DEREG;

/* data type for NFA_P2P_API_ACCEPT_CONN_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         conn_handle;
    UINT16              miu;
    UINT8               rw;
} tNFA_P2P_API_ACCEPT_CONN;

/* data type for NFA_P2P_API_REJECT_CONN_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         conn_handle;
} tNFA_P2P_API_REJECT_CONN;

/* data type for NFA_P2P_API_DISCONNECT_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         conn_handle;
    BOOLEAN             flush;
} tNFA_P2P_API_DISCONNECT;

/* data type for NFA_P2P_API_CONNECT_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         client_handle;
    char                service_name[LLCP_MAX_SN_LEN + 1];
    UINT8               dsap;
    UINT16              miu;
    UINT8               rw;
} tNFA_P2P_API_CONNECT;

/* data type for NFA_P2P_API_SEND_UI_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         handle;
    UINT8               dsap;
    BT_HDR             *p_msg;
} tNFA_P2P_API_SEND_UI;

/* data type for NFA_P2P_API_SEND_DATA_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         conn_handle;
    BT_HDR             *p_msg;
} tNFA_P2P_API_SEND_DATA;

/* data type for NFA_P2P_API_SET_LOCAL_BUSY_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         conn_handle;
    BOOLEAN             is_busy;
} tNFA_P2P_API_SET_LOCAL_BUSY;

/* data type for NFA_P2P_API_GET_LINK_INFO_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         handle;
} tNFA_P2P_API_GET_LINK_INFO;

/* data type for NFA_P2P_API_GET_REMOTE_SAP_EVT */
typedef struct
{
    BT_HDR              hdr;
    tNFA_HANDLE         handle;
    char                service_name[LLCP_MAX_SN_LEN + 1];
} tNFA_P2P_API_GET_REMOTE_SAP;

/* data type for NFA_P2P_API_SET_LLCP_CFG_EVT */
typedef struct
{
    BT_HDR              hdr;
    UINT16              link_miu;
    UINT8               opt;
    UINT8               wt;
    UINT16              link_timeout;
    UINT16              inact_timeout_init;
    UINT16              inact_timeout_target;
    UINT16              symm_delay;
    UINT16              data_link_timeout;
    UINT16              delay_first_pdu_timeout;
} tNFA_P2P_API_SET_LLCP_CFG;

/* union of all event data types */
typedef union
{
    BT_HDR                      hdr;
    tNFA_P2P_API_REG_SERVER     api_reg_server;
    tNFA_P2P_API_REG_CLIENT     api_reg_client;
    tNFA_P2P_API_DEREG          api_dereg;
    tNFA_P2P_API_ACCEPT_CONN    api_accept;
    tNFA_P2P_API_REJECT_CONN    api_reject;
    tNFA_P2P_API_DISCONNECT     api_disconnect;
    tNFA_P2P_API_CONNECT        api_connect;
    tNFA_P2P_API_SEND_UI        api_send_ui;
    tNFA_P2P_API_SEND_DATA      api_send_data;
    tNFA_P2P_API_SET_LOCAL_BUSY api_local_busy;
    tNFA_P2P_API_GET_LINK_INFO  api_link_info;
    tNFA_P2P_API_GET_REMOTE_SAP api_remote_sap;
    tNFA_P2P_API_SET_LLCP_CFG   api_set_llcp_cfg;
} tNFA_P2P_MSG;

/*****************************************************************************
**  control block
*****************************************************************************/
#define NFA_P2P_HANDLE_FLAG_CONN             0x80   /* Bit flag for connection handle           */

/* NFA P2P Connection block */
#define NFA_P2P_CONN_FLAG_IN_USE             0x01   /* Connection control block is used         */
#define NFA_P2P_CONN_FLAG_REMOTE_RW_ZERO     0x02   /* Remote set RW to 0 (flow off)            */
#define NFA_P2P_CONN_FLAG_CONGESTED          0x04   /* data link connection is congested        */

typedef struct
{
    UINT8               flags;                      /* internal flags for data link connection  */
    UINT8               local_sap;                  /* local SAP of data link connection        */
    UINT8               remote_sap;                 /* remote SAP of data link connection       */
    UINT16              remote_miu;                 /* MIU of remote end point                  */
    UINT8               num_pending_i_pdu;          /* number of tx I PDU not processed by NFA  */
} tNFA_P2P_CONN_CB;

/* NFA P2P SAP control block */
#define NFA_P2P_SAP_FLAG_SERVER             0x01    /* registered server                        */
#define NFA_P2P_SAP_FLAG_CLIENT             0x02    /* registered client                        */
#define NFA_P2P_SAP_FLAG_LLINK_CONGESTED    0x04    /* logical link connection is congested     */

typedef struct
{
    UINT8              flags;                       /* internal flags for local SAP             */
    tNFA_P2P_CBACK     *p_cback;                    /* callback function for local SAP          */
    UINT8              num_pending_ui_pdu;          /* number of tx UI PDU not processed by NFA */
} tNFA_P2P_SAP_CB;

/* NFA P2P SDP control block */
typedef struct
{
    UINT8            tid;                           /* transaction ID */
    UINT8            local_sap;
} tNFA_P2P_SDP_CB;

#define NFA_P2P_NUM_SAP         64

/* NFA P2P control block */
typedef struct
{
    tNFA_HANDLE         dm_disc_handle;

    tNFA_DM_RF_DISC_STATE rf_disc_state;
    tNFA_P2P_LLCP_STATE llcp_state;
    BOOLEAN             is_initiator;
    BOOLEAN             is_active_mode;
    UINT16              local_link_miu;
    UINT16              remote_link_miu;

    tNFA_TECHNOLOGY_MASK listen_tech_mask;          /* for P2P listening */
    tNFA_TECHNOLOGY_MASK listen_tech_mask_to_restore;/* to retry without active listen mode */
    TIMER_LIST_ENT      active_listen_restore_timer; /* timer to restore active listen mode */
    BOOLEAN             is_p2p_listening;
    BOOLEAN             is_cho_listening;
    BOOLEAN             is_snep_listening;

    tNFA_P2P_SAP_CB     sap_cb[NFA_P2P_NUM_SAP];
    tNFA_P2P_CONN_CB    conn_cb[LLCP_MAX_DATA_LINK];
    tNFA_P2P_SDP_CB     sdp_cb[LLCP_MAX_SDP_TRANSAC];

    UINT8               total_pending_ui_pdu;       /* total number of tx UI PDU not processed by NFA */
    UINT8               total_pending_i_pdu;        /* total number of tx I PDU not processed by NFA */

    UINT8               trace_level;
} tNFA_P2P_CB;

/*****************************************************************************
**  External variables
*****************************************************************************/

/* NFA P2P control block */
extern tNFA_P2P_CB nfa_p2p_cb;

/*****************************************************************************
**  External functions
*****************************************************************************/
/*
**  nfa_p2p_main.c
*/
void nfa_p2p_init (void);
void nfa_p2p_update_listen_tech (tNFA_TECHNOLOGY_MASK tech_mask);
void nfa_p2p_enable_listening (tNFA_SYS_ID sys_id, BOOLEAN update_wks);
void nfa_p2p_disable_listening (tNFA_SYS_ID sys_id, BOOLEAN update_wks);
void nfa_p2p_activate_llcp (tNFC_DISCOVER *p_data);
void nfa_p2p_deactivate_llcp (void);
void nfa_p2p_set_config (tNFA_DM_DISC_TECH_PROTO_MASK disc_mask);

/*
**  nfa_p2p_act.c
*/
void nfa_p2p_proc_llcp_data_ind (tLLCP_SAP_CBACK_DATA  *p_data);
void nfa_p2p_proc_llcp_connect_ind (tLLCP_SAP_CBACK_DATA  *p_data);
void nfa_p2p_proc_llcp_connect_resp (tLLCP_SAP_CBACK_DATA  *p_data);
void nfa_p2p_proc_llcp_disconnect_ind (tLLCP_SAP_CBACK_DATA  *p_data);
void nfa_p2p_proc_llcp_disconnect_resp (tLLCP_SAP_CBACK_DATA  *p_data);
void nfa_p2p_proc_llcp_congestion (tLLCP_SAP_CBACK_DATA  *p_data);
void nfa_p2p_proc_llcp_link_status (tLLCP_SAP_CBACK_DATA  *p_data);

BOOLEAN nfa_p2p_start_sdp (char *p_service_name, UINT8 local_sap);

BOOLEAN nfa_p2p_reg_server (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_reg_client (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_dereg (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_accept_connection (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_reject_connection (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_disconnect (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_create_data_link_connection (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_send_ui (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_send_data (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_set_local_busy (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_get_link_info (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_get_remote_sap (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_set_llcp_cfg (tNFA_P2P_MSG *p_msg);
BOOLEAN nfa_p2p_restart_rf_discovery (tNFA_P2P_MSG *p_msg);

#if (BT_TRACE_VERBOSE == TRUE)
char *nfa_p2p_evt_code (UINT16 evt_code);
#endif

#else

#define nfa_p2p_init ()
#define nfa_p2p_activate_llcp (a) {};
#define nfa_p2p_deactivate_llcp ()
#define nfa_p2p_set_config ()

#endif /* (defined (NFA_P2P_INCLUDED) && (NFA_P2P_INCLUDED==TRUE)) */
#endif /* NFA_P2P_INT_H */