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