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 <stdlib.h>
18 #include "../includes/common.h"
19
20 #include <nfc_api.h>
21 #include <nfc_int.h>
22 #include <rw_int.h>
23 #include <tags_defs.h>
24 #include <llcp_int.h>
25
26 #define DEFAULT_SAP 1
27 #define LENGTH 0
28
29 bool testInProgress = false;
30
31 struct sigaction new_action, old_action;
32
sigsegv_handler(int signum,siginfo_t * info,void * context)33 void sigsegv_handler(int signum, siginfo_t *info, void *context) {
34 if (testInProgress && info->si_signo == SIGSEGV) {
35 (*old_action.sa_sigaction)(signum, info, context);
36 return;
37 }
38 exit(EXIT_FAILURE);
39 }
40
41 extern tLLCP_CB llcp_cb;
42 extern tRW_CB rw_cb;
43 extern tNFC_CB nfc_cb;
44
GKI_freebuf(void * x)45 void GKI_freebuf(void* x) { (void)x; }
GKI_start_timer(uint8_t,int32_t,bool)46 void GKI_start_timer(uint8_t, int32_t, bool) {}
GKI_stop_timer(uint8_t)47 void GKI_stop_timer(uint8_t) {}
48
poc_cback(tRW_EVENT event,tRW_DATA * p_rw_data)49 void poc_cback(tRW_EVENT event, tRW_DATA* p_rw_data) {
50 (void)event;
51 (void)p_rw_data;
52 }
53
main()54 int32_t main() {
55 sigemptyset(&new_action.sa_mask);
56 new_action.sa_flags = SA_SIGINFO;
57 new_action.sa_sigaction = sigsegv_handler;
58 sigaction(SIGSEGV, &new_action, &old_action);
59
60 tNFC_ACTIVATE_DEVT p_activate_params = {};
61 p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP;
62 p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A;
63 RW_SetActivatedTagType(&p_activate_params, &poc_cback);
64 FAIL_CHECK(rw_cb.p_cback == &poc_cback);
65
66 GKI_init();
67 llcp_init();
68 for (int32_t n = 0; n < LLCP_MAX_DATA_LINK; ++n) {
69 llcp_cb.dlcb[n].state = LLCP_DLC_STATE_CONNECTED;
70 llcp_cb.dlcb[n].local_sap = DEFAULT_SAP;
71 llcp_cb.dlcb[n].remote_sap = DEFAULT_SAP;
72 }
73
74 testInProgress = true;
75 llcp_dlc_proc_rx_pdu(DEFAULT_SAP, LLCP_PDU_RNR_TYPE, DEFAULT_SAP, LENGTH,
76 nullptr);
77 testInProgress = false;
78
79 return EXIT_SUCCESS;
80 }
81