欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android识别NFC芯片制造商的方法

程序员文章站 2022-03-18 12:37:51
如何识别?通过nfc模块的serial number即uid,用户访问权限为r只读,每颗nfc芯片独有序列号(uid),在出厂时写入,用户不能改写。android如何实现?通过intent获取uid...

如何识别?

通过nfc模块的serial number即uid,用户访问权限为r只读,每颗nfc芯片独有序列号(uid),在出厂时写入,用户不能改写。

android如何实现?

通过intent获取uid

    /**
     * 读取nfcuid 返回string类型大写的uid
     * 
     * 这个测试顺便加上的,下面用不到,做个笔记~~
     * 
     */
    public static string readuid(intent intent) throws unsupportedencodingexception {
        tag tagfromintent = intent.getparcelableextra(nfcadapter.extra_tag);
        byte[] uid = tagfromintent != null ? tagfromintent.getid() : null;
        return hexutil.encodehexstr(uid, false);
    }
    
    /**
     * 读取nfcuid 返回byte[]数组
     * 
     */
    public static byte[] readuid(intent intent) throws unsupportedencodingexception {
        tag tagfromintent = intent.getparcelableextra(nfcadapter.extra_tag);
        return tagfromintent.getid();
    }

hexutil工具类:

public class hexutil {

    /**
     * 用于建立十六进制字符的输出的小写字符数组
     */
    private static final char[] digits_lower = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            'a', 'b', 'c', 'd', 'e', 'f'};

    /**
     * 用于建立十六进制字符的输出的大写字符数组
     */
    private static final char[] digits_upper = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            'a', 'b', 'c', 'd', 'e', 'f'};

    /**
     * 将字节数组转换为十六进制字符数组
     *
     * @param data     byte[]
     * @param todigits 用于控制输出的char[]
     * @return 十六进制char[]
     */
    protected static char[] encodehex(byte[] data, char[] todigits) {
        int l = data.length;
        char[] out = new char[l << 1];
        // two characters form the hex value.
        for (int i = 0, j = 0; i < l; i++) {
            out[j++] = todigits[(0xf0 & data[i]) >>> 4];
            out[j++] = todigits[0x0f & data[i]];
        }
        return out;
    }

    /**
     * 将字节数组转换为十六进制字符串
     *
     * @param data        byte[]
     * @param tolowercase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
     * @return 十六进制string
     */
    public static string encodehexstr(byte[] data, boolean tolowercase) {
        return encodehexstr(data, tolowercase ? digits_lower : digits_upper);
    }

    /**
     * 将字节数组转换为十六进制字符串
     *
     * @param data     byte[]
     * @param todigits 用于控制输出的char[]
     * @return 十六进制string
     */
    protected static string encodehexstr(byte[] data, char[] todigits) {
        if (data == null) {
            return "";
        }
        return new string(encodehex(data, todigits));
    }
}
 

通过uid去查询厂商

public class manufacturer {

    private static final string mnf_unknown = "unknown manufacture";

    public static final map<byte, string> manufacturername;

