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 "../includes/common.h"
18 #include <log/log.h>
19 #include <stdlib.h>
20 
21 #include <nfc_api.h>
22 #include <rw_int.h>
23 
24 #define NUM_BYTES 1
25 
26 extern tRW_CB rw_cb;
27 void rw_init(void);
28 void rw_t2t_handle_rsp(uint8_t *p_data);
29 
poc_cback(tRW_EVENT event,tRW_DATA * p_rw_data)30 void poc_cback(tRW_EVENT event, tRW_DATA *p_rw_data) {
31   (void)event;
32   (void)p_rw_data;
33 }
34 
main()35 int main() {
36   tNFC_ACTIVATE_DEVT p_activate_params = {};
37   p_activate_params.protocol = NFC_PROTOCOL_ISO_DEP;
38   p_activate_params.rf_tech_param.mode = NFC_DISCOVERY_TYPE_POLL_A;
39   RW_SetActivatedTagType(&p_activate_params, &poc_cback);
40   if (rw_cb.p_cback != &poc_cback) {
41     ALOGE("Structure tRW_CB mismatch rw_cb.p_cback=%p poc_cback=%p\n",
42           rw_cb.p_cback, poc_cback);
43     return EXIT_FAILURE;
44   }
45   tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
46   rw_init();
47   rw_cb.p_cback = &poc_cback;
48   p_t2t->state = RW_T2T_STATE_DETECT_TLV;
49   p_t2t->tlv_detect = TAG_LOCK_CTRL_TLV;
50   p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
51   p_t2t->found_tlv = TAG_LOCK_CTRL_TLV;
52   p_t2t->bytes_count = NUM_BYTES;
53   p_t2t->tlv_value[1] = 0;
54   int index = p_t2t->num_lock_tlvs;
55   uint8_t data[T2T_READ_DATA_LEN];
56   rw_t2t_handle_rsp(data);
57   int ret = (p_t2t->lock_tlv[index].num_bits == p_t2t->tlv_value[1])
58                 ? EXIT_VULNERABLE
59                 : EXIT_SUCCESS;
60   return ret;
61 }
62