package org.snmp4j;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import org.snmp4j.asn1.BER;
import org.snmp4j.smi.AbstractVariable;
import org.snmp4j.smi.Counter64;
import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.IpAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.TimeTicks;
import org.snmp4j.smi.Variable;
import org.snmp4j.smi.VariableBinding;

/* JADX INFO: loaded from: classes.dex */
public class PDUv1 extends PDU {
    public static final int AUTHENTICATIONFAILURE = 4;
    public static final int COLDSTART = 0;
    public static final int ENTERPRISE_SPECIFIC = 6;
    public static final int LINKDOWN = 2;
    public static final int LINKUP = 3;
    private static final String OPERATION_NOT_SUPPORTED = "Operation not supported for SNMPv1 PDUs";
    public static final int WARMSTART = 1;
    private static final long serialVersionUID = -6478805117911347898L;
    private IpAddress agentAddress;
    private OID enterprise;
    private Integer32 genericTrap;
    private Integer32 specificTrap;
    private TimeTicks timestamp;

    public PDUv1() {
        this.enterprise = new OID();
        this.agentAddress = new IpAddress("0.0.0.0");
        this.genericTrap = new Integer32(0);
        this.specificTrap = new Integer32(0);
        this.timestamp = new TimeTicks(0L);
        setType(-92);
    }

    private void checkV1TRAP() {
        if (getType() != -92) {
            throw new UnsupportedOperationException("Operation is only supported for SNMPv1 trap PDUs (V1TRAP)");
        }
    }

    protected void checkNull(Variable variable) {
        if (variable == null) {
            throw new NullPointerException("Members of PDUv1 must not be null");
        }
    }

    @Override // org.snmp4j.PDU
    public Object clone() {
        return new PDUv1(this);
    }

