1 /******************************************************************************
2  *
3  *  Copyright (C) 2010-2014 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  *  Registration/deregistration functions for inter-module callbacks
22  *
23  ******************************************************************************/
24 #include <android-base/logging.h>
25 #include <android-base/stringprintf.h>
26 
27 #include "nfa_sys.h"
28 #include "nfa_sys_int.h"
29 
30 using android::base::StringPrintf;
31 
32 /*******************************************************************************
33 **
34 ** Function         nfa_sys_cback_reg_enable_complete
35 **
36 ** Description      Called to register an initialization complete callback
37 **                  function
38 **
39 ** Returns          void
40 **
41 *******************************************************************************/
nfa_sys_cback_reg_enable_complete(tNFA_SYS_ENABLE_CBACK * p_cback)42 void nfa_sys_cback_reg_enable_complete(tNFA_SYS_ENABLE_CBACK* p_cback) {
43   nfa_sys_cb.p_enable_cback = p_cback;
44   nfa_sys_cb.enable_cplt_flags = 0;
45 }
46 
47 /*******************************************************************************
48 **
49 ** Function         nfa_sys_cback_notify_enable_complete
50 **
51 ** Description      Called by other NFA subsystems to notify initialization is
52 **                  complete
53 **
54 ** Returns          void
55 **
56 *******************************************************************************/
nfa_sys_cback_notify_enable_complete(uint8_t id)57 void nfa_sys_cback_notify_enable_complete(uint8_t id) {
58   nfa_sys_cb.enable_cplt_flags |= (0x0001 << id);
59 
60   LOG(VERBOSE) << StringPrintf("enable_cplt_flags=0x%x, enable_cplt_mask=0x%x",
61                              nfa_sys_cb.enable_cplt_flags,
62                              nfa_sys_cb.enable_cplt_mask);
63 
64   if ((nfa_sys_cb.enable_cplt_flags == nfa_sys_cb.enable_cplt_mask) &&
65       (nfa_sys_cb.p_enable_cback)) {
66     nfa_sys_cb.p_enable_cback();
67     nfa_sys_cb.p_enable_cback = nullptr;
68   }
69 }
70 
71 /*******************************************************************************
72 **
73 ** Function         nfa_sys_cback_reg_nfcc_power_mode_proc_complete
74 **
75 ** Description      Called to register a callback function for complete of
76 **                  processing NFCC power mode change from NFA sub-systems
77 **
78 ** Returns          void
79 **
80 *******************************************************************************/
nfa_sys_cback_reg_nfcc_power_mode_proc_complete(tNFA_SYS_PROC_NFCC_PWR_MODE_CMPL * p_cback)81 void nfa_sys_cback_reg_nfcc_power_mode_proc_complete(
82     tNFA_SYS_PROC_NFCC_PWR_MODE_CMPL* p_cback) {
83   nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback = p_cback;
84   nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags = 0;
85 }
86 
87 /*******************************************************************************
88 **
89 ** Function         nfa_sys_cback_notify_nfcc_power_mode_proc_complete
90 **
91 ** Description      Called by other NFA subsystems to notify processing NFCC
92 **                  power mode is complete
93 **
94 ** Returns          void
95 **
96 *******************************************************************************/
nfa_sys_cback_notify_nfcc_power_mode_proc_complete(uint8_t id)97 void nfa_sys_cback_notify_nfcc_power_mode_proc_complete(uint8_t id) {
98   nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags |= (0x0001 << id);
99 
100   LOG(VERBOSE) << StringPrintf("flags=0x%x, mask=0x%x",
101                              nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags,
102                              nfa_sys_cb.proc_nfcc_pwr_mode_cplt_mask);
103 
104   /* except SYS */
105   if ((nfa_sys_cb.proc_nfcc_pwr_mode_cplt_flags ==
106        nfa_sys_cb.proc_nfcc_pwr_mode_cplt_mask) &&
107       (nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback)) {
108     nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback();
109     nfa_sys_cb.p_proc_nfcc_pwr_mode_cmpl_cback = nullptr;
110   }
111 }
112