• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *  This file contains functions that interface with the NFCEEs.
22  *
23  ******************************************************************************/
24 #include <android-base/logging.h>
25 #include <android-base/stringprintf.h>
26 #include <string.h>
27 
28 #include "gki.h"
29 #include "nci_hmsgs.h"
30 #include "nfa_ee_int.h"
31 #include "nfc_api.h"
32 #include "nfc_int.h"
33 #include "nfc_target.h"
34 
35 using android::base::StringPrintf;
36 
37 /*******************************************************************************
38 **
39 ** Function         NFC_NfceeDiscover
40 **
41 ** Description      This function is called to enable or disable NFCEE
42 **                  Discovery. The response from NFCC is reported by
43 **                  tNFC_RESPONSE_CBACK as NFC_NFCEE_DISCOVER_REVT.
44 **                  The notification from NFCC is reported by
45 **                  tNFC_RESPONSE_CBACK as NFC_NFCEE_INFO_REVT.
46 **
47 ** Parameters       discover - 1 to enable discover, 0 to disable.
48 **
49 ** Returns          tNFC_STATUS
50 **
51 *******************************************************************************/
NFC_NfceeDiscover(bool discover)52 tNFC_STATUS NFC_NfceeDiscover(bool discover) {
53   return nci_snd_nfcee_discover((uint8_t)(
54       discover ? NCI_DISCOVER_ACTION_ENABLE : NCI_DISCOVER_ACTION_DISABLE));
55 }
56 
57 /*******************************************************************************
58 **
59 ** Function         NFC_NfceeModeSet
60 **
61 ** Description      This function is called to activate or de-activate an NFCEE
62 **                  connected to the NFCC.
63 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
64 **                  as NFC_NFCEE_MODE_SET_REVT.
65 **
66 ** Parameters       nfcee_id - the NFCEE to activate or de-activate.
67 **                  mode - NFC_MODE_ACTIVATE to activate NFCEE,
68 **                         NFC_MODE_DEACTIVATE to de-activate.
69 **
70 ** Returns          tNFC_STATUS
71 **
72 *******************************************************************************/
NFC_NfceeModeSet(uint8_t nfcee_id,tNFC_NFCEE_MODE mode)73 tNFC_STATUS NFC_NfceeModeSet(uint8_t nfcee_id, tNFC_NFCEE_MODE mode) {
74   tNFC_STATUS status = NCI_STATUS_OK;
75   if (mode >= NCI_NUM_NFCEE_MODE || nfcee_id == NCI_DH_ID) {
76     LOG(ERROR) << StringPrintf("%s: invalid parameter=%d", __func__, mode);
77     return NFC_STATUS_FAILED;
78   }
79   if (nfc_cb.nci_version < NCI_VERSION_2_0)
80     status = nci_snd_nfcee_mode_set(nfcee_id, mode);
81   else {
82     if (nfc_cb.flags & NFC_FL_WAIT_MODE_SET_NTF)
83       status = NFC_STATUS_REFUSED;
84     else {
85       nfa_ee_cb.nfcee_id = nfcee_id;
86       nfa_ee_cb.mode = mode;
87       status = nci_snd_nfcee_mode_set(nfcee_id, mode);
88       if (status == NCI_STATUS_OK) {
89         /* Mode set command is successfully queued or sent.
90          * do not allow another Mode Set command until NTF is received */
91         nfc_cb.flags |= NFC_FL_WAIT_MODE_SET_NTF;
92         nfc_start_timer(&nfc_cb.nci_mode_set_ntf_timer,
93                         (uint16_t)(NFC_TTYPE_WAIT_MODE_SET_NTF),
94                         NFC_MODE_SET_NTF_TIMEOUT);
95       }
96     }
97   }
98   return status;
99 }
100 
101 /*******************************************************************************
102 **
103 ** Function         NFC_SetRouting
104 **
105 ** Description      This function is called to configure the CE routing table.
106 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
107 **                  as NFC_SET_ROUTING_REVT.
108 **
109 ** Parameters
110 **
111 ** Returns          tNFC_STATUS
112 **
113 *******************************************************************************/
NFC_SetRouting(bool more,uint8_t num_tlv,uint8_t tlv_size,uint8_t * p_param_tlvs)114 tNFC_STATUS NFC_SetRouting(bool more, uint8_t num_tlv, uint8_t tlv_size,
115                            uint8_t* p_param_tlvs) {
116   return nci_snd_set_routing_cmd(more, num_tlv, tlv_size, p_param_tlvs);
117 }
118 
119 /*******************************************************************************
120 **
121 ** Function         NFC_GetRouting
122 **
123 ** Description      This function is called to retrieve the CE routing table
124 **                  from NFCC. The response from NFCC is reported by
125 **                  tNFC_RESPONSE_CBACK as NFC_GET_ROUTING_REVT.
126 **
127 ** Returns          tNFC_STATUS
128 **
129 *******************************************************************************/
NFC_GetRouting(void)130 tNFC_STATUS NFC_GetRouting(void) { return nci_snd_get_routing_cmd(); }
131 
132 /*******************************************************************************
133 **
134 ** Function         NFC_NfceePLConfig
135 **
136 ** Description      This function is called to set the Power and Link Control to
137 **                  an NFCEE connected to the NFCC.
138 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
139 **                  as NFC_NFCEE_PL_CONTROL_REVT.
140 **
141 ** Parameters       nfcee_id - the NFCEE to activate or de-activate.
142 **                  pl_config -
143 **                   NFCEE_PL_CONFIG_NFCC_DECIDES  NFCC decides (default)
144 **                   NFCEE_PL_CONFIG_PWR_ALWAYS_ON  NFCEE power supply is
145 **                                                          always on
146 **                   NFCEE_PL_CONFIG_LNK_ON_WHEN_PWR_ON  communication link is
147 **                                       always active when NFCEE is powered on
148 **                   NFCEE_PL_CONFIG_PWR_LNK_ALWAYS_ON  power supply and
149 **                                       communication link are always on
150 **
151 ** Returns          tNFC_STATUS
152 **
153 *******************************************************************************/
NFC_NfceePLConfig(uint8_t nfcee_id,tNCI_NFCEE_PL_CONFIG pl_config)154 tNFC_STATUS NFC_NfceePLConfig(uint8_t nfcee_id,
155                               tNCI_NFCEE_PL_CONFIG pl_config) {
156   return nci_snd_nfcee_power_link_control(nfcee_id, pl_config);
157 }
158