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