    /* JADX WARN: Code restructure failed: missing block: B:6:0x001b, code lost:
    
        if (org.snmp4j.SNMP4JSettings.isAllowSNMPv2InV1() != false) goto L7;
     */
    @Override // org.snmp4j.PDU, org.snmp4j.asn1.BERSerializable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void decodeBER(org.snmp4j.asn1.BERInputStream r10) throws java.io.IOException {
        /*
            Method dump skipped, instruction units count: 258
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: org.snmp4j.PDUv1.decodeBER(org.snmp4j.asn1.BERInputStream):void");
    }

    @Override // org.snmp4j.PDU, org.snmp4j.asn1.BERSerializable
    public void encodeBER(OutputStream outputStream) throws IOException {
        BER.encodeHeader(outputStream, this.type, getBERPayloadLength());
        if (this.type == -92) {
            this.enterprise.encodeBER(outputStream);
            this.agentAddress.encodeBER(outputStream);
            this.genericTrap.encodeBER(outputStream);
            this.specificTrap.encodeBER(outputStream);
            this.timestamp.encodeBER(outputStream);
        } else {
            this.requestID.encodeBER(outputStream);
            this.errorStatus.encodeBER(outputStream);
            this.errorIndex.encodeBER(outputStream);
        }
        int bERLength = 0;
        Iterator<VariableBinding> it = this.variableBindings.iterator();
        while (it.hasNext()) {
            bERLength += it.next().getBERLength();
        }
        BER.encodeHeader(outputStream, 48, bERLength);
        for (VariableBinding variableBinding : this.variableBindings) {
            if (!isVariableV1(variableBinding.getVariable())) {
                throw new IOException("Cannot encode Counter64 into a SNMPv1 PDU");
            }
            variableBinding.encodeBER(outputStream);
        }
    }

    @Override // org.snmp4j.PDU
    public boolean equals(Object obj) {
        if (!(obj instanceof PDUv1)) {
            return super.equals(obj);
        }
        PDUv1 pDUv1 = (PDUv1) obj;
        return super.equals(obj) && AbstractVariable.equal(this.enterprise, pDUv1.enterprise) && AbstractVariable.equal(this.agentAddress, pDUv1.agentAddress) && AbstractVariable.equal(this.genericTrap, pDUv1.genericTrap) && AbstractVariable.equal(this.specificTrap, pDUv1.specificTrap) && AbstractVariable.equal(this.timestamp, pDUv1.timestamp);
    }

    public IpAddress getAgentAddress() {
        checkV1TRAP();
        return this.agentAddress;
    }

    @Override // org.snmp4j.PDU
    protected int getBERPayloadLengthPDU() {
        if (getType() != -92) {
            return super.getBERPayloadLengthPDU();
        }
        int bERLength = 0;
        Iterator<VariableBinding> it = this.variableBindings.iterator();
        while (it.hasNext()) {
            bERLength += it.next().getBERLength();
        }
        return bERLength + BER.getBERLengthOfLength(bERLength) + 1 + this.agentAddress.getBERLength() + this.enterprise.getBERLength() + this.genericTrap.getBERLength() + this.specificTrap.getBERLength() + this.timestamp.getBERLength();
    }

    public OID getEnterprise() {
        checkV1TRAP();
        return this.enterprise;
    }

    public int getGenericTrap() {
        checkV1TRAP();
        return this.genericTrap.getValue();
    }

    @Override // org.snmp4j.PDU
    public int getMaxRepetitions() {
        throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
    }

    public int getSpecificTrap() {
        checkV1TRAP();
        return this.specificTrap.getValue();
    }

    public long getTimestamp() {
        checkV1TRAP();
        return this.timestamp.getValue();
    }

    protected boolean isVariableV1(Variable variable) {
        return !(variable instanceof Counter64) || SNMP4JSettings.isAllowSNMPv2InV1();
    }

    public void setAgentAddress(IpAddress ipAddress) {
        checkV1TRAP();
        checkNull(ipAddress);
        this.agentAddress = ipAddress;
    }

    public void setEnterprise(OID oid) {
        checkV1TRAP();
        checkNull(oid);
        this.enterprise = (OID) oid.clone();
    }

    public void setGenericTrap(int i2) {
        checkV1TRAP();
        this.genericTrap.setValue(i2);
    }

    @Override // org.snmp4j.PDU
    public void setMaxRepetitions(int i2) {
        throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
    }

    public void setMaxSizeScopedPDU(int i2) {
        throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
    }

    @Override // org.snmp4j.PDU
    public void setNonRepeaters(int i2) {
        throw new UnsupportedOperationException(OPERATION_NOT_SUPPORTED);
    }

    public void setSpecificTrap(int i2) {
        checkV1TRAP();
        this.specificTrap.setValue(i2);
    }

    public void setTimestamp(long j2) {
        checkV1TRAP();
        this.timestamp.setValue(j2);
    }

    @Override // org.snmp4j.PDU
    public String toString() {
        if (this.type != -92) {
            return super.toString();
        }
        StringBuilder sb = new StringBuilder();
        sb.append(PDU.getTypeString(this.type));
        sb.append("[reqestID=");
        sb.append(this.requestID);
        sb.append(",timestamp=");
        sb.append(this.timestamp);
        sb.append(",enterprise=");
        sb.append(this.enterprise);
        sb.append(",genericTrap=");
        sb.append(this.genericTrap);
        sb.append(",specificTrap=");
        sb.append(this.specificTrap);
        sb.append(", VBS[");
        int i2 = 0;
        while (i2 < this.variableBindings.size()) {
            sb.append(this.variableBindings.get(i2));
            i2++;
            if (i2 < this.variableBindings.size()) {
                sb.append("; ");
            }
        }
        sb.append("]]");
        return sb.toString();
    }

    public PDUv1(PDUv1 pDUv1) {
        super(pDUv1);
        this.enterprise = new OID();
        this.agentAddress = new IpAddress("0.0.0.0");
        this.genericTrap = new Integer32(0);
        this.specificTrap = new Integer32(0);
        this.timestamp = new TimeTicks(0L);
        this.enterprise = (OID) pDUv1.enterprise.clone();
        this.agentAddress = (IpAddress) pDUv1.agentAddress.clone();
        this.genericTrap = (Integer32) pDUv1.genericTrap.clone();
        this.specificTrap = (Integer32) pDUv1.specificTrap.clone();
        this.timestamp = (TimeTicks) pDUv1.timestamp.clone();
    }
}
