Search in sources :

Example 26 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by crdroidandroid.

the class DhcpPacketTest method testBug2136.

@SmallTest
public void testBug2136() throws Exception {
    final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(// Ethernet header.
    "bcf5ac000000d0c7890000000800" + // IP header.
    "4500014c00000000ff119beac3eaf3880a3f5d04" + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation).
    "0043004401387574" + // BOOTP header.
    "0201060163339a3000050000000000000a209ecd0000000000000000" + // MAC address.
    "bcf5ac00000000000000000000000000" + // Server name.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options.
    "6382536335010236040a20ff80330400001c200104fffff00003040a20900106089458413494584135" + "0f0b6c616e63732e61632e756b000000000000000000ff00000000"));
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L2);
    assertTrue(offerPacket instanceof DhcpOfferPacket);
    assertEquals("BCF5AC000000", HexDump.toHexString(offerPacket.getClientMac()));
    DhcpResults dhcpResults = offerPacket.toDhcpResults();
    assertDhcpResults("10.32.158.205/20", "10.32.144.1", "148.88.65.52,148.88.65.53", "lancs.ac.uk", "10.32.255.128", null, 7200, false, 0, dhcpResults);
}
Also used : DhcpResults(android.net.DhcpResults) ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 27 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by crdroidandroid.

the class DhcpPacketTest method checkMtu.

private void checkMtu(ByteBuffer packet, int expectedMtu, byte[] mtuBytes) throws Exception {
    if (mtuBytes != null) {
        packet.position(packet.capacity() - mtuBytes.length);
        packet.put(mtuBytes);
        packet.clear();
    }
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
    // Implicitly checks it's non-null.
    assertTrue(offerPacket instanceof DhcpOfferPacket);
    DhcpResults dhcpResults = offerPacket.toDhcpResults();
    assertDhcpResults("192.168.159.247/20", "192.168.159.254", "8.8.8.8,8.8.4.4", null, "192.168.144.3", null, 7200, false, expectedMtu, dhcpResults);
}
Also used : DhcpResults(android.net.DhcpResults) DhcpPacket(android.net.dhcp.DhcpPacket)

Example 28 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by crdroidandroid.

the class DhcpPacketTest method testMultipleRouters.

@SmallTest
public void testMultipleRouters() throws Exception {
    final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(// Ethernet header.
    "fc3d93000000" + "081735000000" + "0800" + // IP header.
    "45000148c2370000ff117ac2c0a8bd02ffffffff" + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation).
    "0043004401343beb" + // BOOTP header.
    "0201060027f518e20000800000000000c0a8bd310000000000000000" + // MAC address.
    "fc3d9300000000000000000000000000" + // Server name.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options.
    "638253633501023604c0abbd023304000070803a04000038403b04000062700104ffffff00" + "0308c0a8bd01ffffff0006080808080808080404ff000000000000"));
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L2);
    assertTrue(offerPacket instanceof DhcpOfferPacket);
    assertEquals("FC3D93000000", HexDump.toHexString(offerPacket.getClientMac()));
    DhcpResults dhcpResults = offerPacket.toDhcpResults();
    assertDhcpResults("192.168.189.49/24", "192.168.189.1", "8.8.8.8,8.8.4.4", null, "192.171.189.2", null, 28800, false, 0, dhcpResults);
}
Also used : DhcpResults(android.net.DhcpResults) ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 29 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by ParanoidAndroid.

the class WifiService method getDhcpInfo.

/**
     * Return the DHCP-assigned addresses from the last successful DHCP request,
     * if any.
     * @return the DHCP information
     * @deprecated
     */
