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