nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2009-2014 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains functions that interface with the NFC NCI transport. |
| 22 | * On the receive side, it routes events to the appropriate handler |
| 23 | * (callback). On the transmit side, it manages the command transmission. |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | #include <string.h> |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 27 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 28 | #include <android-base/stringprintf.h> |
| 29 | #include <base/logging.h> |
| 30 | |
| 31 | #include "nfc_target.h" |
| 32 | |
| 33 | #include "bt_types.h" |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 34 | #include "ce_api.h" |
| 35 | #include "ce_int.h" |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 36 | |
| 37 | using android::base::StringPrintf; |
| 38 | |
| 39 | extern bool nfc_debug_enabled; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 40 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 41 | tCE_CB ce_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 42 | |
| 43 | /******************************************************************************* |
| 44 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 45 | void ce_init(void) { |
| 46 | memset(&ce_cb, 0, sizeof(tCE_CB)); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 47 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 48 | /* Initialize tag-specific fields of ce control block */ |
| 49 | ce_t3t_init(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /******************************************************************************* |
| 53 | ** |
| 54 | ** Function CE_SendRawFrame |
| 55 | ** |
| 56 | ** Description This function sends a raw frame to the peer device. |
| 57 | ** |
| 58 | ** Returns tNFC_STATUS |
| 59 | ** |
| 60 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 61 | tNFC_STATUS CE_SendRawFrame(uint8_t* p_raw_data, uint16_t data_len) { |
| 62 | tNFC_STATUS status = NFC_STATUS_FAILED; |
| 63 | NFC_HDR* p_data; |
| 64 | uint8_t* p; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 65 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 66 | if (ce_cb.p_cback) { |
| 67 | /* a valid opcode for RW */ |
| 68 | p_data = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 69 | if (p_data) { |
| 70 | p_data->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 71 | p = (uint8_t*)(p_data + 1) + p_data->offset; |
| 72 | memcpy(p, p_raw_data, data_len); |
| 73 | p_data->len = data_len; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 74 | DLOG_IF(INFO, nfc_debug_enabled) |
| 75 | << StringPrintf("CE SENT raw frame (0x%x)", data_len); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 76 | status = NFC_SendData(NFC_RF_CONN_ID, p_data); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 77 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 78 | } |
| 79 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /******************************************************************************* |
| 83 | ** |
| 84 | ** Function CE_SetActivatedTagType |
| 85 | ** |
| 86 | ** Description This function selects the tag type for CE mode. |
| 87 | ** |
| 88 | ** Returns tNFC_STATUS |
| 89 | ** |
| 90 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 91 | tNFC_STATUS CE_SetActivatedTagType(tNFC_ACTIVATE_DEVT* p_activate_params, |
| 92 | uint16_t t3t_system_code, |
| 93 | tCE_CBACK* p_cback) { |
| 94 | tNFC_STATUS status = NFC_STATUS_FAILED; |
| 95 | tNFC_PROTOCOL protocol = p_activate_params->protocol; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 96 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 97 | DLOG_IF(INFO, nfc_debug_enabled) |
| 98 | << StringPrintf("CE_SetActivatedTagType protocol:%d", protocol); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 99 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 100 | switch (protocol) { |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 101 | case NFC_PROTOCOL_T1T: |
| 102 | case NFC_PROTOCOL_T2T: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 103 | return NFC_STATUS_FAILED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 104 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 105 | case NFC_PROTOCOL_T3T: /* Type3Tag - NFC-F */ |
| 106 | /* store callback function before NFC_SetStaticRfCback () */ |
| 107 | ce_cb.p_cback = p_cback; |
| 108 | status = ce_select_t3t(t3t_system_code, |
| 109 | p_activate_params->rf_tech_param.param.lf.nfcid2); |
| 110 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 111 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 112 | case NFC_PROTOCOL_ISO_DEP: /* ISODEP/4A,4B- NFC-A or NFC-B */ |
| 113 | /* store callback function before NFC_SetStaticRfCback () */ |
| 114 | ce_cb.p_cback = p_cback; |
| 115 | status = ce_select_t4t(); |
| 116 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 117 | |
| 118 | default: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 119 | LOG(ERROR) << StringPrintf("CE_SetActivatedTagType Invalid protocol"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 120 | return NFC_STATUS_FAILED; |
| 121 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 122 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 123 | if (status != NFC_STATUS_OK) { |
| 124 | NFC_SetStaticRfCback(NULL); |
| 125 | ce_cb.p_cback = NULL; |
| 126 | } |
| 127 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 128 | } |