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_int.h>
18 #include <rw_int.h>
19
20 #define RW_MFC_STATE_READ_NDEF 0x03
21 #define RW_MFC_SUBSTATE_READ_BLOCK 0x03
22
23 extern tRW_CB rw_cb;
24
GKI_freebuf(void *)25 void GKI_freebuf(void*) {
26 }
27
GKI_start_timer(uint8_t,int32_t,bool)28 void GKI_start_timer(uint8_t, int32_t, bool) {
29 }
30
GKI_stop_timer(uint8_t)31 void GKI_stop_timer(uint8_t) {
32 }
33
cback(tRW_EVENT,tRW_DATA *)34 void cback(tRW_EVENT, tRW_DATA*) {
35 }
36
main()37 int main() {
38 tRW_MFC_CB* p_mfc = &rw_cb.tcb.mfc;
39
40 GKI_init();
41 rw_init();
42
43 uint8_t selres = 1;
44 uint8_t uid[MFC_UID_LEN] = { 1 };
45 if (rw_mfc_select(selres, uid) != NFC_STATUS_OK) {
46 return EXIT_FAILURE;
47 }
48
49 p_mfc->state = RW_MFC_STATE_READ_NDEF;
50 p_mfc->substate = RW_MFC_SUBSTATE_READ_BLOCK;
51
52 tNFC_CONN_CB* p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
53
54 tNFC_CONN* p_data = (tNFC_CONN*) malloc(sizeof(tNFC_CONN));
55 if (!p_data) {
56 return EXIT_FAILURE;
57 }
58
59 p_data->data.p_data = (NFC_HDR*) malloc(sizeof(uint8_t) * 16);
60 if (!(p_data->data.p_data)) {
61 free(p_data);
62 return EXIT_FAILURE;
63 }
64
65 p_data->data.status = NFC_STATUS_OK;
66 tNFC_CONN_EVT event = NFC_DATA_CEVT;
67
68 NFC_HDR* mfc_data = (NFC_HDR*) p_data->data.p_data;
69 mfc_data->len = 0x10;
70 mfc_data->offset = 0;
71 p_mfc->ndef_length = 1024;
72 p_mfc->p_ndef_buffer = (uint8_t*) malloc(sizeof(uint8_t) * 16);
73 if (!(p_mfc->p_ndef_buffer)) {
74 free(p_data->data.p_data);
75 free(p_data);
76 return EXIT_FAILURE;
77 }
78
79 rw_cb.p_cback = cback;
80
81 p_cb->p_cback(0, event, p_data);
82
83 free(p_mfc->p_ndef_buffer);
84 free(p_data->data.p_data);
85 free(p_data);
86 return EXIT_SUCCESS;
87 }
88