public DhcpInfo getDhcpInfo() {
    enforceAccessPermission();
    DhcpResults dhcpResults = mWifiStateMachine.syncGetDhcpResults();
    if (dhcpResults.linkProperties == null)
        return null;
    DhcpInfo info = new DhcpInfo();
    for (LinkAddress la : dhcpResults.linkProperties.getLinkAddresses()) {
        InetAddress addr = la.getAddress();
        if (addr instanceof Inet4Address) {
            info.ipAddress = NetworkUtils.inetAddressToInt((Inet4Address) addr);
            break;
        }
    }
    for (RouteInfo r : dhcpResults.linkProperties.getRoutes()) {
        if (r.isDefaultRoute()) {
            InetAddress gateway = r.getGateway();
            if (gateway instanceof Inet4Address) {
                info.gateway = NetworkUtils.inetAddressToInt((Inet4Address) gateway);
            }
        } else if (r.hasGateway() == false) {
            LinkAddress dest = r.getDestination();
            if (dest.getAddress() instanceof Inet4Address) {
                info.netmask = NetworkUtils.prefixLengthToNetmaskInt(dest.getNetworkPrefixLength());
            }
        }
    }
    int dnsFound = 0;
    for (InetAddress dns : dhcpResults.linkProperties.getDnses()) {
        if (dns instanceof Inet4Address) {
            if (dnsFound == 0) {
                info.dns1 = NetworkUtils.inetAddressToInt((Inet4Address) dns);
            } else {
                info.dns2 = NetworkUtils.inetAddressToInt((Inet4Address) dns);
            }
            if (++dnsFound > 1)
                break;
        }
    }
    InetAddress serverAddress = dhcpResults.serverAddress;
    if (serverAddress instanceof Inet4Address) {
        info.serverAddress = NetworkUtils.inetAddressToInt((Inet4Address) serverAddress);
    }
    info.leaseDuration = dhcpResults.leaseDuration;
    return info;
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) DhcpResults(android.net.DhcpResults) DhcpInfo(android.net.DhcpInfo) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 30 with DhcpResults

use of android.net.DhcpResults in project android_frameworks_base by ParanoidAndroid.

the class BluetoothTetheringDataTracker method startReverseTether.

void startReverseTether(final LinkProperties linkProperties) {
    if (linkProperties == null || TextUtils.isEmpty(linkProperties.getInterfaceName())) {
        Log.e(TAG, "attempted to reverse tether with empty interface");
        return;
    }
    synchronized (mLinkPropertiesLock) {
        if (mLinkProperties.getInterfaceName() != null) {
            Log.e(TAG, "attempted to reverse tether while already in process");
            return;
        }
        mLinkProperties = linkProperties;
    }
    Thread dhcpThread = new Thread(new Runnable() {

        public void run() {
            //Currently this thread runs independently.
            DhcpResults dhcpResults = new DhcpResults();
            boolean success = NetworkUtils.runDhcp(linkProperties.getInterfaceName(), dhcpResults);
            synchronized (mLinkPropertiesLock) {
                if (linkProperties.getInterfaceName() != mLinkProperties.getInterfaceName()) {
                    Log.e(TAG, "obsolete DHCP run aborted");
                    return;
                }
                if (!success) {
                    Log.e(TAG, "DHCP request error:" + NetworkUtils.getDhcpError());
                    return;
                }
                mLinkProperties = dhcpResults.linkProperties;
                synchronized (mNetworkInfoLock) {
                    mNetworkInfo.setIsAvailable(true);
                    mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, null);
                    if (mCsHandler != null) {
                        Message msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, new NetworkInfo(mNetworkInfo));
                        msg.sendToTarget();
                    }
                }
                return;
            }
        }
    });
    dhcpThread.start();
}
Also used : Message(android.os.Message) NetworkInfo(android.net.NetworkInfo) DhcpResults(android.net.DhcpResults)

Aggregations

DhcpResults (android.net.DhcpResults)55 DhcpPacket (android.net.dhcp.DhcpPacket)40 ByteBuffer (java.nio.ByteBuffer)36 SmallTest (android.test.suitebuilder.annotation.SmallTest)28 LinkAddress (android.net.LinkAddress)9 Inet4Address (java.net.Inet4Address)5 LinkProperties (android.net.LinkProperties)4 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)4 DhcpInfo (android.net.DhcpInfo)1 NetworkInfo (android.net.NetworkInfo)1 RouteInfo (android.net.RouteInfo)1 Message (android.os.Message)1 InetAddress (java.net.InetAddress)1