Ejemplo n.º 1
0
        /**
         * Constructor of DataCode
         *
         * @param u8    the character to be transformed
         * @param index the index of the char
         */
        public DataCode(char u8, int index)
        {
            if (index > INDEX_MAX)
            {
                throw new EsptouchException("index > INDEX_MAX");
            }
            byte[] dataBytes = ByteUtil.splitUint8To2bytes(u8);
            mDataHigh = dataBytes[0];
            mDataLow  = dataBytes[1];

            CRC8 crc8 = new CRC8();

            crc8.update(ByteUtil.convertUint8toByte(u8));
            crc8.update(index);

            byte[] crcBytes = ByteUtil.splitUint8To2bytes((char)crc8.getValue());
            mCrcHigh   = crcBytes[0];
            mCrcLow    = crcBytes[1];
            mSeqHeader = (byte)index;
        }
Ejemplo n.º 2
0
        /**
         * Constructor of DatumCode
         *
         * @param apSsid      the Ap's ssid
         * @param apBssid     the Ap's bssid
         * @param apPassword  the Ap's password
         * @param ipAddress   the ip address of the phone or pad
         * @param encryptor null use origin data, not null use encrypted data
         */
        public DatumCode(byte[] apSsid, byte[] apBssid, byte[] apPassword,
                         IPAddress ipAddress, ITouchEncryptor encryptor)
        {
            // Data = total len(1 byte) + apPwd len(1 byte) + SSID CRC(1 byte) +
            // BSSID CRC(1 byte) + TOTAL XOR(1 byte)+ ipAddress(4 byte) + apPwd + apSsid apPwdLen <=
            // 105 at the moment

            // total xor
            char totalXor = (char)0;

            char apPwdLen = (char)apPassword.Length;
            CRC8 crc      = new CRC8();

            crc.update(apSsid);
            char apSsidCrc = (char)crc.getValue();

            crc.reset();
            crc.update(apBssid);
            char apBssidCrc = (char)crc.getValue();

            char apSsidLen = (char)apSsid.Length;

            byte[] ipBytes = ipAddress.GetAddressBytes();
            int    ipLen   = ipBytes.Length;

            char totalLen = (char)(EXTRA_HEAD_LEN + ipLen + apPwdLen + apSsidLen);

            // build data codes
            mDataCodes = new List <DataCode>();
            mDataCodes.Add(new DataCode(totalLen, 0));
            totalXor ^= totalLen;
            mDataCodes.Add(new DataCode(apPwdLen, 1));
            totalXor ^= apPwdLen;
            mDataCodes.Add(new DataCode(apSsidCrc, 2));
            totalXor ^= apSsidCrc;
            mDataCodes.Add(new DataCode(apBssidCrc, 3));
            totalXor ^= apBssidCrc;
            // ESPDataCode 4 is null
            for (int i = 0; i < ipLen; ++i)
            {
                char c = ByteUtil.convertByte2Uint8(ipBytes[i]);
                totalXor ^= c;
                mDataCodes.Add(new DataCode(c, i + EXTRA_HEAD_LEN));
            }

            for (int i = 0; i < apPassword.Length; i++)
            {
                char c = ByteUtil.convertByte2Uint8(apPassword[i]);
                totalXor ^= c;
                mDataCodes.Add(new DataCode(c, i + EXTRA_HEAD_LEN + ipLen));
            }

            // totalXor will xor apSsidChars no matter whether the ssid is hidden
            for (int i = 0; i < apSsid.Length; i++)
            {
                char c = ByteUtil.convertByte2Uint8(apSsid[i]);
                totalXor ^= c;
                mDataCodes.Add(new DataCode(c, i + EXTRA_HEAD_LEN + ipLen + apPwdLen));
            }

            // add total xor last
            mDataCodes.Insert(4, new DataCode(totalXor, 4));

            // add bssid
            int bssidInsertIndex = EXTRA_HEAD_LEN;

            for (int i = 0; i < apBssid.Length; i++)
            {
                int      index = totalLen + i;
                char     c     = ByteUtil.convertByte2Uint8(apBssid[i]);
                DataCode dc    = new DataCode(c, index);
                if (bssidInsertIndex >= mDataCodes.Count)
                {
                    mDataCodes.Add(dc);
                }
                else
                {
                    mDataCodes.Insert(bssidInsertIndex, dc);
                }
                bssidInsertIndex += 4;
            }
        }