llcp_main.c revision ad483f6fa0128f07fd2187bb9c46c2e3f7728cc5
1/***************************************************************************** 2** 3** Name: llcp_main.c 4** 5** Description: This file contains the main LLCP entry points 6** 7** 8** Copyright (c) 2010, Broadcom Corp., All Rights Reserved. 9** Broadcom Bluetooth Core. Proprietary and confidential. 10******************************************************************************/ 11 12#include <string.h> 13#include "gki.h" 14#include "nfc_target.h" 15#include "bt_types.h" 16#include "llcp_api.h" 17#include "llcp_int.h" 18#include "llcp_defs.h" 19#include "nfc_int.h" 20 21#if (LLCP_DYNAMIC_MEMORY == FALSE) 22tLLCP_CB llcp_cb; 23#endif 24 25/******************************************************************************* 26** 27** Function llcp_init 28** 29** Description This function is called once at startup to initialize 30** all the LLCP structures 31** 32** Returns void 33** 34*******************************************************************************/ 35void llcp_init (void) 36{ 37 UINT32 pool_count; 38 39 memset (&llcp_cb, 0, sizeof (tLLCP_CB)); 40 41 llcp_cb.trace_level = LLCP_INITIAL_TRACE_LEVEL; 42 43 LLCP_TRACE_DEBUG0 ("LLCP - llcp_init ()"); 44 45 llcp_cb.lcb.local_link_miu = (LLCP_MIU <= LLCP_MAX_MIU ? LLCP_MIU : LLCP_MAX_MIU); 46 llcp_cb.lcb.local_opt = LLCP_OPT_VALUE; 47 llcp_cb.lcb.local_wt = LLCP_WAITING_TIME; 48 llcp_cb.lcb.local_lto = LLCP_LTO_VALUE; 49 50 llcp_cb.lcb.inact_timeout_init = LLCP_INIT_INACTIVITY_TIMEOUT; 51 llcp_cb.lcb.inact_timeout_target = LLCP_TARGET_INACTIVITY_TIMEOUT; 52 llcp_cb.lcb.symm_delay = LLCP_DELAY_RESP_TIME; 53 llcp_cb.lcb.data_link_timeout = LLCP_DATA_LINK_CONNECTION_TOUT; 54 llcp_cb.lcb.delay_first_pdu_timeout = LLCP_DELAY_TIME_TO_SEND_FIRST_PDU; 55 56 llcp_cb.lcb.wks = LLCP_WKS_MASK_LM; 57 58 /* total number of buffers for LLCP */ 59 pool_count = GKI_poolcount (LLCP_POOL_ID); 60 61 /* number of buffers for receiving data */ 62 llcp_cb.num_rx_buff = (pool_count * LLCP_RX_BUFF_RATIO) / 100; 63 64 /* rx congestion start/end threshold */ 65 llcp_cb.overall_rx_congest_start = (UINT8) ((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_START) / 100); 66 llcp_cb.overall_rx_congest_end = (UINT8) ((llcp_cb.num_rx_buff * LLCP_RX_CONGEST_END) / 100); 67 68 /* max number of buffers for receiving data on logical data link */ 69 llcp_cb.max_num_ll_rx_buff = (UINT8) ((llcp_cb.num_rx_buff * LLCP_LL_RX_BUFF_LIMIT) / 100); 70 71 LLCP_TRACE_DEBUG4 ("num_rx_buff = %d, rx_congest_start = %d, rx_congest_end = %d, max_num_ll_rx_buff = %d", 72 llcp_cb.num_rx_buff, llcp_cb.overall_rx_congest_start, 73 llcp_cb.overall_rx_congest_end, llcp_cb.max_num_ll_rx_buff); 74 75 /* max number of buffers for transmitting data */ 76 llcp_cb.max_num_tx_buff = (UINT8) (pool_count - llcp_cb.num_rx_buff); 77 78 /* max number of buffers for transmitting data on logical data link */ 79 llcp_cb.max_num_ll_tx_buff = (UINT8) ((llcp_cb.max_num_tx_buff * LLCP_LL_TX_BUFF_LIMIT) / 100); 80 81 LLCP_TRACE_DEBUG2 ("max_num_tx_buff = %d, max_num_ll_tx_buff = %d", 82 llcp_cb.max_num_tx_buff, llcp_cb.max_num_ll_tx_buff); 83 84 llcp_cb.ll_tx_uncongest_ntf_start_sap = LLCP_SAP_SDP + 1; 85 86 LLCP_RegisterServer (LLCP_SAP_SDP, LLCP_LINK_TYPE_DATA_LINK_CONNECTION, "urn:nfc:sn:sdp", llcp_sdp_proc_data); 87} 88 89/******************************************************************************* 90** 91** Function llcp_cleanup 92** 93** Description This function is called once at closing to clean up 94** 95** Returns void 96** 97*******************************************************************************/ 98void llcp_cleanup (void) 99{ 100 UINT8 sap; 101 tLLCP_APP_CB *p_app_cb; 102 103 LLCP_TRACE_DEBUG0 ("LLCP - llcp_cleanup ()"); 104 105 for (sap = LLCP_SAP_SDP; sap < LLCP_NUM_SAPS; sap++) 106 { 107 p_app_cb = llcp_util_get_app_cb (sap); 108 109 if ( (p_app_cb) 110 &&(p_app_cb->p_app_cback) ) 111 { 112 LLCP_Deregister (sap); 113 } 114 } 115 116 nfc_stop_quick_timer (&llcp_cb.lcb.inact_timer); 117 nfc_stop_quick_timer (&llcp_cb.lcb.timer); 118} 119 120/******************************************************************************* 121** 122** Function llcp_process_timeout 123** 124** Description This function is called when an LLCP-related timeout occurs 125** 126** Returns void 127** 128*******************************************************************************/ 129void llcp_process_timeout (TIMER_LIST_ENT *p_tle) 130{ 131 UINT8 reason; 132 133 LLCP_TRACE_DEBUG1 ("llcp_process_timeout: event=%d", p_tle->event); 134 135 switch (p_tle->event) 136 { 137 case NFC_TTYPE_LLCP_LINK_MANAGER: 138 /* Link timeout or Symm timeout */ 139 llcp_link_process_link_timeout (); 140 break; 141 142 case NFC_TTYPE_LLCP_LINK_INACT: 143 /* inactivity timeout */ 144 llcp_link_deactivate (LLCP_LINK_LOCAL_INITIATED); 145 break; 146 147 case NFC_TTYPE_LLCP_DATA_LINK: 148 reason = LLCP_SAP_DISCONNECT_REASON_TIMEOUT; 149 llcp_dlsm_execute ((tLLCP_DLCB *) (p_tle->param), LLCP_DLC_EVENT_TIMEOUT, &reason); 150 break; 151 152 case NFC_TTYPE_LLCP_DELAY_FIRST_PDU: 153 llcp_link_check_send_data (); 154 break; 155 156 default: 157 break; 158 } 159} 160 161/******************************************************************************* 162** 163** Function LLCP_SetTraceLevel 164** 165** Description This function sets the trace level for LLCP. If called with 166** a value of 0xFF, it simply returns the current trace level. 167** 168** Returns The new or current trace level 169** 170*******************************************************************************/ 171UINT8 LLCP_SetTraceLevel (UINT8 new_level) 172{ 173 if (new_level != 0xFF) 174 llcp_cb.trace_level = new_level; 175 176 return (llcp_cb.trace_level); 177} 178