    static {
        manufacturername = new hashmap<>();
        manufacturername.put((byte)1, "motorola");
        manufacturername.put((byte)2, "stmicroelectronics sa ");
        manufacturername.put((byte)3, "hitachi, ltd");
        manufacturername.put((byte)4, "nxp semiconductors");
        manufacturername.put((byte)5, "infineon technologies ag ");
        manufacturername.put((byte)6, "cylink");
        manufacturername.put((byte)7, "texas instrument");
        manufacturername.put((byte)8, "fujitsu limited");
        manufacturername.put((byte)9, "matsushita electronics corporation, semiconductor company");
        manufacturername.put((byte)10, "nec");
        manufacturername.put((byte)11, "oki electric industry co. ltd");
        manufacturername.put((byte)12, "toshiba corp");
        manufacturername.put((byte)13, "mitsubishi electric corp");
        manufacturername.put((byte)14, "samsung electronics co. ltd");
        manufacturername.put((byte)15, "hynix");
        manufacturername.put((byte)16, "lg-semiconductors co. ltd");
        manufacturername.put((byte)17, "emosyn-em microelectronics");
        manufacturername.put((byte)18, "inside technology");
        manufacturername.put((byte)19, "orga kartensysteme gmbh");
        manufacturername.put((byte)20, "sharp corporation");
        manufacturername.put((byte)21, "atmel");
        manufacturername.put((byte)22, "em microelectronic-marin sa");
        manufacturername.put((byte)23, "smartrac technology gmbh ");
        manufacturername.put((byte)24, "zmd ag");
        manufacturername.put((byte)25, "xicor, inc");
        manufacturername.put((byte)26, "sony corporation");
        manufacturername.put((byte)27, "malaysia microelectronic solutions sdn. bhd");
        manufacturername.put((byte)28, "emosyn");
        manufacturername.put((byte)29, "shanghai fudan microelectronics co. ltd");
        manufacturername.put((byte)30, "magellan technology pty limited");
        manufacturername.put((byte)31, "melexis nv bo");
        manufacturername.put((byte)32, "renesas technology corp");
        manufacturername.put((byte)33, "tagsys");
        manufacturername.put((byte)34, "transcore");
        manufacturername.put((byte)35, "shanghai belling corp., ltd");
        manufacturername.put((byte)36, "masktech germany gmbh");
        manufacturername.put((byte)37, "innovision research and technology plc");
        manufacturername.put((byte)38, "hitachi ulsi systems co., ltd");
        manufacturername.put((byte)39, "yubico ab ");
        manufacturername.put((byte)40, "ricoh");
        manufacturername.put((byte)41, "ask");
        manufacturername.put((byte)42, "unicore microsystems, llc");
        manufacturername.put((byte)43, "dallas semiconductor/maxim");
        manufacturername.put((byte)44, "impinj, inc");
        manufacturername.put((byte)45, "rightplug alliance");
        manufacturername.put((byte)46, "broadcom corporation");
        manufacturername.put((byte)47, "mstar semiconductor, inc");
        manufacturername.put((byte)48, "beedar technology inc");
        manufacturername.put((byte)49, "rfidsec");
        manufacturername.put((byte)50, "schweizer electronic ag ");
        manufacturername.put((byte)51, "amic technology corp");
        manufacturername.put((byte)52, "mikron jsc");
        manufacturername.put((byte)53, "fraunhofer institute for photonic microsystems");
        manufacturername.put((byte)54, "ids microchip ag");
        manufacturername.put((byte)55, "kovio");
        manufacturername.put((byte)56, "hmt microelectronic ltd");
        manufacturername.put((byte)57, "silicon craft technology");
        manufacturername.put((byte)58, "advanced film device inc");
        manufacturername.put((byte)59, "nitecrest ltd");
        manufacturername.put((byte)60, "verayo inc");
        manufacturername.put((byte)61, "hid global");
        manufacturername.put((byte)62, "productivity engineering gmbh");
        manufacturername.put((byte)63, "austriamicrosystems ag (reserved)");
        manufacturername.put((byte)64, "gemalto sa");
        manufacturername.put((byte)65, "renesas electronics corporation");
        manufacturername.put((byte)66, "3alogics inc");
        manufacturername.put((byte)67, "top troniq asia limited");
        manufacturername.put((byte)68, "gentag inc (usa)");
        manufacturername.put((byte)69, "invengo information technology co.ltd ");
        manufacturername.put((byte)70, "guangzhou sysur microelectronics, inc");
        manufacturername.put((byte)71, "ceitec s.a");
        manufacturername.put((byte)72, "shanghai quanray electronics co. ltd");
        manufacturername.put((byte)73, "mediatek inc");
        manufacturername.put((byte)74, "angstrem pjsc");
        manufacturername.put((byte)75, "celisic semiconductor (*) limited");
        manufacturername.put((byte)76, "legic identsystems ag");
        manufacturername.put((byte)77, "balluff gmbh");
        manufacturername.put((byte)78, "oberthur technologies ");
        manufacturername.put((byte)79, "silterra malaysia sdn. bhd");
        manufacturername.put((byte)80, "delta danish electronics, light & acoustics ");
        manufacturername.put((byte)81, "giesecke & devrient gmbh");
        manufacturername.put((byte)82, "shenzhen china vision microelectronics co., ltd");
        manufacturername.put((byte)83, "shanghai feiju microelectronics co. ltd");
        manufacturername.put((byte)84, "intel corporation");
        manufacturername.put((byte)85, "microsensys gmbh");
        manufacturername.put((byte)86, "sonix technology co., ltd");
        manufacturername.put((byte)87, "qualcomm technologies inc");
        manufacturername.put((byte)88, "realtek semiconductor corp");
        manufacturername.put((byte)89, "freevision technologies co. ltd");
        manufacturername.put((byte)90, "giantec semiconductor inc");
        manufacturername.put((byte)91, "jsc angstrem-t");
        manufacturername.put((byte)92, "starchip");
        manufacturername.put((byte)93, "spirtech");
        manufacturername.put((byte)94, "gantner electronic gmbh");
        manufacturername.put((byte)95, "nordic semiconductor");
        manufacturername.put((byte)96, "verisiti inc");
        manufacturername.put((byte)97, "wearlinks technology inc");
        manufacturername.put((byte)98, "userstar information systems co., ltd");
        manufacturername.put((byte)99, "pragmatic printing ltd");
        manufacturername.put((byte)100, "associado laboratde sistemas integrtecnollsi-tec");
        manufacturername.put((byte)101, "tendyron corporation");
        manufacturername.put((byte)102, "muto smart co., ltd");
        manufacturername.put((byte)103, "on semiconductor");
        manufacturername.put((byte)104, "tübitak bilgem");
        manufacturername.put((byte)105, "huada semiconductor co., ltd");
        manufacturername.put((byte)106, "seveney");
        manufacturername.put((byte)107, "issm");
        manufacturername.put((byte)108, "wisesec ltd");
        manufacturername.put((byte)126, "holtek");
        manufacturername.put((byte)-112, "shanghai fudan microelectronics co. ltd");
    }


    /**
     *  通过uid/serial number获取芯片制造商名字
     * @param paramarrayofbyte uid/serial number
     * @return 制造商名字
     */
    public static string getmanufacturerbyuid(byte[] paramarrayofbyte) {
        if (paramarrayofbyte != null)
            try {
                if (paramarrayofbyte.length == 8) {
                    byte[] arrayofbyte = new byte[3];
                    system.arraycopy(paramarrayofbyte, paramarrayofbyte.length - 3, arrayofbyte, 0, 3);
                    return arrays.equals(arrayofbyte, new byte[] { 29, 4, -32 })
                            ? manufacturername.get((byte)29) : (arrays.equals(arrayofbyte, new byte[] { -95, 4, -32 })
                            ? manufacturername.get((byte)29) : (arrays.equals(arrayofbyte, new byte[] { -94, 4, -32 })
                            ? manufacturername.get((byte)29) : manufacturername.get(paramarrayofbyte[6])));
                }
                if (paramarrayofbyte.length == 7)
                    return manufacturername.get(paramarrayofbyte[0]);
            } catch (exception exception) {
                exception.printstacktrace();
            }
        return mnf_unknown;
    }

到此这篇关于android识别nfc芯片制造商的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持