• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-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  *
22  *  This file contains functions that interface with the NFC NCI transport.
23  *  On the receive side, it routes events to the appropriate handler
24  *  (callback). On the transmit side, it manages the command transmission.
25  *
26  ******************************************************************************/
27 #include <string.h>
28 #include "nfc_target.h"
29 #include "bt_types.h"
30 
31 #if (NFC_INCLUDED == TRUE)
32 #include "nfc_api.h"
33 #include "nci_hmsgs.h"
34 #include "ce_api.h"
35 #include "ce_int.h"
36 #include "gki.h"
37 
38 tCE_CB  ce_cb;
39 
40 /*******************************************************************************
41 *******************************************************************************/
ce_init(void)42 void ce_init (void)
43 {
44     memset (&ce_cb, 0, sizeof (tCE_CB));
45     ce_cb.trace_level = NFC_INITIAL_TRACE_LEVEL;
46 
47     /* Initialize tag-specific fields of ce control block */
48     ce_t3t_init ();
49 }
50 
51 /*******************************************************************************
52 **
53 ** Function         CE_SendRawFrame
54 **
55 ** Description      This function sends a raw frame to the peer device.
56 **
57 ** Returns          tNFC_STATUS
58 **
59 *******************************************************************************/
CE_SendRawFrame(UINT8 * p_raw_data,UINT16 data_len)60 tNFC_STATUS CE_SendRawFrame (UINT8 *p_raw_data, UINT16 data_len)
61 {
62     tNFC_STATUS status = NFC_STATUS_FAILED;
63     BT_HDR  *p_data;
64     UINT8   *p;
65 
66     if (ce_cb.p_cback)
67     {
68         /* a valid opcode for RW */
69         p_data = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
70         if (p_data)
71         {
72             p_data->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
73             p = (UINT8 *) (p_data + 1) + p_data->offset;
74             memcpy (p, p_raw_data, data_len);
75             p_data->len = data_len;
76             CE_TRACE_EVENT1 ("CE SENT raw frame (0x%x)", data_len);
77             status = NFC_SendData (NFC_RF_CONN_ID, p_data);
78         }
79 
80     }
81     return status;
82 }
83 
84 /*******************************************************************************
85 **
86 ** Function         CE_SetActivatedTagType
87 **
88 ** Description      This function selects the tag type for CE mode.
89 **
90 ** Returns          tNFC_STATUS
91 **
92 *******************************************************************************/
CE_SetActivatedTagType(tNFC_ACTIVATE_DEVT * p_activate_params,UINT16 t3t_system_code,tCE_CBACK * p_cback)93 tNFC_STATUS CE_SetActivatedTagType (tNFC_ACTIVATE_DEVT *p_activate_params, UINT16 t3t_system_code, tCE_CBACK *p_cback)
94 {
95     tNFC_STATUS status = NFC_STATUS_FAILED;
96     tNFC_PROTOCOL protocol = p_activate_params->protocol;
97 
98     CE_TRACE_API1 ("CE_SetActivatedTagType protocol:%d", protocol);
99 
100     switch (protocol)
101     {
102     case NFC_PROTOCOL_T1T:
103     case NFC_PROTOCOL_T2T:
104         return NFC_STATUS_FAILED;
105 
106     case NFC_PROTOCOL_T3T:   /* Type3Tag    - NFC-F */
107         /* store callback function before NFC_SetStaticRfCback () */
108         ce_cb.p_cback  = p_cback;
109         status = ce_select_t3t (t3t_system_code, p_activate_params->rf_tech_param.param.lf.nfcid2);
110         break;
111 
112     case NFC_PROTOCOL_ISO_DEP:     /* ISODEP/4A,4B- NFC-A or NFC-B */
113         /* store callback function before NFC_SetStaticRfCback () */
114         ce_cb.p_cback  = p_cback;
115         status = ce_select_t4t ();
116         break;
117 
118     default:
119         CE_TRACE_ERROR0 ("CE_SetActivatedTagType Invalid protocol");
120         return NFC_STATUS_FAILED;
121     }
122 
123     if (status != NFC_STATUS_OK)
124     {
125         NFC_SetStaticRfCback (NULL);
126         ce_cb.p_cback  = NULL;
127     }
128     return status;
129 }
130 
131 /*******************************************************************************
132 **
133 ** Function         CE_SetTraceLevel
134 **
135 ** Description      This function sets the trace level for Card Emulation mode.
136 **                  If called with a value of 0xFF,
137 **                  it simply returns the current trace level.
138 **
139 ** Returns          The new or current trace level
140 **
141 *******************************************************************************/
CE_SetTraceLevel(UINT8 new_level)142 UINT8 CE_SetTraceLevel (UINT8 new_level)
143 {
144     if (new_level != 0xFF)
145         ce_cb.trace_level = new_level;
146 
147     return (ce_cb.trace_level);
148 }
149 
150 #endif /* NFC_INCLUDED == TRUE */
151