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 <nfc_api.h>
20 #include <rw_int.h>
21
22 bool isTestInProgress = false;
23 struct sigaction new_action, old_action;
sigabrt_handler(int signum,siginfo_t * info,void * context)24 void sigabrt_handler(int signum, siginfo_t* info, void* context) {
25 if (isTestInProgress && info->si_signo == SIGABRT) {
26 (*old_action.sa_sigaction)(signum, info, context);
27 return;
28 }
29 exit(EXIT_FAILURE);
30 }
31
32 extern tRW_CB rw_cb;
33 void rw_init(void);
34 void rw_t2t_handle_rsp(uint8_t* p_data);
poc_cback(tRW_EVENT event,tRW_DATA * p_rw_data)35 void poc_cback(tRW_EVENT event, tRW_DATA* p_rw_data) {
36 (void)event;
37 (void)p_rw_data;
38 }
39
main()40 int main() {
41 sigemptyset(&new_action.sa_mask);
42 new_action.sa_flags = SA_SIGINFO;
43 new_action.sa_sigaction = sigabrt_handler;
44 sigaction(SIGABRT, &new_action, &old_action);
45
46 tNFC_ACTIVATE_DEVT p_activate_params = {};
47 p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP;
48 p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A;
49 RW_SetActivatedTagType(&p_activate_params, &poc_cback);
50 FAIL_CHECK(rw_cb.p_cback == &poc_cback);
51
52 tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
53 rw_init();
54 rw_cb.p_cback = &poc_cback;
55 p_t2t->state = RW_T2T_STATE_DETECT_TLV;
56 p_t2t->tlv_detect = TAG_LOCK_CTRL_TLV;
57 p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
58 p_t2t->found_tlv = TAG_LOCK_CTRL_TLV;
59 p_t2t->bytes_count = 1;
60 p_t2t->num_lockbytes = RW_T2T_MAX_LOCK_BYTES;
61 uint8_t data[T2T_READ_DATA_LEN];
62 isTestInProgress = true;
63 rw_t2t_handle_rsp(data);
64 isTestInProgress = false;
65 return EXIT_SUCCESS;
66 }
67