-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
236 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/java/cc/ioctl/nfcdevicehost/decoder/IoctlDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package cc.ioctl.nfcdevicehost.decoder; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
public class IoctlDecoder { | ||
|
||
@NonNull | ||
public static String requestToString(int request) { | ||
int dir = (request >> 30) & 0x3; | ||
int size = (request >> 16) & 0x3f; | ||
int type = (request >> 8) & 0xff; | ||
int nr = request & 0xff; | ||
String dirStr; | ||
switch (dir) { | ||
case 0: | ||
dirStr = "IO"; | ||
break; | ||
case 1: | ||
dirStr = "IOW"; | ||
break; | ||
case 2: | ||
dirStr = "IOR"; | ||
break; | ||
case 3: | ||
dirStr = "IOWR"; | ||
break; | ||
default: | ||
// should never happen | ||
throw new IllegalArgumentException("Invalid direction"); | ||
} | ||
String nrStr = nr < 10 ? String.valueOf(nr) : String.format(Locale.ROOT, "0x%02X", nr); | ||
return (dir == 0 && size == 0) ? String.format(Locale.ROOT, "%s(0x%02X, %s)", dirStr, type, nrStr) | ||
: String.format(Locale.ROOT, "%s(0x%02X, %s, %d)", dirStr, type, nrStr, size); | ||
} | ||
|
||
@Nullable | ||
public static String getIoctlRequestName(int request) { | ||
return IOCTL_NAMES.get(request); | ||
} | ||
|
||
public static int IO(int type, int nr) { | ||
return (0 << 30) | (0 << 16) | (type << 8) | nr; | ||
} | ||
|
||
public static int IOW(int type, int nr, int size) { | ||
return (1 << 30) | (size << 16) | (type << 8) | nr; | ||
} | ||
|
||
public static int IOR(int type, int nr, int size) { | ||
return (2 << 30) | (size << 16) | (type << 8) | nr; | ||
} | ||
|
||
public static int IOWR(int type, int nr, int size) { | ||
return (3 << 30) | (size << 16) | (type << 8) | nr; | ||
} | ||
|
||
private static final Map<Integer, String> IOCTL_NAMES = new HashMap<>(); | ||
|
||
static { | ||
// /dev/nq-nci | ||
IOCTL_NAMES.put(IOW(0xE9, 0x01, 0x04), "NFC_SET_PWR"); | ||
IOCTL_NAMES.put(IOW(0xE9, 0x02, 0x04), "ESE_SET_PWR"); | ||
IOCTL_NAMES.put(IOR(0xE9, 0x03, 0x04), "ESE_GET_PWR"); | ||
IOCTL_NAMES.put(IO(0xE9, 0x04), "NFC_GET_PLATFORM_TYPE"); | ||
IOCTL_NAMES.put(IOW(0xE9, 0x05, 4), "NFC_GET_IRQ_STATE"); | ||
// /dev/assd | ||
IOCTL_NAMES.put(IO('A', 0x00), "ASSD_IOC_ENABLE"); | ||
IOCTL_NAMES.put(IOWR('A', 0x01, 4), "ASSD_IOC_TRANSCEIVE"); | ||
IOCTL_NAMES.put(IOWR('A', 0x01, 8), "ASSD_IOC_TRANSCEIVE"); | ||
IOCTL_NAMES.put(IO('A', 0x02), "ASSD_IOC_PROBE"); | ||
IOCTL_NAMES.put(IOW('A', 0x03, 4), "ASSD_IOC_WAIT"); | ||
IOCTL_NAMES.put(IOWR('A', 0x04, 4), "ASSD_IOC_SET_TIMEOUT"); | ||
IOCTL_NAMES.put(IOR('A', 0x05, 4), "ASSD_IOC_GET_VERSION"); | ||
IOCTL_NAMES.put(IOR('A', 0x05, 8), "ASSD_IOC_GET_VERSION"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.