Skip to content

Commit 01ed0fc

Browse files
luk1337AKoskovich
authored andcommitted
Add reverse engineered nqnfcinfo binary
Change-Id: I0fef4aff6f66570faf1e5680134f09b353e2205d Co-authored-by: Alexander Koskovich <[email protected]>
1 parent de147ee commit 01ed0fc

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

nqnfcinfo/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../build/soong/scripts/system-clang-format

nqnfcinfo/Android.bp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cc_binary {
2+
name: "nqnfcinfo",
3+
vendor: true,
4+
5+
cflags: [
6+
"-Wall",
7+
"-Werror",
8+
"-Wextra",
9+
],
10+
11+
srcs: [
12+
"main.cpp",
13+
],
14+
15+
header_libs: ["generated_kernel_headers"],
16+
17+
shared_libs: [
18+
"libc",
19+
"libbase"
20+
],
21+
}

nqnfcinfo/main.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2022 The LineageOS 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+
#define LOG_TAG "nqnfcinfo"
18+
19+
#include <errno.h>
20+
#include <fcntl.h>
21+
22+
#include <fmt/format.h>
23+
24+
#include <android-base/logging.h>
25+
#include <android-base/properties.h>
26+
27+
#include <linux/nfc/nfcinfo.h>
28+
29+
using ::android::base::SetProperty;
30+
31+
#define NQ_NCI_PATH "/dev/nq-nci"
32+
33+
int main() {
34+
// Open our fd
35+
int fd = open(NQ_NCI_PATH, O_RDONLY);
36+
37+
// Make sure we could get the fd
38+
if (fd < 0) {
39+
LOG(ERROR) << "Could not open " << NQ_NCI_PATH << ": " << strerror(errno);
40+
return fd;
41+
}
42+
43+
// NXP's kernel driver returns a struct that is union'ed with an integer
44+
// as the return value of the IOCTL call here. Presumably this is to avoid
45+
// dealing with copying memory to/from userspace, but it's a little silly
46+
// Since this is an unsigned type, I don't know how to check for errors...
47+
nqx_uinfo info{};
48+
info.i = ioctl(fd, NFCC_GET_INFO, 0);
49+
50+
// Close fd
51+
close(fd);
52+
53+
// Set properties based on IOCTL return
54+
SetProperty("vendor.qti.nfc.chipid", fmt::format("{:#02x}", info.info.chip_type));
55+
SetProperty("vendor.qti.nfc.fwver", fmt::format("{:02x}.{:02x}.{:02x}", info.info.rom_version,
56+
info.info.fw_major, info.info.fw_minor));
57+
58+
return 0;
59+
}

0 commit comments

Comments
 (0)