1 /****************************************************************************
3 * Copyright (c) 2001 Broadcom Corporation
6 * No portions of this material may be reproduced in any form without the
7 * written permission of:
10 * 16251 Laguna Canyon Road
11 * Irvine, California 92618
13 * All information contained in this document is Broadcom Corporation
14 * company private, proprietary, and trade secret.
16 *****************************************************************************/
19 * @file atmMibHelper.c
21 * @brief Helper functions for the ATM MIB
23 ****************************************************************************/
25 /* ---- Include Files ---------------------------------------------------- */
31 #include <net-snmp/net-snmp-config.h>
32 #include <net-snmp/net-snmp-includes.h>
33 #include <net-snmp/agent/net-snmp-agent-includes.h>
34 #include <net-snmp/agent/auto_nlist.h>
36 #include "../interfaces.h"
37 #include "atmMibHelper.h"
38 #include "atmMibDefs.h"
41 #include <bcmatmapi.h>
42 #include <atmapidrv.h>
44 #ifdef BUILD_SNMP_ATM_MIB
46 /* ---- Public Variables ------------------------------------------------- */
47 /* ---- Private Constants and Types -------------------------------------- */
49 #define ATMMIB_STATUS_OK 0
50 #define ATMMIB_STATUS_ERR 1
52 /* ---- Private Variables ------------------------------------------------ */
54 static oid defAtmTrafficDescriptor[ATM_TRAFDESC_OIDLEN] = { 1, 3, 6, 1, 2, 1, 37, 1, 1, 2 } ;
56 /* ---- Private Function Prototypes -------------------------------------- */
57 static int getConfVccCount( void );
58 static void trafDescCopyDriverData( ATM_TRAFDESC_TABLE* tableRow, ATM_TRAFFIC_DESCR_PARM_ENTRY* driverTableRow );
59 static void trafDescSetDefValues( ATM_TRAFDESC_TABLE* tableRow );
60 static void trafDescMapType( ATM_TRAFDESC_TABLE* tableRow, ATM_TRAFFIC_DESCR_PARM_ENTRY* driverTableRow );
61 static void vclCopyDriverData( ATM_VCL_TABLE* tableRow, PATM_VCC_ADDR pAddrs, ATM_VCC_CFG* vccCfg );
62 static void aal5vccCopyDriverData( AAL5_VCC_TABLE* tableRow, PATM_VCC_ADDR pAddrs, ATM_VCC_STATS* stats );
63 static void aal5vccSetDefValues( AAL5_VCC_TABLE* tableRow );
64 static void vclSetDefValues( ATM_VCL_TABLE* tableRow );
65 static int mapAalType( UINT32 driverAalType );
67 /* ---- Functions -------------------------------------------------------- */
68 int getVccAddrs( int numAddrs, PATM_VCC_ADDR pAddrs );
69 int getAal5CpcsIfIndex( void );
70 int getAtmCellIfIndex( void );
73 /* Fill out the ATM interface configuration table */
74 void atmMibHelper_fillAtmIfConfTable( ATM_INTERFACE_CONF_TABLE* pTable )
76 /* Assuming only one ATM interface (ATM_INTERFACE_COUNT = 1) */
78 ATM_INTERFACE_CONF_TABLE* p = pTable;
80 p->pTableBeginning = pTable;
81 p->ifIndex = getAtmCellIfIndex();
83 p->atmInterfaceMaxVpcs = ATM_INTF_MAX_VPCS;
84 p->atmInterfaceMaxVccs = ATM_INTF_MAX_VCCS;
85 p->atmInterfaceConfVpcs = ATM_INTF_CONF_VPCS;
86 p->atmInterfaceConfVccs = getConfVccCount();
87 p->atmInterfaceMaxActiveVpiBits = ATM_INTF_MAX_ACTIVE_VPI_BITS;
88 p->atmInterfaceMaxActiveVciBits = ATM_INTF_MAX_ACTIVE_VCI_BITS;
89 p->atmInterfaceIlmiVpi = ATM_INTF_ILMI_VPI;
90 #ifdef BUILD_SNMP_AUTOCONFIG
91 p->atmInterfaceIlmiVci = ATM_INTF_ILMI_VCI;
93 p->atmInterfaceIlmiVci = ATM_INTF_ILMI_VCI_UNSUPPORTED;
95 p->atmInterfaceAddressType = ATM_INTF_ADDRTYPE_OTHER;
96 strncpy( p->atmInterfaceAdminAddress, "", strlen("") );
97 strncpy( p->atmInterfaceMyNeighborIpAddress, "", strlen("") );
98 strncpy( p->atmInterfaceMyNeighborIfName, "", strlen("") );
99 p->atmInterfaceCurrentMaxVpiBits = ATM_INTF_CURRENT_MAX_VPI_BITS;
100 p->atmInterfaceCurrentMaxVciBits = ATM_INTF_CURRENT_MAX_VCI_BITS;
101 strncpy( p->atmInterfaceSubscrAddress, "", strlen("") );
105 #endif /* ATMIFCONFTBL */
109 /* Fill out the ATM interface TC table */
110 void atmMibHelper_fillAtmIfTCTable( ATM_INTERFACE_TC_TABLE* pTable )
112 /* Assuming only one ATM interface (ATM_INTERFACE_COUNT = 1) */
114 ATM_INTERFACE_TC_TABLE* p = pTable;
115 p->pTableBeginning = pTable;
116 p->ifIndex = getAtmCellIfIndex();
118 p->atmInterfaceOCDEvents = ATM_INTF_TC_OCD ;
119 p->atmInterfaceTCAlarmState = ATM_INTF_TC_ALMST_NOALARM ;
123 #endif /* ATMIFTCTBL */
126 #ifdef ATMTRAFFDESCTBL
127 /* Fill out the ATM interface traffic descriptor table */
128 int atmMibHelper_fillAtmTrafDescTable( ATM_TRAFDESC_TABLE* pTable )
130 ATM_TRAFDESC_TABLE* p = pTable;
133 UINT32 ulTdtSize = 0;
134 int errStatus = ATMMIB_STATUS_ERR;
135 ATM_TRAFFIC_DESCR_PARM_ENTRY* pTdt = NULL;
136 ATM_TRAFFIC_DESCR_PARM_ENTRY* pTdte = NULL;
138 /* Small portion taken from TdteHandler and TdteHandlerShow in atmctl.c */
139 BcmAtm_GetTrafficDescrTableSize( &ulTdtSize );
140 pTdt = (PATM_TRAFFIC_DESCR_PARM_ENTRY) malloc( ulTdtSize * sizeof(ATM_TRAFFIC_DESCR_PARM_ENTRY) );
143 pTdt->ulStructureId = ID_ATM_TRAFFIC_DESCR_PARM_ENTRY;
144 nRet = (int) BcmAtm_GetTrafficDescrTable( pTdt, ulTdtSize );
148 for ( i = 1; i <= ulTdtSize; i++, pTdte++ )
150 p->pTableBeginning = pTable;
151 trafDescCopyDriverData( p, pTdte );
152 if ( i == ulTdtSize )
156 errStatus = ATMMIB_STATUS_OK;
167 ATMMIBLOG_ERROR(("atmMibHelper_fillAtmTrafDescTable: Could not get traffic description table"));
172 ATMMIBLOG_ERROR(("atmMibHelper_fillAtmTrafDescTable: Could not allocate memory for the traffic description table"));
179 #endif /* ATMTRAFFDESCTBL */
182 /* Fill out the ATM VCL table */
183 int atmMibHelper_fillAtmVclTable( ATM_VCL_TABLE* pTable )
185 /* Assuming only one ATM interface (ATM_INTERFACE_COUNT = 1) */
187 int errStatus = ATMMIB_STATUS_ERR;
189 PATM_VCC_ADDR pAddrs = NULL;
190 ATM_VCL_TABLE* p = pTable;
194 PATM_VCC_ADDR freePointer;
196 vccCount = getConfVccCount();
200 /* Allocate memory for an ATM_VCC_ADDR stuct for each configured VCC. */
201 pAddrs = (PATM_VCC_ADDR)malloc( vccCount * (sizeof(ATM_VCC_ADDR) + sizeof(UINT8)) );
202 freePointer = pAddrs;
205 if ( getVccAddrs( vccCount, pAddrs ) == 0 )
207 for ( i = 1; i <= vccCount; i++, pAddrs++ )
209 memset( &Cfg, 0x00, sizeof(Cfg) );
210 Cfg.ulStructureId = ID_ATM_VCC_CFG;
212 nRet = (int) BcmAtm_GetVccCfg( pAddrs, &Cfg );
215 p->pTableBeginning = pTable;
216 p->ifIndex = getAtmCellIfIndex();
217 vclCopyDriverData( p, pAddrs, &Cfg );
222 errStatus = ATMMIB_STATUS_OK;
232 ATMMIBLOG_ERROR(("atmMibHelper_fillAtmVclTable: Could not get VCC configuration"));
239 ATMMIBLOG_ERROR(("atmMibHelper_fillAtmVclTable: Could not get VCC address"));
246 ATMMIBLOG_ERROR(("atmMibHelper_fillAtmVclTable: Could not allocate memory"));
252 #endif /* ATMVCLTBL */
256 /* Fill out the AAL5 VCC table */
257 int atmMibHelper_fillAal5VccTable( AAL5_VCC_TABLE* pTable )
259 /* Assuming only one AAL5 CPCS interface */
261 int errStatus = ATMMIB_STATUS_ERR;
263 PATM_VCC_ADDR pAddrs = NULL;
264 AAL5_VCC_TABLE* p = pTable;
268 PATM_VCC_ADDR freePointer;
271 vccCount = getConfVccCount();
275 /* Allocate memory for an ATM_VCC_ADDR stuct for each configured VCC. */
276 pAddrs = (PATM_VCC_ADDR)malloc( vccCount * (sizeof(ATM_VCC_ADDR) + sizeof(UINT8)) );
277 freePointer = pAddrs;
280 if ( getVccAddrs( vccCount, pAddrs ) == 0 )
282 for ( i = 1; i <= vccCount; i++, pAddrs++ )
284 memset( &Stats, 0x00, sizeof(Stats) );
285 Stats.ulStructureId = ID_ATM_VCC_STATS;
287 nRet = (int) BcmAtm_GetVccStatistics( pAddrs, &Stats, 0 );
290 p->pTableBeginning = pTable;
291 p->aal5ifIndex = getAal5CpcsIfIndex();
292 aal5vccCopyDriverData( p, pAddrs, &Stats );
297 errStatus = ATMMIB_STATUS_OK;
307 ATMMIBLOG_ERROR(("atmMibHelper_fillAal5VccTable: Could not get AAL5 VCC statistics"));
314 ATMMIBLOG_ERROR(("atmMibHelper_fillAtmVclTable: Could not get VCC address"));
321 ATMMIBLOG_ERROR(("atmMibHelper_fillAtmVclTable: Could not allocate memory"));
327 #endif /* AAL5VCCTBL */
329 /* Get the number of traffic indexes */
330 int atmMibHelper_getTrafDescIndexCount( void )
334 BcmAtm_GetTrafficDescrTableSize( (UINT32*)&ulTdtSize );
340 /* Get the number of ATM interfaces */
341 int atmMibHelper_getAtmIfCount( void )
343 #if ( ATM_INTERFACE_COUNT != 1 )
344 #error Currently only one ATM interface supported by the ATM MIB
346 return( ATM_INTERFACE_COUNT );
350 int atmMibHelper_getTotalVccCount( void )
352 return ( getConfVccCount() );
355 /* Get the (first) ATM cell interface index */
356 int getAtmCellIfIndex( void )
358 /* This should be the index for the ATM cell layer in the ifTable */
359 return( Interface_Index_By_Name(ATM_CELL_LAYER_IFNAME, strlen(ATM_CELL_LAYER_IFNAME)) );
362 /* Get the (first) AAL5 CPCS interface index */
363 int getAal5CpcsIfIndex( void )
365 /* This should be the index for the AAL5 CPCS layer in the ifTable */
366 return( Interface_Index_By_Name(AAL5_CPCS_LAYER_IFNAME, strlen(AAL5_CPCS_LAYER_IFNAME)) );
369 /* Get the number of configured VCCs */
370 int getConfVccCount( void )
372 UINT32 ulNumAddrs = 0;
373 UINT32 ulInterfaceId = 0;
374 UINT32 ulAddrsReturned = 0;
377 /* Small portion taken from GetVccAddrsToUse in atmctl.c */
378 for( i = 0; i < PHY_NUM_PORTS; i++ )
380 ulInterfaceId = (UINT32) i;
381 BcmAtm_GetInterfaceId( (UINT8) i, &ulInterfaceId );
382 BcmAtm_GetVccAddrs( ulInterfaceId, NULL, 0, &ulAddrsReturned );
383 ulNumAddrs += ulAddrsReturned;
386 return( ulNumAddrs );
390 #ifdef ATMTRAFFDESCTBL
391 /* Map the traffic descriptor type from a value provided by the ATM driver (0-15)
392 ** to a oid value for the traffic descriptor type (e.g. { 1, 3, 6, 1, 2, 1, 37, 1, 1, 2 } ) */
393 void trafDescMapType( ATM_TRAFDESC_TABLE* tableRow, ATM_TRAFFIC_DESCR_PARM_ENTRY* driverTableRow )
395 /* Set the default traffic descriptor */
396 memcpy( tableRow->atmTrafficDescrType, defAtmTrafficDescriptor, sizeof(defAtmTrafficDescriptor) );
398 /* The ATM driver returns values from 1 to 15 for the traffic descriptor type.
399 ** Modify only the last entry in the oid array. */
400 tableRow->atmTrafficDescrType[ATM_TRAFDESC_OIDLEN-1] = driverTableRow->ulTrafficDescrType;
403 /* Copy the data from the driver table to the ATM traffic descriptor table */
404 void trafDescCopyDriverData( ATM_TRAFDESC_TABLE* tableRow, ATM_TRAFFIC_DESCR_PARM_ENTRY* driverTableRow )
406 /* First, set the default values */
407 trafDescSetDefValues( tableRow );
409 /* Change only the values that can be obtained from the ATM driver.
410 ** Don't change the other values (i.e. keep the defaults) */
411 tableRow->atmTrafficDescrParamIndex = driverTableRow->ulTrafficDescrIndex;
412 trafDescMapType( tableRow, driverTableRow );
413 tableRow->atmTrafficDescrParam1 = driverTableRow->ulTrafficDescrParm1;
414 tableRow->atmTrafficDescrParam2 = driverTableRow->ulTrafficDescrParm2;
415 tableRow->atmTrafficDescrParam3 = driverTableRow->ulTrafficDescrParm3;
416 tableRow->atmTrafficDescrParam4 = driverTableRow->ulTrafficDescrParm4;
417 tableRow->atmTrafficDescrParam5 = driverTableRow->ulTrafficDescrParm5;
418 tableRow->atmServiceCategory = driverTableRow->ulServiceCategory;
419 tableRow->atmTrafficFrameDiscard = driverTableRow->ulTrafficFrameDiscard;
422 /* Set the default values for the ATM traffic descriptor table */
423 void trafDescSetDefValues( ATM_TRAFDESC_TABLE* tableRow )
425 memcpy( tableRow->atmTrafficDescrType, defAtmTrafficDescriptor, sizeof(defAtmTrafficDescriptor) );
426 tableRow->atmTrafficDescrParam1 = ATM_TRAFDESC_PARAM;
427 tableRow->atmTrafficDescrParam2 = ATM_TRAFDESC_PARAM;
428 tableRow->atmTrafficDescrParam3 = ATM_TRAFDESC_PARAM;
429 tableRow->atmTrafficDescrParam4 = ATM_TRAFDESC_PARAM;
430 tableRow->atmTrafficDescrParam5 = ATM_TRAFDESC_PARAM;
431 tableRow->atmTrafficQoSClass = 0;
432 tableRow->atmTrafficDescrRowStatus= ATM_TRAFDESC_ROWSTATUS_ACTIVE;
433 tableRow->atmServiceCategory = ATM_TRAFDESC_SERVICE_CAT_UBR;
434 tableRow->atmTrafficFrameDiscard = 1;
436 #endif /* ATMTRAFFDESCTBL */
439 int getVccAddrs( int numAddrs, PATM_VCC_ADDR pAddrs )
442 UINT8 *pucPorts = NULL;
443 UINT32 ulInterfaceId = 0;
444 UINT32 ulAddrsReturned = 0;
447 /* Get the addresses of all configured VCCs. */
450 UINT32 ulAddrsIndex = 0;
452 pucPorts = (UINT8 *) (pAddrs + numAddrs);
453 for( i = 0; i < PHY_NUM_PORTS; i++ )
455 ulInterfaceId = (UINT32) i;
456 BcmAtm_GetInterfaceId( (UINT8) i, &ulInterfaceId );
457 if( BcmAtm_GetVccAddrs(ulInterfaceId, pAddrs + ulAddrsIndex,
458 numAddrs - ulAddrsIndex, &ulAddrsReturned) == STS_SUCCESS)
460 memset( pucPorts + ulAddrsIndex, i, ulAddrsReturned );
461 ulAddrsIndex += ulAddrsReturned;
475 /* Copy the driver data to the user structure for the ATM VCL table */
476 void vclCopyDriverData( ATM_VCL_TABLE* tableRow, PATM_VCC_ADDR pAddrs, ATM_VCC_CFG* vccCfg )
478 /* First, set the default values */
479 vclSetDefValues( tableRow );
481 /* Change only the values that can be obtained from the ATM driver.
482 ** Don't change the other values (i.e. keep the defaults) */
483 tableRow->atmVclVpi = pAddrs->usVpi;
484 tableRow->atmVclVci = pAddrs->usVci;
485 tableRow->atmVclAdminStatus = vccCfg->ulAtmVclAdminStatus;
486 tableRow->atmVclOperStatus = vccCfg->ulAtmVclOperStatus;
487 tableRow->atmVclLastChange = vccCfg->ulAtmVclLastChange;
488 tableRow->atmVccAalType = mapAalType( vccCfg->ulAalType );
489 tableRow->atmVclTransmitTrafficDescrIndex = vccCfg->ulAtmVclTransmitTrafficDescrIndex;
490 tableRow->atmVclReceiveTrafficDescrIndex = tableRow->atmVclTransmitTrafficDescrIndex;
491 tableRow->atmVccAal5EncapsType = vccCfg->u.Aal5Cfg.ulAtmVccEncapsType;
494 /* Set the default values for the ATM VCL table */
495 void vclSetDefValues( ATM_VCL_TABLE* tableRow )
497 tableRow->atmVccAalType = ATM_VCL_AALTYPE_AAL5;
498 tableRow->atmVccAal5CpcsTransmitSduSize = ATM_VCL_SDUSIZE;
499 tableRow->atmVccAal5CpcsReceiveSduSize = ATM_VCL_SDUSIZE;
500 tableRow->atmVccAalType = ATM_VCL_AALTYPE_AAL5;
501 tableRow->atmVclCrossConnectIdentifier = 0;
502 tableRow->atmVclRowStatus = ATM_VCL_ROWSTATUS_ACTIVE;
503 tableRow->atmVclCastType = ATM_VCL_CAST_TYPE_P2P;
504 tableRow->atmVclConnKind = ATM_VCL_CONN_KIND_PVC;
507 /* Map the AAL type provided by the driver to a value understood by the MIB
508 ** (used for the ATM VCL table) */
509 int mapAalType( UINT32 driverAalType )
511 int aalType = ATM_VCL_AALTYPE_AAL5;
513 switch ( driverAalType )
516 aalType = ATM_VCL_AALTYPE_AAL2;
519 aalType = ATM_VCL_AALTYPE_AAL5;
522 aalType = ATM_VCL_AALTYPE_UNKNOWN;
528 #endif /* ATMVCLTBL */
532 /* Copy the driver data to the user structure for the AAL5 VCC table */
533 void aal5vccCopyDriverData( AAL5_VCC_TABLE* tableRow, PATM_VCC_ADDR pAddrs, ATM_VCC_STATS* stats )
535 /* First, set the default values */
536 aal5vccSetDefValues( tableRow );
538 /* Change only the values that can be obtained from the ATM driver.
539 ** Keep the defaults for the other values */
540 tableRow->aal5VccVpi = pAddrs->usVpi;
541 tableRow->aal5VccVci = pAddrs->usVci;
542 tableRow->aal5VccCrcErrors = stats->u.AtmVccAal5Stats.ulAal5VccCrcErrors;
543 tableRow->aal5VccOverSizedSDUs = stats->u.AtmVccAal5Stats.ulAal5VccOverSizedSdus;
544 tableRow->aal5VccSarTimeOuts = stats->u.AtmVccAal5Stats.ulAal5VccSarTimeOuts;
547 /* Set the default values for the AAL5 VCC table */
548 void aal5vccSetDefValues( AAL5_VCC_TABLE* tableRow )
550 tableRow->aal5VccCrcErrors = 0;
551 tableRow->aal5VccOverSizedSDUs = 0;
552 tableRow->aal5VccSarTimeOuts = 0;
555 #endif /* AAL5VCCTBL */
557 #endif /* BUILD_SNMP_ATM_MIB */
559 int getAtmIntfOperStatus(void)
561 ATM_INTERFACE_CFG Cfg;
562 UINT32 ulInterfaceId;
565 BcmAtm_GetInterfaceId( (UINT8) port, &ulInterfaceId );
566 Cfg.ulStructureId = ID_ATM_INTERFACE_CFG;
568 if (BcmAtm_GetInterfaceCfg( ulInterfaceId, &Cfg ) == STS_SUCCESS)
570 if (Cfg.ulIfOperStatus == OPRSTS_UP)
571 return IF_OPER_STATUS_UP;
573 return IF_OPER_STATUS_DOWN;
575 return IF_OPER_STATUS_UNKNOWN;
578 int getAtmIntfAdminStatus(void)
580 ATM_INTERFACE_CFG Cfg;
581 UINT32 ulInterfaceId;
584 BcmAtm_GetInterfaceId( (unsigned char) port, &ulInterfaceId );
585 Cfg.ulStructureId = ID_ATM_INTERFACE_CFG;
587 if (BcmAtm_GetInterfaceCfg( ulInterfaceId, &Cfg ) == STS_SUCCESS)
588 return (Cfg.ulIfAdminStatus);
590 return IF_ADMIN_STATUS_DOWN;
593 int setAtmIntfAdminStatus(int status)
595 ATM_INTERFACE_CFG Cfg;
596 UINT32 ulInterfaceId;
600 Cfg.ulStructureId = ID_ATM_INTERFACE_CFG;
601 ret = BcmAtm_GetInterfaceId( (UINT8) port, &ulInterfaceId );
604 /* Change the state to the specified value. */
605 Cfg.ulIfAdminStatus = status;
606 ret = (int)BcmAtm_SetInterfaceCfg(ulInterfaceId, &Cfg );