• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdlib.h>
18 #include <rw_int.h>
19 #include <nfc_int.h>
20 
21 extern tRW_CB rw_cb;
22 extern tNFC_CB nfc_cb;
23 void rw_init(void);
24 tNFC_STATUS rw_i93_select(uint8_t* p_uid);
25 
26 // borrowed from rw_i93.cc
27 enum {
28     RW_I93_STATE_NOT_ACTIVATED, /* ISO15693 is not activated            */
29     RW_I93_STATE_IDLE, /* waiting for upper layer API          */
30     RW_I93_STATE_BUSY, /* waiting for response from tag        */
31 
32     RW_I93_STATE_DETECT_NDEF, /* performing NDEF detection precedure  */
33     RW_I93_STATE_READ_NDEF, /* performing read NDEF procedure       */
34     RW_I93_STATE_UPDATE_NDEF, /* performing update NDEF procedure     */
35     RW_I93_STATE_FORMAT, /* performing format procedure          */
36     RW_I93_STATE_SET_READ_ONLY, /* performing set read-only procedure   */
37 
38     RW_I93_STATE_PRESENCE_CHECK /* checking presence of tag             */
39 };
40 
41 // borrowed from rw_i93.cc
42 enum {
43     RW_I93_SUBSTATE_WAIT_UID, /* waiting for response of inventory    */
44     RW_I93_SUBSTATE_WAIT_SYS_INFO, /* waiting for response of get sys info */
45     RW_I93_SUBSTATE_WAIT_CC, /* waiting for reading CC               */
46     RW_I93_SUBSTATE_SEARCH_NDEF_TLV, /* searching NDEF TLV                   */
47     RW_I93_SUBSTATE_CHECK_LOCK_STATUS, /* check if any NDEF TLV is locked      */
48 
49     RW_I93_SUBSTATE_RESET_LEN, /* set length to 0 to update NDEF TLV   */
50     RW_I93_SUBSTATE_WRITE_NDEF, /* writing NDEF and Terminator TLV      */
51     RW_I93_SUBSTATE_UPDATE_LEN, /* set length into NDEF TLV             */
52 
53     RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI, /* reset DSFID and AFI */
54     RW_I93_SUBSTATE_CHECK_READ_ONLY, /* check if any block is locked         */
55     RW_I93_SUBSTATE_WRITE_CC_NDEF_TLV, /* write CC and empty NDEF/Terminator TLV
56      */
57 
58     RW_I93_SUBSTATE_WAIT_UPDATE_CC, /* updating CC as read-only             */
59     RW_I93_SUBSTATE_LOCK_NDEF_TLV, /* lock blocks of NDEF TLV              */
60     RW_I93_SUBSTATE_WAIT_LOCK_CC /* lock block of CC                     */
61 };
62 
GKI_freebuf(void *)63 void GKI_freebuf(void*) {
64 }
65 
GKI_start_timer(uint8_t,int32_t,bool)66 void GKI_start_timer(uint8_t, int32_t, bool) {
67 }
68 
GKI_stop_timer(uint8_t)69 void GKI_stop_timer(uint8_t) {
70 }
71 
main()72 int main() {
73     tRW_I93_CB* p_i93 = &rw_cb.tcb.i93;
74 
75     GKI_init();
76     rw_init();
77 
78     uint8_t p_uid = 1;
79     if (rw_i93_select(&p_uid) != NFC_STATUS_OK) {
80         return EXIT_FAILURE;
81     }
82 
83     tNFC_CONN_CB* p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
84     tNFC_CONN_EVT event = NFC_DATA_CEVT;
85 
86     tNFC_CONN *p_data = (tNFC_CONN *) malloc(sizeof(tNFC_CONN));
87     if (!p_data) {
88         return EXIT_FAILURE;
89     }
90 
91     p_data->data.p_data = (NFC_HDR *) malloc(sizeof(uint8_t) * 32);
92     if (!(p_data->data.p_data)) {
93         free(p_data);
94         return EXIT_FAILURE;
95     }
96 
97     NFC_HDR *p_resp = (NFC_HDR*) p_data->data.p_data;
98     p_resp->len = 0;
99     p_resp->offset = 0;
100 
101     p_i93->state = RW_I93_STATE_UPDATE_NDEF;
102     p_i93->sub_state = RW_I93_SUBSTATE_RESET_LEN;
103     p_i93->block_size = 2 * (I93_MAX_BLOCK_LENGH + 1);
104     p_i93->ndef_tlv_start_offset = 2 * (I93_MAX_BLOCK_LENGH) - 1;
105     p_data->status = NFC_STATUS_OK;
106 
107     p_cb->p_cback(0, event, p_data);
108     free(p_data->data.p_data);
109     free(p_data);
110     return EXIT_SUCCESS;
111 }
112