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 <string.h> 19 #include <llcp_int.h> 20 #include <nfc_int.h> 21 22 extern tLLCP_CB llcp_cb; 23 extern tNFC_CB nfc_cb; 24 void rw_init(void); 25 void llcp_init(void); 26 main()27int main() { 28 GKI_init(); 29 rw_init(); 30 llcp_init(); 31 32 tNFC_CONN *p_data = (tNFC_CONN *)malloc(sizeof(tNFC_CONN)); 33 if (!p_data) { 34 return EXIT_FAILURE; 35 } 36 // NOLINTNEXTLINE(clang-analyzer-unix.MallocSizeof) 37 p_data->data.p_data = (NFC_HDR *)malloc(16400 * sizeof(uint8_t)); 38 if (!(p_data->data.p_data)) { 39 free(p_data); 40 return EXIT_FAILURE; 41 } 42 nfc_cb.quick_timer_queue.p_first = (TIMER_LIST_ENT *)malloc(16); 43 if (!(nfc_cb.quick_timer_queue.p_first)) { 44 free(p_data); 45 free(p_data->data.p_data); 46 return EXIT_FAILURE; 47 } 48 49 uint8_t conn_id = 1; 50 llcp_cb.lcb.agreed_major_version = LLCP_MIN_SNL_MAJOR_VERSION; 51 llcp_cb.lcb.agreed_minor_version = LLCP_MIN_SNL_MINOR_VERSION; 52 llcp_cb.lcb.link_state = LLCP_LINK_STATE_ACTIVATED; 53 // Set llcp_cb.lcb.local_link_miu greater than p_msg->len 54 llcp_cb.lcb.local_link_miu = 16400; 55 llcp_cb.lcb.received_first_packet = true; 56 llcp_cb.lcb.symm_state = LLCP_LINK_SYMM_REMOTE_XMIT_NEXT; 57 tNFC_CONN_EVT event = NFC_DATA_CEVT; 58 59 NFC_HDR *p_msg = (NFC_HDR *)(p_data->data.p_data); 60 // p_msg->len is calculated based on the total PDUs in AGF PDU 61 p_msg->len = 16395; 62 p_msg->offset = 0; 63 uint8_t *p = (uint8_t *)(p_msg + 1) + p_msg->offset; 64 // First 2 bytes are set to values so that call flow goes from llcp_link_proc_rx_data 65 // to llcp_link_proc_rx_pdu and then to llcp_link_proc_agf_pdu. 66 *p = 0x00; 67 *(p + 1) = 0x80; 68 // The following are trying to emulate PDUs in AGF PDU 69 *(p + 2) = 0x00; 70 *(p + 3) = 0x02; 71 *(p + 4) = 0x02; 72 *(p + 5) = 0x40; 73 *(p + 6) = 0x00; 74 *(p + 7) = 0x01; 75 *(p + 8) = 0x02; 76 *(p + 9) = 0x40; 77 *(p + 10) = 0x00; 78 *(p + 11) = 0x02; 79 *(p + 12) = 0x40; 80 81 llcp_link_connection_cback(conn_id, event, p_data); 82 83 free(p_data); 84 free(nfc_cb.quick_timer_queue.p_first); 85 return EXIT_SUCCESS; 86 } 87