1 /****************************************************************************** 2 * 3 * Copyright (C) 2010-2012 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 main implementation file for the NFA Connection Handover. 22 * 23 ******************************************************************************/ 24 #include <string.h> 25 #include "nfc_api.h" 26 #include "nfa_sys.h" 27 #include "nfa_cho_api.h" 28 #include "nfa_cho_int.h" 29 #include "trace_api.h" 30 31 /***************************************************************************** 32 ** Global Variables 33 *****************************************************************************/ 34 35 /* system manager control block definition */ 36 #if NFA_DYNAMIC_MEMORY == FALSE 37 tNFA_CHO_CB nfa_cho_cb; 38 #endif 39 40 /***************************************************************************** 41 ** Static Functions 42 *****************************************************************************/ 43 44 /* event handler function type */ 45 static BOOLEAN nfa_cho_evt_hdlr (BT_HDR *p_msg); 46 47 /* disable function type */ 48 static void nfa_cho_sys_disable (void); 49 50 /***************************************************************************** 51 ** Constants 52 *****************************************************************************/ 53 static const tNFA_SYS_REG nfa_cho_sys_reg = 54 { 55 NULL, 56 nfa_cho_evt_hdlr, 57 nfa_cho_sys_disable, 58 NULL 59 }; 60 61 /******************************************************************************* 62 ** 63 ** Function nfa_cho_timer_cback 64 ** 65 ** Description Process timeout event when timer expires 66 ** 67 ** 68 ** Returns None 69 ** 70 *******************************************************************************/ 71 static void nfa_cho_timer_cback (void *p_tle) 72 { 73 nfa_cho_sm_execute (NFA_CHO_TIMEOUT_EVT, NULL); 74 } 75 76 /******************************************************************************* 77 ** 78 ** Function nfa_cho_init 79 ** 80 ** Description Initialize NFA Connection Handover 81 ** 82 ** 83 ** Returns None 84 ** 85 *******************************************************************************/ 86 void nfa_cho_init (void) 87 { 88 CHO_TRACE_DEBUG0 ("nfa_cho_init ()"); 89 90 /* initialize control block */ 91 memset (&nfa_cho_cb, 0, sizeof (tNFA_CHO_CB)); 92 93 nfa_cho_cb.server_sap = LLCP_INVALID_SAP; 94 nfa_cho_cb.client_sap = LLCP_INVALID_SAP; 95 nfa_cho_cb.remote_sap = LLCP_INVALID_SAP; 96 97 nfa_cho_cb.hs_ndef_type_handle = NFA_HANDLE_INVALID; 98 nfa_cho_cb.bt_ndef_type_handle = NFA_HANDLE_INVALID; 99 nfa_cho_cb.wifi_ndef_type_handle = NFA_HANDLE_INVALID; 100 101 nfa_cho_cb.trace_level = APPL_INITIAL_TRACE_LEVEL; 102 103 /* register message handler on NFA SYS */ 104 nfa_sys_register ( NFA_ID_CHO, &nfa_cho_sys_reg); 105 106 /* initialize timer callback */ 107 nfa_cho_cb.timer.p_cback = nfa_cho_timer_cback; 108 } 109 110 /******************************************************************************* 111 ** 112 ** Function nfa_cho_sys_disable 113 ** 114 ** Description Deregister NFA Connection Handover from NFA SYS/DM 115 ** 116 ** 117 ** Returns None 118 ** 119 *******************************************************************************/ 120 static void nfa_cho_sys_disable (void) 121 { 122 CHO_TRACE_DEBUG0 ("nfa_cho_sys_disable ()"); 123 124 /* clean up if application is still registered */ 125 if (nfa_cho_cb.p_cback) 126 { 127 nfa_cho_proc_api_dereg (); 128 } 129 130 /* deregister message handler on NFA SYS */ 131 nfa_sys_deregister (NFA_ID_CHO); 132 } 133 134 /******************************************************************************* 135 ** 136 ** Function nfa_cho_evt_hdlr 137 ** 138 ** Description Processing event for NFA Connection Handover 139 ** 140 ** 141 ** Returns TRUE if p_msg needs to be deallocated 142 ** 143 *******************************************************************************/ 144 static BOOLEAN nfa_cho_evt_hdlr (BT_HDR *p_msg) 145 { 146 tNFA_CHO_INT_EVENT_DATA *p_data = (tNFA_CHO_INT_EVENT_DATA *) p_msg; 147 148 nfa_cho_sm_execute (p_data->hdr.event, p_data); 149 150 return TRUE; 151 } 152 153 154