TCPIP_SNMP_VarbindSet Function

C

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

Description

This is a callback function called by module for SNMP SET request. This function content is modified by the application developer. This function contains the implementation of WRITE 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
varWrite enable Variable id whose value is to be set.
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 0 if first byte is set otherwise non zero value to indicate corresponding byte being set. SNMP set will performed until ref is not equal to SNMP_END_OF_VAR and SNMP set starts with ref = SNMP_START_OF_VAR.
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, COUNTER32, or GAUGE32, value is in val->dword - If var data type is OCTET_STRING, ASCII_STRING value is in val->byte; multi-byte transfer will be performed to transfer remaining bytes of data.

Returns

  • True - If it is okay to set more byte(s).

  • False - If it is not okay to set more byte(s).

Remarks

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

Example

switch(var)
{
    // LED_D5 - generated from the Microchip style MIB script using mib2bib.jar is a scalar variable
    case LED_D5:
        LED2_IO = val.byte;
        return true;
        
    // TRAP_COMMUNITY - generated from the Microchip style MIB script using mib2bib.jar,
    // is a Sequence variable.  
    
    case TRAP_COMMUNITY:
        // Since this is a ASCII_STRING data type, SNMP will call with
        // SNMP_END_OF_VAR to indicate no more bytes or end of SNMP SET process
        // Use this information to determine if we just added new row
        // or updated an existing one.
        if ( ref ==  SNMP_END_OF_VAR )
        {
            // Index equal to table size means that we have new row.
            if ( index == trapInfo.Size )
                trapInfo.Size++;

            // Length of string is one more than index.
            trapInfo.table[index].communityLen++;

            return true;
        }

        // Make sure that index is within our range.
        if ( index < trapInfo.Size )
        {
            // Copy given value into local buffer.
            trapInfo.table[index].community[ref] = val.byte;
            // Keep track of length too.
            // This may not be NULL terminate string.
            trapInfo.table[index].communityLen = (uint8_t)ref;
            return true;
        }
        break;
}