1 /*
2 * Copyright (C) 2022 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 <rw_int.h>
18 #include <stdlib.h>
19 #include "../includes/common.h"
20
21 bool testInProgress = false;
22 struct sigaction new_action, old_action;
sigabrt_handler(int signum,siginfo_t * info,void * context)23 void sigabrt_handler(int signum, siginfo_t *info, void *context) {
24 if (testInProgress && info->si_signo == SIGABRT) {
25 (*old_action.sa_sigaction)(signum, info, context);
26 return;
27 }
28 exit(EXIT_FAILURE);
29 }
30
31 uint8_t *p_data = nullptr;
32 extern tRW_CB rw_cb;
33
34 extern void rw_t2t_handle_rsp(uint8_t *p_data);
35
poc_cback(uint8_t,tRW_DATA *)36 void poc_cback(uint8_t, tRW_DATA *) {}
37
exit_handler(void)38 void exit_handler(void) {
39 if (p_data) {
40 free(p_data);
41 p_data = nullptr;
42 }
43 }
44
main()45 int main() {
46 atexit(exit_handler);
47 sigemptyset(&new_action.sa_mask);
48 new_action.sa_flags = SA_SIGINFO;
49 new_action.sa_sigaction = sigabrt_handler;
50 sigaction(SIGABRT, &new_action, &old_action);
51
52 tNFC_ACTIVATE_DEVT p_activate_params = {};
53 p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP;
54 p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A;
55 FAIL_CHECK(RW_SetActivatedTagType(&p_activate_params, &poc_cback) == NFC_STATUS_OK);
56 FAIL_CHECK(rw_cb.p_cback == &poc_cback);
57 tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
58 p_t2t->state = RW_T2T_STATE_DETECT_TLV;
59 p_t2t->tlv_detect = TAG_LOCK_CTRL_TLV;
60 p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
61 p_t2t->found_tlv = TAG_LOCK_CTRL_TLV;
62 p_t2t->bytes_count = 0;
63 p_t2t->p_cur_cmd_buf = (NFC_HDR *)GKI_getpoolbuf(NFC_RW_POOL_ID);
64 rw_cb.p_cback = &poc_cback;
65 p_data = (uint8_t *)malloc(sizeof(uint8_t));
66 FAIL_CHECK(p_data);
67
68 testInProgress = true;
69 rw_t2t_handle_rsp(p_data);
70 testInProgress = false;
71
72 return EXIT_SUCCESS;
73 }
74