summaryrefslogtreecommitdiff
path: root/src/nfc/llcp/llcp_main.c
blob: 631f074cad2aaa265cd5638323b449a36b4939e9 (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
/******************************************************************************
 *
 *  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 file contains the main LLCP entry points
 *
 ******************************************************************************/

#include <string.h>
#include "gki.h"
#include "nfc_target.h"
#include "bt_types.h"
#include "llcp_api.h"
#include "llcp_int.h"
#include "llcp_defs.h"
#include "nfc_int.h"

tLLCP_CB llcp_cb;

/*******************************************************************************
**
** Function         llcp_init
**
** Description      This function is called once at startup to initialize
**                  all the LLCP structures
**
** Returns          void
**
*******************************************************************************/
void llcp_init (void)
{
    UINT32 pool_count;

    memset (&llcp_cb, 0, sizeof (tLLCP_CB));

    llcp_cb.trace_level = LLCP_INITIAL_TRACE_LEVEL;

    LLCP_TRACE_DEBUG0 ("LLCP - llcp_init ()");

    llcp_cb.lcb.local_link_miu = (LLCP_MIU <= LLCP_MAX_MIU ? LLCP_MIU : LLCP_MAX_MIU);
    llcp_cb.lcb.local_opt      = LLCP_OPT_VALUE;
    llcp_cb.lcb.local_wt       = LLCP_WAITING_TIME;
    llcp_cb.lcb.local_lto      = LLCP_LTO_VALUE;

    llcp_cb.lcb.inact_timeout_init   = LLCP_INIT_INACTIVITY_TIMEOUT;
    llcp_cb.lcb.inact_timeout_target = LLCP_TARGET_INACTIVITY_TIMEOUT;
    llcp_cb.lcb.symm_delay           = LLCP_DELAY_RESP_TIME;
    llcp_cb.lcb.data_link_timeout    = LLCP_DATA_LINK_CONNECTION_TOUT;
    llcp_cb.lcb.delay_first_pdu_timeout = LLCP_DELAY_TIME_TO_SEND_FIRST_PDU;

    llcp_cb.lcb.wks  = LLCP_WKS_MASK_LM;

    /* total number of buffers for LLCP */
    pool_count = GKI_poolcount (LLCP_POOL_ID);

    /* number of buffers for receiving data */
    llcp_cb.num_rx_buff = (pool_count * LLCP_RX_BUFF_RATIO) / 100;

    /* rx congestion start/end threshold */
    llcp_cb.overall_rx_congest_start = (UINT8) ((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_START) / 100);
    llcp_cb.overall_rx_congest_end   = (UINT8) ((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_END) / 100);

    /* max number of buffers for receiving data on logical data link */
    llcp_cb.max_num_ll_rx_buff = (UINT8) ((llcp_cb.num_rx_buff * LLCP_LL_RX_BUFF_LIMIT) / 100);

    LLCP_TRACE_DEBUG4 ("num_rx_buff = %d, rx_congest_start = %d, rx_congest_end = %d, max_num_ll_rx_buff = %d",
                        llcp_cb.num_rx_buff, llcp_cb.overall_rx_congest_start,
                        llcp_cb.overall_rx_congest_end, llcp_cb.max_num_ll_rx_buff);

    /* max number of buffers for transmitting data */
    llcp_cb.max_num_tx_buff    = (UINT8) (pool_count - llcp_cb.num_rx_buff);

    /* max number of buffers for transmitting data on logical data link */
    llcp_cb.max_num_ll_tx_buff = (UINT8) ((llcp_cb.max_num_tx_buff * LLCP_LL_TX_BUFF_LIMIT) / 100);

    LLCP_TRACE_DEBUG2 ("max_num_tx_buff = %d, max_num_ll_tx_buff = %d",
                        llcp_cb.max_num_tx_buff, llcp_cb.max_num_ll_tx_buff);

    llcp_cb.ll_tx_uncongest_ntf_start_sap = LLCP_SAP_SDP + 1;

    LLCP_RegisterServer (LLCP_SAP_SDP, LLCP_LINK_TYPE_DATA_LINK_CONNECTION, "urn:nfc:sn:sdp", llcp_sdp_proc_data);
}

/*******************************************************************************
**
** Function         llcp_cleanup
**
** Description      This function is called once at closing to clean up
**
** Returns          void
**
*******************************************************************************/
void llcp_cleanup (void)
{
    UINT8 sap;
    tLLCP_APP_CB *p_app_cb;

    LLCP_TRACE_DEBUG0 ("LLCP - llcp_cleanup ()");

    for (sap = LLCP_SAP_SDP; sap < LLCP_NUM_SAPS; sap++)
    {
        p_app_cb = llcp_util_get_app_cb (sap);

        if (  (p_app_cb)
            &&(p_app_cb->p_app_cback)  )
        {
            LLCP_Deregister (sap);
        }
    }

    nfc_stop_quick_timer (&llcp_cb.lcb.inact_timer);
    nfc_stop_quick_timer (&llcp_cb.lcb.timer);
}

/*******************************************************************************
**
** Function         llcp_process_timeout
**
** Description      This function is called when an LLCP-related timeout occurs
**
** Returns          void
**
*******************************************************************************/
void llcp_process_timeout (TIMER_LIST_ENT *p_tle)
{
    UINT8 reason;

    LLCP_TRACE_DEBUG1 ("llcp_process_timeout: event=%d", p_tle->event);

    switch (p_tle->event)
    {
    case NFC_TTYPE_LLCP_LINK_MANAGER:
        /* Link timeout or Symm timeout */
        llcp_link_process_link_timeout ();
        break;

    case NFC_TTYPE_LLCP_LINK_INACT:
        /* inactivity timeout */
        llcp_link_deactivate (LLCP_LINK_LOCAL_INITIATED);
        break;

    case NFC_TTYPE_LLCP_DATA_LINK:
        reason = LLCP_SAP_DISCONNECT_REASON_TIMEOUT;
        llcp_dlsm_execute ((tLLCP_DLCB *) (p_tle->param), LLCP_DLC_EVENT_TIMEOUT, &reason);
        break;

    case NFC_TTYPE_LLCP_DELAY_FIRST_PDU:
        llcp_link_check_send_data ();
        break;

    default:
        break;
    }
}

/*******************************************************************************
**
** Function         LLCP_SetTraceLevel
**
** Description      This function sets the trace level for LLCP.  If called with
**                  a value of 0xFF, it simply returns the current trace level.
**
** Returns          The new or current trace level
**
*******************************************************************************/
UINT8 LLCP_SetTraceLevel (UINT8 new_level)
{
    if (new_level != 0xFF)
        llcp_cb.trace_level = new_level;

    return (llcp_cb.trace_level);
}