1.2.1.19.51 TCPIP_SNMP_VarbindGet Function

C

bool TCPIP_SNMP_VarbindGet(
    SNMP_ID var, 
    SNMP_INDEX index, 
    uint8_t* ref, 
    SNMP_VAL* val
);

Description

This is a callback function called by SNMP module. This function is called only when SNMP GET, GETNEXT and GETBULK request is made. This function content is modified by the application developer. This function contains the implementation of READ enable MIB OID macros.

mib2bib.jar Microchip MIB compiler utility is used to generate mib.h, which lists all the MIB OID ID value.

Preconditions

TCPIP_SNMP_ProcessVariables() is called.

Parameters

ParametersDescription
varVariable id whose value is to be returned.
indexFor a scalar variable , Index value is zero. For sequence variable index value specifies which index value need to be set.
refVariable reference used to transfer multi-byte data. It is always SNMP_START_OF_VAR when very first byte is requested. Otherwise, use this as a reference to keep track of multi-byte transfers.
valUp to 4 byte data value: - If var data type is uint8_t, variable value is in val->byte - If var data type is uint16_t, variable value is in val->word - If var data type is uint32_t, variable value is in val->dword.- If var data type is IP_ADDRESS, transfer data in val->v or val->dword - If var data type is COUNTER32, TIME_TICKS or GAUGE32, transfer data in val->dword - If var data type is ASCII_STRING or OCTET_STRING transfer data in val->byte using multi-byte transfer mechanism.

Returns

  • True - If a value exists for given variable.

  • False - If a value does not exist for a given variable.

Remarks

This function may get called more than once depending on number of bytes in a specific get request for given variable. only dynamic read variables needs to be handled.

Example

// In the beginning *ref is equal to SNMP_START_OF_VAR
myRef = *ref;
switch(var)
{
// TRAP_COMMUNITY - generated from the Microchip style MIB script using mib2bib.jar,
// is a Sequence variable.
    case TRAP_COMMUNITY:   
        if ( index < trapInfo.Size )
        {
        // check if the myRef should not cross the maximum length 
            if ( myRef == trapInfo.table[index].communityLen )
            {
            // End of SNMP GET process
                *ref = SNMP_END_OF_VAR;
                return true;
            }
            if ( trapInfo.table[index].communityLen == 0u )
                *ref = SNMP_END_OF_VAR; // End of SNMP GET process
            else
            {
                // Start of SNMP GET process byte by byte
                val->byte = trapInfo.table[index].community[myRef];
                myRef++;
                *ref = myRef;
            }
            return true;
        }
        break;
// LED_D5 - generated from the Microchip style MIB script using mib2bib.jar is a scalar variable
    case LED_D5:
        val->byte = LED2_IO;
        return true;
}