1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdlib.h>
18 #include "../includes/common.h"
19 #include "../includes/memutils.h"
20
21 #include <log/log.h>
22 #include <nfc_api.h>
23 #include <nfc_int.h>
24 #include <rw_int.h>
25 #include <tags_defs.h>
26
27 extern tRW_CB rw_cb;
28 extern tNFC_CB nfc_cb;
29 void rw_init(void);
30 tNFC_STATUS rw_t4t_select(void);
GKI_freebuf(void * x)31 void GKI_freebuf(void* x) { (void)x; }
32
33 // borrowed from rw_t4t.cc
34 /* main state */
35 #define RW_T4T_STATE_READ_NDEF 0x03
36 /* sub state */
37 #define RW_T4T_SUBSTATE_WAIT_READ_RESP 0x05
38
GKI_start_timer(uint8_t,int32_t,bool)39 void GKI_start_timer(uint8_t, int32_t, bool) {}
GKI_stop_timer(uint8_t)40 void GKI_stop_timer(uint8_t) {}
41
poc_cback(tRW_EVENT event,tRW_DATA * p_rw_data)42 void poc_cback(tRW_EVENT event, tRW_DATA* p_rw_data) {
43 (void)event;
44 (void)p_rw_data;
45 }
46
main()47 int main() {
48 tNFC_ACTIVATE_DEVT p_activate_params = {};
49 p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP;
50 p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A;
51 RW_SetActivatedTagType(&p_activate_params, &poc_cback);
52 if (rw_cb.p_cback != &poc_cback) {
53 ALOGE("Structure tRW_CB mismatch rw_cb.p_cback=%p poc_cback=%p\n", rw_cb.p_cback,
54 poc_cback);
55 return EXIT_FAILURE;
56 }
57 tRW_T4T_CB* p_t4t = &rw_cb.tcb.t4t;
58 GKI_init();
59 rw_init();
60
61 if ((rw_t4t_select()) != NFC_STATUS_OK) {
62 return EXIT_FAILURE;
63 }
64
65 tNFC_CONN* p_data = (tNFC_CONN*)malloc(sizeof(tNFC_CONN));
66 if (!p_data) {
67 return EXIT_FAILURE;
68 }
69 p_data->data.p_data = (NFC_HDR*)malloc(sizeof(uint8_t) * 16);
70 if (!(p_data->data.p_data)) {
71 free(p_data);
72 return EXIT_FAILURE;
73 }
74 p_data->status = NFC_STATUS_OK;
75
76 p_t4t->state = RW_T4T_STATE_READ_NDEF;
77 p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_READ_RESP;
78
79 NFC_HDR* p_r_apdu = (NFC_HDR*)p_data->data.p_data;
80 p_r_apdu->offset = 8;
81 p_r_apdu->len = 1;
82
83 tNFC_CONN_CB* p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
84 tNFC_CONN_EVT event = NFC_DATA_CEVT;
85
86 p_cb->p_cback(0, event, p_data);
87
88 free(p_data->data.p_data);
89 free(p_data);
90
91 return EXIT_SUCCESS;
92 }
93