/* This file was generated by mib2c and is intended for use as a mib module for the ucd-snmp snmpd agent. */ #ifdef IN_UCD_SNMP_SOURCE /* If we're compiling this file inside the ucd-snmp source tree */ /* This should always be included first before anything else */ #include /* minimal include directives */ #include "mibincl.h" #include "util_funcs.h" #else /* !IN_UCD_SNMP_SOURCE */ #include #include #include #endif /* !IN_UCD_SNMP_SOURCE */ #include #include #include #include "enseirb.h" // Line Printer parallel port base address #define lp_base 0x378 #define OFF 0 #define ON 1 static char led0 = OFF; static char led1 = OFF; static char led2 = OFF; static char led3 = OFF; static char led4 = OFF; static char led5 = OFF; static char led6 = OFF; static char led7 = OFF; static char lpdata; /* * enseirb_variables_oid: * this is the top level oid that we want to register under. This * is essentially a prefix, with the suffix appearing in the * variable below. */ oid enseirb_variables_oid[] = { 1,3,6,1,4,1,9362 }; /* * variable2 enseirb_variables: * this variable defines function callbacks and type return information * for the enseirb mib section */ struct variable2 enseirb_variables[] = { /* magic number , variable type , ro/rw , callback fn , L, oidsuffix */ #define LED0 1 { LED0 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,1 } }, #define LED1 2 { LED1 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,2 } }, #define LED2 3 { LED2 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,3 } }, #define LED3 4 { LED3 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,4 } }, #define LED4 5 { LED4 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,5 } }, #define LED5 6 { LED5 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,6 } }, #define LED6 7 { LED6 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,7 } }, #define LED7 8 { LED7 , ASN_INTEGER , RWRITE, var_enseirb, 2, { 1,8 } }, }; /* (L = length of the oidsuffix) */ /* * init_enseirb(): * Initialization routine. This is called when the agent starts up. * At a minimum, registration of your variables should take place here. */ void init_enseirb(void) { /* register ourselves with the agent to handle our mib tree */ REGISTER_MIB("enseirb", enseirb_variables, variable2, enseirb_variables_oid); /* place any other initialization junk you need here */ ioperm(lp_base, 1, 1); lpdata = 0; outb(lpdata, lp_base); } /* * var_enseirb(): * This function is called every time the agent gets a request for * a scalar variable that might be found within your mib section * registered above. It is up to you to do the right thing and * return the correct value. * You should also correct the value of "var_len" if necessary. * * Please see the documentation for more information about writing * module extensions, and check out the examples in the examples * and mibII directories. */ unsigned char * var_enseirb(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { /* variables we may use later */ static long long_ret; static unsigned char string[SPRINT_MAX_LEN]; static oid objid[MAX_OID_LEN]; static struct counter64 c64; if (header_generic(vp,name,length,exact,var_len,write_method) == MATCH_FAILED ) return NULL; /* * this is where we do the value assignments for the mib results. */ switch(vp->magic) { case LED0: *write_method = write_led0; long_ret = led0; return (unsigned char *) &long_ret; case LED1: *write_method = write_led1; long_ret = led1; return (unsigned char *) &long_ret; case LED2: *write_method = write_led2; long_ret = led2; return (unsigned char *) &long_ret; case LED3: *write_method = write_led3; long_ret = led3; return (unsigned char *) &long_ret; case LED4: *write_method = write_led4; long_ret = led4; return (unsigned char *) &long_ret; case LED5: *write_method = write_led5; long_ret = led5; return (unsigned char *) &long_ret; case LED6: *write_method = write_led6; long_ret = led6; return (unsigned char *) &long_ret; case LED7: *write_method = write_led7; long_ret = led7; return (unsigned char *) &long_ret; default: ERROR_MSG(""); } return NULL; } int write_led0(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led0 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led0: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 0; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 0; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led0 = *long_ret; // send_easy_trap(SNMP_TRAP_ENTERPRISESPECIFIC, 3); send_easy_trap(10, 100); break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; } int write_led1(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led1 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led1: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 1; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 1; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led1 = *long_ret; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; } int write_led2(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led2 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led2: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 2; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 2; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led2 = *long_ret; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; } int write_led3(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led3 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led3: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 3; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 3; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led3 = *long_ret; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; } int write_led4(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led4 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led4: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 4; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 4; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led4 = *long_ret; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; } int write_led5(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led5 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led5: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 5; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 5; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led5 = *long_ret; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; } int write_led6(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led6 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led6: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 6; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 6; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led6 = *long_ret; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; } int write_led7(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { static long *long_ret; int size; char tmp; switch ( action ) { case RESERVE1: if (var_val_type != ASN_INTEGER){ fprintf(stderr, "write to led7 not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ fprintf(stderr,"write to led7: bad length\n"); return SNMP_ERR_WRONGLENGTH; } break; case RESERVE2: size = var_val_len; long_ret = (long *) var_val; break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* The variable has been stored in long_ret for you to use, and you have just been asked to do something with it. Note that anything done here must be reversable in the UNDO case */ lpdata = inb(lp_base); tmp = *long_ret << 7; if(tmp) lpdata = lpdata | tmp; else { tmp = 1 << 7; lpdata = lpdata & (~tmp); } outb(lpdata, lp_base); led7 = *long_ret; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; }